Skip to content

Commit

Permalink
core: Update GPU name string size
Browse files Browse the repository at this point in the history
Modern CUDA releases use 256 characters.
  • Loading branch information
jngrad committed Apr 25, 2024
1 parent 7cced5b commit 9e81648
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/core/cuda_init.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct EspressoGpuDevice {
/** Local CUDA device id */
int id;
/** Local CUDA device name */
char name[64];
char name[256];
/** Node identification */
char proc_name[64];
/** MPI process identification */
Expand Down Expand Up @@ -71,9 +71,9 @@ int cuda_check_gpu_compute_capability(int dev);
/** Get the name of a CUDA device.
*
* @param[in] dev the CUDA device number to ask the name for
* @param[out] name a buffer to write the name to, at least 64 characters
* @param[out] name a buffer to write the name to, at least 256 characters
*/
void cuda_get_gpu_name(int dev, char name[64]);
void cuda_get_gpu_name(int dev, char *name);

/** Choose a device for future CUDA computations.
*
Expand Down
18 changes: 13 additions & 5 deletions src/core/cuda_init_cuda.cu
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,20 @@ int cuda_check_gpu_compute_capability(int dev) {
return ES_OK;
}

void cuda_get_gpu_name(int dev, char name[64]) {
/**
* @brief Safely copy the device name and pad the string with null characters.
*/
static void cuda_copy_gpu_name(char *const name, cudaDeviceProp const &prop) {
char buffer[256] = {'\0'};
std::strncpy(buffer, prop.name, 256);
name[255] = '\0';
std::strncpy(name, buffer, 256);
}

void cuda_get_gpu_name(int dev, char *const name) {
cudaDeviceProp deviceProp;
CUDA_CHECK(cudaGetDeviceProperties(&deviceProp, dev))
std::strncpy(name, deviceProp.name, 63);
name[63] = 0;
cuda_copy_gpu_name(name, deviceProp);
}

EspressoGpuDevice cuda_get_device_props(const int dev) {
Expand All @@ -76,8 +85,7 @@ EspressoGpuDevice cuda_get_device_props(const int dev) {
deviceProp.minor,
deviceProp.totalGlobalMem,
deviceProp.multiProcessorCount};
std::strncpy(device.name, deviceProp.name, 64);
device.name[63] = '\0';
cuda_copy_gpu_name(device.name, deviceProp);
return device;
}

Expand Down
4 changes: 2 additions & 2 deletions src/python/espressomd/cuda_init.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ from libcpp.vector cimport vector
cdef extern from "cuda_init.hpp":
cdef struct EspressoGpuDevice:
int id
char name[64]
char name[256]
char proc_name[64]
int node
int compute_capability_major
Expand All @@ -33,5 +33,5 @@ cdef extern from "cuda_init.hpp":
void cuda_set_device(int dev) except +
int cuda_get_device() except +
int cuda_get_n_gpus() except +
void cuda_get_gpu_name(int dev, char name[64]) except +
void cuda_get_gpu_name(int dev, char * name) except +
vector[EspressoGpuDevice] cuda_gather_gpus()
2 changes: 1 addition & 1 deletion src/python/espressomd/cuda_init.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ cdef class CudaInitHandle:
List of available CUDA devices.
"""
cdef char gpu_name_buffer[4 + 64]
cdef char gpu_name_buffer[256]
n_gpus = 0
try:
n_gpus = cuda_get_n_gpus()
Expand Down

0 comments on commit 9e81648

Please sign in to comment.