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 11, 2024
1 parent 6d01134 commit a348b1a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/core/cuda/init.hpp
Expand Up @@ -36,7 +36,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 @@ -73,9 +73,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
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
2 changes: 1 addition & 1 deletion src/script_interface/system/CudaInitHandle.cpp
Expand Up @@ -59,7 +59,7 @@ Variant CudaInitHandle::do_call_method(std::string const &name,
invoke_skip_cuda_exceptions([&n_gpus]() { n_gpus = cuda_get_n_gpus(); });
for (int i = 0; i < n_gpus; ++i) {
invoke_skip_cuda_exceptions([&devices, i]() {
char gpu_name_buffer[4 + 64];
char gpu_name_buffer[256] = {'\0'};
cuda_get_gpu_name(i, gpu_name_buffer);
devices[i] = std::string{gpu_name_buffer};
});
Expand Down

0 comments on commit a348b1a

Please sign in to comment.