Gromacs  2016.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Typedefs | Functions
gpu_utils.h File Reference
#include <cstdio>
#include "gromacs/gpu_utils/gpu_macros.h"
#include "gromacs/utility/basedefinitions.h"
+ Include dependency graph for gpu_utils.h:

Description

Declare functions for detection and initialization for GPU devices.

Author
Szilard Pall pall..nosp@m.szil.nosp@m.ard@g.nosp@m.mail.nosp@m..com
Mark Abraham mark..nosp@m.j.ab.nosp@m.raham.nosp@m.@gma.nosp@m.il.co.nosp@m.m

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 Documentation

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.

Function Documentation

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.

Parameters
[out]checkrescheck result for each ID passed in requested_devs
[in]gpu_infopointer to structure holding GPU information
[out]gpu_optpointer to structure holding GPU options
Returns
TRUE if every the requested GPUs are compatible
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.

Parameters
[in]gpu_infopointer to structure holding GPU information.
[out]err_strThe 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.
Returns
non-zero if the detection encountered a failure, zero otherwise.

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.

Parameters
[in]mygpuindex of the GPU clean up for
[out]result_strthe message related to the error that occurred during the initialization (if there was any).
[in]gpu_infoGPU info of all detected devices in the system.
[in]gpu_optoptions for using the GPUs in gpu_info
Returns
true if no error occurs during the freeing.
void free_gpu_info ( const struct gmx_gpu_info_t *  gpu_info)

Frees the gpu_dev and dev_use array fields of gpu_info.

Parameters
[in]gpu_infopointer 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.

Returns
device ID of the GPU in use at the time of the call
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.

Parameters
[in]gpu_infoPointer to structure holding GPU information
[in]gpu_optPointer to structure holding GPU options
[in]idxIndex into the array of used GPUs
Returns
device ID of the requested GPU
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.

Parameters
[out]spointer to output string (has to be allocated externally)
[in]gpu_infopointer to structure holding GPU information
[in]indexan 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.

Parameters
[in]gpu_infoPointer to structure holding GPU information
[in]gpu_optPointer to structure holding GPU options
[in]idxIndex into the array of used GPUs
Returns
A string with the name of the requested OpenCL GPU
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.

Parameters
[out]fploglog file to write to
[in]mygpuindex of the GPU to initialize
[out]result_strthe message related to the error that occurred during the initialization (if there was any).
[in]gpu_infoGPU info of all detected devices in the system.
[in]gpu_optoptions for using the GPUs in gpu_info
Returns
true if no error occurs during initialization.
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.

Parameters
[in]gpu_infopointer to structure holding GPU information
[in,out]gpu_optpointer 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
size in bytes of gpu_dev_info

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.