Gromacs
2020.4
|
#include "gmxpre.h"
#include "config.h"
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cstdio>
#include <memory.h>
#include "gromacs/gpu_utils/gpu_utils.h"
#include "gromacs/gpu_utils/ocl_compiler.h"
#include "gromacs/gpu_utils/oclraii.h"
#include "gromacs/gpu_utils/oclutils.h"
#include "gromacs/hardware/hw_info.h"
#include "gromacs/utility/cstringutil.h"
#include "gromacs/utility/exceptions.h"
#include "gromacs/utility/fatalerror.h"
#include "gromacs/utility/smalloc.h"
#include "gromacs/utility/stringutil.h"
Define functions for detection and initialization for OpenCL devices.
Functions | |
static bool | runningOnCompatibleOSForAmd () |
Return true if executing on compatible OS for AMD OpenCL. More... | |
static std::string | gmx::makeOpenClInternalErrorString (const char *message, cl_int status) |
Make an error string following an OpenCL API call. More... | |
static bool | gmx::isDeviceSane (const gmx_device_info_t *devInfo, std::string *errorMessage) |
Checks that device devInfo is sane (ie can run a kernel). More... | |
static int | gmx::isDeviceSupported (const gmx_device_info_t *devInfo) |
Checks that device devInfo is compatible with GROMACS. More... | |
static int | gmx::checkGpu (size_t deviceId, const gmx_device_info_t *deviceInfo) |
Check whether the ocl_gpu_device is suitable for use by mdrun. More... | |
static ocl_vendor_id_t | get_vendor_id (char *vendor_name) |
Returns an ocl_vendor_id_t value corresponding to the input OpenCL vendor name. More... | |
bool | isGpuDetectionFunctional (std::string *errorMessage) |
Return whether GPU detection is functioning correctly. More... | |
void | findGpus (gmx_gpu_info_t *gpu_info) |
Find all GPUs in the system. 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... | |
void | init_gpu (const gmx_device_info_t *deviceInfo) |
Initializes the GPU described by deviceInfo . 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... | |
size_t | sizeof_gpu_dev_info () |
Returns the size of the gpu_dev_info struct. More... | |
int | gpu_info_get_stat (const gmx_gpu_info_t &info, int index) |
Get status of device with specified index. | |
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 canPerformGpuDetection() 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) |
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 |
|
static |
Returns an ocl_vendor_id_t value corresponding to the input OpenCL vendor name.
[in] | vendor_name | String with OpenCL vendor name. |
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
. 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.
bool isGpuDetectionFunctional | ( | std::string * | errorMessage | ) |
Return whether GPU detection is functioning correctly.
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.
|
static |
Return true if executing on compatible OS for AMD OpenCL.
This is assumed to be true for OS X version of at least 10.10.4 and all other OS flavors.
Uses the BSD sysctl() interfaces to extract the kernel version.
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.