Gromacs
2019
|
#include <cstdio>
#include <string>
#include <vector>
#include "gromacs/gpu_utils/gpu_macros.h"
#include "gromacs/utility/basedefinitions.h"
Declare functions for detection and initialization for GPU devices.
Typedefs | |
typedef void | gmx_host_alloc_t (void **ptr, size_t nbytes) |
Returns a pointer *ptr to page-locked memory of size nbytes. More... | |
typedef void | gmx_host_free_t (void *ptr) |
Frees page-locked memory pointed to by *ptr. More... | |
Enumerations | |
enum | GpuApiCallBehavior { Sync, Async } |
Enum which is only used to describe transfer calls at the moment. | |
enum | GpuTaskCompletion { Wait, Check } |
Types of actions associated to waiting or checking the completion of GPU tasks. | |
Functions | |
bool | canDetectGpus (std::string *errorMessage) |
Return whether GPUs can be detected. More... | |
void | findGpus (gmx_gpu_info_t *gpu_info) |
Find all GPUs in the system. More... | |
std::vector< int > | getCompatibleGpus (const gmx_gpu_info_t &gpu_info) |
Return a container of the detected GPUs that are compatible. More... | |
const char * | getGpuCompatibilityDescription (const gmx_gpu_info_t &gpu_info, int index) |
Return a string describing how compatible the GPU with given index is. More... | |
void | free_gpu_info (const gmx_gpu_info_t *gpu_info) |
Frees the gpu_dev and dev_use array fields of gpu_info . More... | |
void | init_gpu (const gmx_device_info_t *deviceInfo) |
Initializes the GPU described by deviceInfo . More... | |
void | free_gpu (const gmx_device_info_t *deviceInfo) |
Frees up the CUDA GPU used by the active context at the time of calling. More... | |
gmx_device_info_t * | getDeviceInfo (const gmx_gpu_info_t &gpu_info, int deviceId) |
Return a pointer to the device info for deviceId . More... | |
int | get_current_cuda_gpu_device_id (void) |
Returns the device ID of the CUDA GPU currently in use. More... | |
void | get_gpu_device_info_string (char *s, const gmx_gpu_info_t &gpu_info, int index) |
Formats and returns a device information string for a given GPU. More... | |
bool | areAllGpuDevicesFromAmd (const gmx_gpu_info_t &gpuInfo) |
Returns whether all compatible OpenCL devices are from AMD. More... | |
size_t | sizeof_gpu_dev_info () |
Returns the size of the gpu_dev_info struct. More... | |
void | gpu_set_host_malloc_and_free (bool bUseGpuKernels, gmx_host_alloc_t **nb_alloc, gmx_host_free_t **nb_free) |
Set page-locked memory allocation functions used by the GPU host. More... | |
int | gpu_info_get_stat (const gmx_gpu_info_t &info, int index) |
Get status of device with specified index. | |
bool | buildSupportsNonbondedOnGpu (std::string *error) |
Check if GROMACS has been built with GPU support. More... | |
void | startGpuProfiler (void) |
Starts the GPU profiler if mdrun is being profiled. More... | |
void | resetGpuProfiler (void) |
Resets the GPU profiler if mdrun is being profiled. More... | |
void | stopGpuProfiler (void) |
Stops the CUDA profiler if mdrun is being profiled. More... | |
bool | isHostMemoryPinned (const void *h_ptr) |
Tells whether the host buffer was pinned for non-blocking transfers. Only implemented for CUDA. | |
typedef void gmx_host_alloc_t(void **ptr, size_t nbytes) |
Returns a pointer *ptr to page-locked memory of size nbytes.
The allocated memory is suitable to be used for data transfers between host and GPU. Error handling should be done within this function.
typedef void gmx_host_free_t(void *ptr) |
Frees page-locked memory pointed to by *ptr.
NULL should not be passed to this function.
bool areAllGpuDevicesFromAmd | ( | const gmx_gpu_info_t & | gpuInfo | ) |
Returns whether all compatible OpenCL devices are from AMD.
This is currently the most useful and best tested platform for supported OpenCL devices, so some modules may need to check what degree of support they should offer.
bool buildSupportsNonbondedOnGpu | ( | std::string * | error | ) |
Check if GROMACS has been built with GPU support.
[in] | error | Pointer to error string or nullptr. |
bool canDetectGpus | ( | std::string * | errorMessage | ) |
Return whether GPUs can be detected.
Returns true when this is a build of GROMACS configured to support GPU usage, and a valid device driver, ICD, and/or runtime was detected.
This function is not intended to be called from build configurations that do not support GPUs, and there will be no descriptive message in that case.
[out] | errorMessage | When returning false on a build configured with GPU support and non-nullptr was passed, the string contains a descriptive message about why GPUs cannot be detected. |
Does not throw.
Return whether GPUs can be detected.
void findGpus | ( | gmx_gpu_info_t * | gpu_info | ) |
Find all GPUs in the system.
Will detect every GPU supported by the device driver in use. Must only be called if canDetectGpus() has returned true. This routine also checks for the compatibility of each and fill the gpu_info->gpu_dev array with the required information on each the device: ID, device properties, status.
Note that this function leaves the GPU runtime API error state clean; this is implemented ATM in the CUDA flavor. TODO: check if errors do propagate in OpenCL as they do in CUDA and whether there is a mechanism to "clear" them.
[in] | gpu_info | pointer to structure holding GPU information. |
InternalError | if a GPU API returns an unexpected failure (because the call to canDetectGpus() should always prevent this occuring) |
Find all GPUs in the system.
void free_gpu | ( | const gmx_device_info_t * | deviceInfo | ) |
Frees up the CUDA GPU used by the active context at the time of calling.
If deviceInfo
is nullptr, then it is understood that no device was selected so no context is active to be freed. Otherwise, the context is explicitly destroyed and therefore all data uploaded to the GPU is lost. This must only be called when none of this data is required anymore, because subsequent attempts to free memory associated with the context will otherwise fail.
Calls gmx_warning upon errors.
[in] | deviceInfo | device info of the GPU to clean up for |
void free_gpu_info | ( | const gmx_gpu_info_t * | gpu_info | ) |
Frees the gpu_dev and dev_use array fields of gpu_info
.
[in] | gpu_info | pointer to structure holding GPU information |
int get_current_cuda_gpu_device_id | ( | void | ) |
Returns the device ID of the CUDA GPU currently in use.
The GPU used is the one that is active at the time of the call in the active context.
void get_gpu_device_info_string | ( | char * | s, |
const gmx_gpu_info_t & | gpu_info, | ||
int | index | ||
) |
Formats and returns a device information string for a given GPU.
Given an index directly into the array of available GPUs (gpu_dev) returns a formatted info string for the respective GPU which includes ID, name, compute capability, and detection status.
[out] | s | pointer to output string (has to be allocated externally) |
[in] | gpu_info | Information about detected GPUs |
[in] | index | an index directly into the array of available GPUs |
Formats and returns a device information string for a given GPU.
std::vector<int> getCompatibleGpus | ( | const gmx_gpu_info_t & | gpu_info | ) |
Return a container of the detected GPUs that are compatible.
This function filters the result of the detection for compatible GPUs, based on the previously run compatibility tests.
[in] | gpu_info | Information detected about GPUs, including compatibility. |
gmx_device_info_t* getDeviceInfo | ( | const gmx_gpu_info_t & | gpu_info, |
int | deviceId | ||
) |
Return a pointer to the device info for deviceId
.
[in] | gpu_info | GPU info of all detected devices in the system. |
[in] | deviceId | ID for the GPU device requested. |
deviceId
.Return a pointer to the device info for deviceId
.
const char* getGpuCompatibilityDescription | ( | const gmx_gpu_info_t & | gpu_info, |
int | index | ||
) |
Return a string describing how compatible the GPU with given index
is.
[in] | gpu_info | Information about detected GPUs |
[in] | index | index of GPU to ask about |
void gpu_set_host_malloc_and_free | ( | bool | , |
gmx_host_alloc_t ** | nb_alloc, | ||
gmx_host_free_t ** | nb_free | ||
) |
Set page-locked memory allocation functions used by the GPU host.
Set page-locked memory allocation functions used by the GPU host.
Since GPU support is not configured, there is no host memory to allocate.
void init_gpu | ( | const gmx_device_info_t * | deviceInfo | ) |
Initializes the GPU described by deviceInfo
.
TODO Doxygen complains about these - probably a Doxygen bug, since the patterns here are the same as elsewhere in this header.
[in] | deviceInfo | device info of the GPU to initialize |
Issues a fatal error for any critical errors that occur during initialization.
Initializes the GPU described by deviceInfo
.
void resetGpuProfiler | ( | void | ) |
Resets the GPU profiler if mdrun is being profiled.
When a profiler run is in progress (based on the presence of the NVPROF_ID env. var.), the profiler data is restet in order to eliminate the data collected from the preceding part fo the run.
This function should typically be called at the mdrun counter reset time.
Note that this is implemented only for the CUDA API.
size_t sizeof_gpu_dev_info | ( | ) |
Returns the size of the gpu_dev_info struct.
The size of gpu_dev_info can be used for allocation and communication.
Returns the size of the gpu_dev_info struct.
void startGpuProfiler | ( | void | ) |
Starts the GPU profiler if mdrun is being profiled.
When a profiler run is in progress (based on the presence of the NVPROF_ID env. var.), the profiler is started to begin collecting data during the rest of the run (or until stopGpuProfiler is called).
Note that this is implemented only for the CUDA API.
void stopGpuProfiler | ( | void | ) |
Stops the CUDA profiler if mdrun is being profiled.
This function can be called at cleanup when skipping recording recording subsequent API calls from being traces/profiled is desired, e.g. before uninitialization.
Note that this is implemented only for the CUDA API.