add GPU device query functions to library interface and its wrappers
This commit is contained in:
@ -15,6 +15,8 @@ This section documents the following functions:
|
|||||||
- :cpp:func:`lammps_config_package_count`
|
- :cpp:func:`lammps_config_package_count`
|
||||||
- :cpp:func:`lammps_config_package_name`
|
- :cpp:func:`lammps_config_package_name`
|
||||||
- :cpp:func:`lammps_config_accelerator`
|
- :cpp:func:`lammps_config_accelerator`
|
||||||
|
- :cpp:func:`lammps_has_gpu_device`
|
||||||
|
- :cpp:func:`lammps_gpu_device_info`
|
||||||
- :cpp:func:`lammps_has_style`
|
- :cpp:func:`lammps_has_style`
|
||||||
- :cpp:func:`lammps_style_count`
|
- :cpp:func:`lammps_style_count`
|
||||||
- :cpp:func:`lammps_style_name`
|
- :cpp:func:`lammps_style_name`
|
||||||
@ -132,6 +134,16 @@ approach.
|
|||||||
|
|
||||||
-----------------------
|
-----------------------
|
||||||
|
|
||||||
|
.. doxygenfunction:: lammps_has_gpu_device
|
||||||
|
:project: progguide
|
||||||
|
|
||||||
|
-----------------------
|
||||||
|
|
||||||
|
.. doxygenfunction:: lammps_get_gpu_device_info
|
||||||
|
:project: progguide
|
||||||
|
|
||||||
|
-----------------------
|
||||||
|
|
||||||
.. doxygenfunction:: lammps_has_style
|
.. doxygenfunction:: lammps_has_style
|
||||||
:project: progguide
|
:project: progguide
|
||||||
|
|
||||||
|
|||||||
@ -281,6 +281,7 @@ class lammps(object):
|
|||||||
self.lib.lammps_version.argtypes = [c_void_p]
|
self.lib.lammps_version.argtypes = [c_void_p]
|
||||||
|
|
||||||
self.lib.lammps_get_os_info.argtypes = [c_char_p, c_int]
|
self.lib.lammps_get_os_info.argtypes = [c_char_p, c_int]
|
||||||
|
self.lib.lammps_get_gpu_device_info.argtypes = [c_char_p, c_int]
|
||||||
|
|
||||||
self.lib.lammps_get_mpi_comm.argtypes = [c_void_p]
|
self.lib.lammps_get_mpi_comm.argtypes = [c_void_p]
|
||||||
|
|
||||||
@ -490,7 +491,7 @@ class lammps(object):
|
|||||||
|
|
||||||
sb = create_string_buffer(512)
|
sb = create_string_buffer(512)
|
||||||
self.lib.lammps_get_os_info(sb,512)
|
self.lib.lammps_get_os_info(sb,512)
|
||||||
return sb
|
return sb.value.decode()
|
||||||
|
|
||||||
# -------------------------------------------------------------------------
|
# -------------------------------------------------------------------------
|
||||||
|
|
||||||
@ -1552,6 +1553,37 @@ class lammps(object):
|
|||||||
|
|
||||||
# -------------------------------------------------------------------------
|
# -------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@property
|
||||||
|
def has_gpu_device(self):
|
||||||
|
""" Availability of GPU package compatible device
|
||||||
|
|
||||||
|
This is a wrapper around the :cpp:func:`lammps_has_gpu_device`
|
||||||
|
function of the C library interface.
|
||||||
|
|
||||||
|
:return: True if a GPU package compatible device is present, otherwise False
|
||||||
|
:rtype: bool
|
||||||
|
"""
|
||||||
|
return self.lib.lammps_has_gpu_device() != 0
|
||||||
|
|
||||||
|
# -------------------------------------------------------------------------
|
||||||
|
|
||||||
|
def get_gpu_device_info(self):
|
||||||
|
"""Return a string with detailed information about any devices that are
|
||||||
|
usable by the GPU package.
|
||||||
|
|
||||||
|
This is a wrapper around the :cpp:func:`lammps_get_gpu_device_info`
|
||||||
|
function of the C-library interface.
|
||||||
|
|
||||||
|
:return: GPU device info string
|
||||||
|
:rtype: string
|
||||||
|
"""
|
||||||
|
|
||||||
|
sb = create_string_buffer(8192)
|
||||||
|
self.lib.lammps_get_gpu_device_info(sb,8192)
|
||||||
|
return sb.value.decode()
|
||||||
|
|
||||||
|
# -------------------------------------------------------------------------
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def installed_packages(self):
|
def installed_packages(self):
|
||||||
""" List of the names of enabled packages in the LAMMPS shared library
|
""" List of the names of enabled packages in the LAMMPS shared library
|
||||||
|
|||||||
@ -4111,8 +4111,10 @@ int lammps_version(void *handle)
|
|||||||
The :cpp:func:`lammps_get_os_info` function can be used to retrieve
|
The :cpp:func:`lammps_get_os_info` function can be used to retrieve
|
||||||
detailed information about the hosting operating system and
|
detailed information about the hosting operating system and
|
||||||
compiler/runtime.
|
compiler/runtime.
|
||||||
|
|
||||||
A suitable buffer for a C-style string has to be provided and its length.
|
A suitable buffer for a C-style string has to be provided and its length.
|
||||||
If the assembled text will be truncated to not overflow this buffer.
|
The assembled text will be truncated to not overflow this buffer. The
|
||||||
|
string is typically a few hundred bytes long.
|
||||||
|
|
||||||
.. versionadded:: 9Oct2020
|
.. versionadded:: 9Oct2020
|
||||||
|
|
||||||
@ -4339,6 +4341,60 @@ int lammps_config_accelerator(const char *package,
|
|||||||
return Info::has_accelerator_feature(package,category,setting) ? 1 : 0;
|
return Info::has_accelerator_feature(package,category,setting) ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Check for presence of a viable GPU package device
|
||||||
|
*
|
||||||
|
\verbatim embed:rst
|
||||||
|
|
||||||
|
The :cpp:func:`lammps_has_gpu_device` function checks at runtime if
|
||||||
|
an accelerator device is present that can be used with the
|
||||||
|
:doc:`GPU package <Speed_gpu>`. If at least one suitable device is
|
||||||
|
present the function will return 1, otherwise 0.
|
||||||
|
|
||||||
|
More detailed information about the available device or devices can
|
||||||
|
be obtained by calling the
|
||||||
|
:cpp:func:`lammps_get_gpu_device_info` function.
|
||||||
|
|
||||||
|
.. versionadded:: 14May2021
|
||||||
|
|
||||||
|
\endverbatim
|
||||||
|
*
|
||||||
|
* \return 1 if viable device is available, 0 if not. */
|
||||||
|
|
||||||
|
int lammps_has_gpu_device()
|
||||||
|
{
|
||||||
|
return Info::has_gpu_device() ? 1: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Get GPU package device information
|
||||||
|
*
|
||||||
|
\verbatim embed:rst
|
||||||
|
|
||||||
|
The :cpp:func:`lammps_get_gpu_device_info` function can be used to retrieve
|
||||||
|
detailed information about any accelerator devices that are viable for use
|
||||||
|
with the :doc:`GPU package <Speed_gpu>`. It will produce a string that is
|
||||||
|
equivalent to the output of the ``nvc_get_device`` or ``ocl_get_device`` or
|
||||||
|
``hip_get_device`` tools that are compiled alongside LAMMPS if the GPU
|
||||||
|
package is enabled.
|
||||||
|
|
||||||
|
A suitable buffer for a C-style string has to be provided and its length.
|
||||||
|
The assembled text will be truncated to not overflow this buffer. This
|
||||||
|
string can be several kilobytes long, if multiple devices are present.
|
||||||
|
|
||||||
|
.. versionadded:: 14May2021
|
||||||
|
|
||||||
|
\endverbatim
|
||||||
|
*
|
||||||
|
* \param buffer string buffer to copy the information to
|
||||||
|
* \param buf_size size of the provided string buffer */
|
||||||
|
|
||||||
|
void lammps_get_gpu_device_info(char *buffer, int buf_size)
|
||||||
|
{
|
||||||
|
if (buf_size <= 0) return;
|
||||||
|
buffer[0] = buffer[buf_size-1] = '\0';
|
||||||
|
std::string devinfo = Info::get_gpu_device_info();
|
||||||
|
strncpy(buffer, devinfo.c_str(), buf_size-1);
|
||||||
|
}
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------- */
|
||||||
|
|
||||||
/** Check if a specific style has been included in LAMMPS
|
/** Check if a specific style has been included in LAMMPS
|
||||||
|
|||||||
@ -196,6 +196,8 @@ int lammps_config_package_count();
|
|||||||
int lammps_config_package_name(int, char *, int);
|
int lammps_config_package_name(int, char *, int);
|
||||||
|
|
||||||
int lammps_config_accelerator(const char *, const char *, const char *);
|
int lammps_config_accelerator(const char *, const char *, const char *);
|
||||||
|
int lammps_has_gpu_device();
|
||||||
|
void lammps_get_gpu_device_info(char *buffer, int buf_size);
|
||||||
|
|
||||||
int lammps_has_style(void *, const char *, const char *);
|
int lammps_has_style(void *, const char *, const char *);
|
||||||
int lammps_style_count(void *, const char *);
|
int lammps_style_count(void *, const char *);
|
||||||
|
|||||||
@ -116,6 +116,8 @@ extern int lammps_config_has_package(const char *);
|
|||||||
extern int lammps_config_package_count();
|
extern int lammps_config_package_count();
|
||||||
extern int lammps_config_package_name(int, char *, int);
|
extern int lammps_config_package_name(int, char *, int);
|
||||||
extern int lammps_config_accelerator(const char *, const char *, const char *);
|
extern int lammps_config_accelerator(const char *, const char *, const char *);
|
||||||
|
extern int lammps_has_gpu_device();
|
||||||
|
extern void lammps_get_gpu_device_info(char *buffer, int buf_size);
|
||||||
extern int lammps_has_style(void *, const char *, const char *);
|
extern int lammps_has_style(void *, const char *, const char *);
|
||||||
extern int lammps_style_count(void *, const char *);
|
extern int lammps_style_count(void *, const char *);
|
||||||
extern int lammps_style_name(void *, const char *, int, char *buffer, int buf_size);
|
extern int lammps_style_name(void *, const char *, int, char *buffer, int buf_size);
|
||||||
@ -236,6 +238,8 @@ extern int lammps_config_has_package(const char *);
|
|||||||
extern int lammps_config_package_count();
|
extern int lammps_config_package_count();
|
||||||
extern int lammps_config_package_name(int, char *, int);
|
extern int lammps_config_package_name(int, char *, int);
|
||||||
extern int lammps_config_accelerator(const char *, const char *, const char *);
|
extern int lammps_config_accelerator(const char *, const char *, const char *);
|
||||||
|
extern int lammps_has_gpu_device();
|
||||||
|
extern void lammps_get_gpu_device_info(char *buffer, int buf_size);
|
||||||
extern int lammps_has_style(void *, const char *, const char *);
|
extern int lammps_has_style(void *, const char *, const char *);
|
||||||
extern int lammps_style_count(void *, const char *);
|
extern int lammps_style_count(void *, const char *);
|
||||||
extern int lammps_style_name(void *, const char *, int, char *buffer, int buf_size);
|
extern int lammps_style_name(void *, const char *, int, char *buffer, int buf_size);
|
||||||
|
|||||||
Reference in New Issue
Block a user