Gromacs
2016.6
|
#include <cstdio>
#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... | |
Functions | |
int | detect_gpus (struct gmx_gpu_info_t *gpu_info, char *err_str) |
Detect all GPUs in the system. More... | |
void | pick_compatible_gpus (const struct gmx_gpu_info_t *gpu_info, gmx_gpu_opt_t *gpu_opt) |
Select the compatible GPUs. More... | |
gmx_bool | check_selected_gpus (int *checkres, const struct gmx_gpu_info_t *gpu_info, gmx_gpu_opt_t *gpu_opt) |
Check the existence/compatibility of a set of GPUs specified by their device IDs. More... | |
void | free_gpu_info (const struct gmx_gpu_info_t *gpu_info) |
Frees the gpu_dev and dev_use array fields of gpu_info . More... | |
gmx_bool | init_gpu (FILE *fplog, int mygpu, char *result_str, const struct gmx_gpu_info_t *gpu_info, const gmx_gpu_opt_t *gpu_opt) |
Initializes the GPU with the given index. More... | |
gmx_bool | free_cuda_gpu (int mygpu, char *result_str, const gmx_gpu_info_t *gpu_info, const gmx_gpu_opt_t *gpu_opt) |
Frees up the CUDA GPU used by the active context at the time of calling. More... | |
int | get_current_cuda_gpu_device_id (void) |
Returns the device ID of the CUDA GPU currently in use. More... | |
int | get_gpu_device_id (const struct gmx_gpu_info_t *gpu_info, const gmx_gpu_opt_t *gpu_opt, int idx) |
Returns an identifier for the GPU with a given index into the array of used GPUs. More... | |
char * | get_ocl_gpu_device_name (const struct gmx_gpu_info_t *gpu_info, const gmx_gpu_opt_t *gpu_opt, int idx) |
Returns the name for the OpenCL GPU with a given index into the array of used GPUs. More... | |
void | get_gpu_device_info_string (char *s, const struct gmx_gpu_info_t *gpu_info, int index) |
Formats and returns a device information string for a given GPU. More... | |
size_t | sizeof_gpu_dev_info (void) |
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... | |
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... | |
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.
gmx_bool check_selected_gpus | ( | int * | checkres, |
const struct gmx_gpu_info_t * | gpu_info, | ||
gmx_gpu_opt_t * | gpu_opt | ||
) |
Check the existence/compatibility of a set of GPUs specified by their device IDs.
Given the a list of gpu_opt->n_dev_use GPU device IDs stored in gpu_opt->dev_use check the existence and compatibility of the respective GPUs. Also provide the caller with an array containing the result of checks in checkres
.
[out] | checkres | check result for each ID passed in requested_devs |
[in] | gpu_info | pointer to structure holding GPU information |
[out] | gpu_opt | pointer to structure holding GPU options |
int detect_gpus | ( | gmx_gpu_info_t * | gpu_info, |
char * | err_str | ||
) |
Detect all GPUs in the system.
Will detect every GPU supported by the device driver in use. Also check 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.
[in] | gpu_info | pointer to structure holding GPU information. |
[out] | err_str | The error message of any GPU API error that caused the detection to fail (if there was any). The memory the pointer points to should be managed externally. |
Detect all GPUs in the system.
gmx_bool free_cuda_gpu | ( | int | mygpu, |
char * | result_str, | ||
const gmx_gpu_info_t * | gpu_info, | ||
const gmx_gpu_opt_t * | gpu_opt | ||
) |
Frees up the CUDA GPU used by the active context at the time of calling.
The context is explicitly destroyed and therefore all data uploaded to the GPU is lost. This should only be called when none of this data is required anymore.
[in] | mygpu | index of the GPU clean up for |
[out] | result_str | the message related to the error that occurred during the initialization (if there was any). |
[in] | gpu_info | GPU info of all detected devices in the system. |
[in] | gpu_opt | options for using the GPUs in gpu_info |
void free_gpu_info | ( | const struct 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.
int get_gpu_device_id | ( | const struct gmx_gpu_info_t * | gpu_info, |
const gmx_gpu_opt_t * | gpu_opt, | ||
int | idx | ||
) |
Returns an identifier for the GPU with a given index into the array of used GPUs.
Getter function which, given an index into the array of GPUs in use (dev_use) – typically an MPI rank –, returns an identifier of the respective GPU.
[in] | gpu_info | Pointer to structure holding GPU information |
[in] | gpu_opt | Pointer to structure holding GPU options |
[in] | idx | Index into the array of used GPUs |
void get_gpu_device_info_string | ( | char * | s, |
const struct 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 | pointer to structure holding GPU information |
[in] | index | an index directly into the array of available GPUs |
char* get_ocl_gpu_device_name | ( | const struct gmx_gpu_info_t * | gpu_info, |
const gmx_gpu_opt_t * | gpu_opt, | ||
int | idx | ||
) |
Returns the name for the OpenCL GPU with a given index into the array of used GPUs.
Getter function which, given an index into the array of GPUs in use (dev_use) – typically a tMPI/MPI rank –, returns the device name for the respective OpenCL GPU.
[in] | gpu_info | Pointer to structure holding GPU information |
[in] | gpu_opt | Pointer to structure holding GPU options |
[in] | idx | Index into the array of used GPUs |
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.
gmx_bool init_gpu | ( | FILE * | fplog, |
int | mygpu, | ||
char * | result_str, | ||
const struct gmx_gpu_info_t * | gpu_info, | ||
const gmx_gpu_opt_t * | gpu_opt | ||
) |
Initializes the GPU with the given index.
The varible mygpu
is the index of the GPU to initialize in the gpu_info.gpu_dev array.
[out] | fplog | log file to write to |
[in] | mygpu | index of the GPU to initialize |
[out] | result_str | the message related to the error that occurred during the initialization (if there was any). |
[in] | gpu_info | GPU info of all detected devices in the system. |
[in] | gpu_opt | options for using the GPUs in gpu_info |
void pick_compatible_gpus | ( | const struct gmx_gpu_info_t * | gpu_info, |
gmx_gpu_opt_t * | gpu_opt | ||
) |
Select the compatible GPUs.
This function selects the compatible gpus and initializes gpu_info->dev_use and gpu_info->n_dev_use.
Given the list of GPUs available in the system check each device in gpu_info->gpu_dev and place the indices of the compatible GPUs into dev_use with this marking the respective GPUs as "available for use." Note that detect_gpus
must have been called before.
[in] | gpu_info | pointer to structure holding GPU information |
[in,out] | gpu_opt | pointer to structure holding GPU options |
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 | ( | void | ) |
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.