Skip to content

Commit 9e81648

Browse files
committed
core: Update GPU name string size
Modern CUDA releases use 256 characters.
1 parent 7cced5b commit 9e81648

File tree

4 files changed

+19
-11
lines changed

4 files changed

+19
-11
lines changed

src/core/cuda_init.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ struct EspressoGpuDevice {
3434
/** Local CUDA device id */
3535
int id;
3636
/** Local CUDA device name */
37-
char name[64];
37+
char name[256];
3838
/** Node identification */
3939
char proc_name[64];
4040
/** MPI process identification */
@@ -71,9 +71,9 @@ int cuda_check_gpu_compute_capability(int dev);
7171
/** Get the name of a CUDA device.
7272
*
7373
* @param[in] dev the CUDA device number to ask the name for
74-
* @param[out] name a buffer to write the name to, at least 64 characters
74+
* @param[out] name a buffer to write the name to, at least 256 characters
7575
*/
76-
void cuda_get_gpu_name(int dev, char name[64]);
76+
void cuda_get_gpu_name(int dev, char *name);
7777

7878
/** Choose a device for future CUDA computations.
7979
*

src/core/cuda_init_cuda.cu

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,20 @@ int cuda_check_gpu_compute_capability(int dev) {
5858
return ES_OK;
5959
}
6060

61-
void cuda_get_gpu_name(int dev, char name[64]) {
61+
/**
62+
* @brief Safely copy the device name and pad the string with null characters.
63+
*/
64+
static void cuda_copy_gpu_name(char *const name, cudaDeviceProp const &prop) {
65+
char buffer[256] = {'\0'};
66+
std::strncpy(buffer, prop.name, 256);
67+
name[255] = '\0';
68+
std::strncpy(name, buffer, 256);
69+
}
70+
71+
void cuda_get_gpu_name(int dev, char *const name) {
6272
cudaDeviceProp deviceProp;
6373
CUDA_CHECK(cudaGetDeviceProperties(&deviceProp, dev))
64-
std::strncpy(name, deviceProp.name, 63);
65-
name[63] = 0;
74+
cuda_copy_gpu_name(name, deviceProp);
6675
}
6776

6877
EspressoGpuDevice cuda_get_device_props(const int dev) {
@@ -76,8 +85,7 @@ EspressoGpuDevice cuda_get_device_props(const int dev) {
7685
deviceProp.minor,
7786
deviceProp.totalGlobalMem,
7887
deviceProp.multiProcessorCount};
79-
std::strncpy(device.name, deviceProp.name, 64);
80-
device.name[63] = '\0';
88+
cuda_copy_gpu_name(device.name, deviceProp);
8189
return device;
8290
}
8391

src/python/espressomd/cuda_init.pxd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ from libcpp.vector cimport vector
2222
cdef extern from "cuda_init.hpp":
2323
cdef struct EspressoGpuDevice:
2424
int id
25-
char name[64]
25+
char name[256]
2626
char proc_name[64]
2727
int node
2828
int compute_capability_major
@@ -33,5 +33,5 @@ cdef extern from "cuda_init.hpp":
3333
void cuda_set_device(int dev) except +
3434
int cuda_get_device() except +
3535
int cuda_get_n_gpus() except +
36-
void cuda_get_gpu_name(int dev, char name[64]) except +
36+
void cuda_get_gpu_name(int dev, char * name) except +
3737
vector[EspressoGpuDevice] cuda_gather_gpus()

src/python/espressomd/cuda_init.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ cdef class CudaInitHandle:
6363
List of available CUDA devices.
6464
6565
"""
66-
cdef char gpu_name_buffer[4 + 64]
66+
cdef char gpu_name_buffer[256]
6767
n_gpus = 0
6868
try:
6969
n_gpus = cuda_get_n_gpus()

0 commit comments

Comments
 (0)