Skip to content

Commit 996199b

Browse files
Copilotdzzz2001
andcommitted
Fix CUDA GPU detection when device is set to CPU
- Add runtime check for PARAM.inp.device before calling GPU detection functions - Prevent cudaErrcheck from exiting when no GPU is available but device is set to "cpu" - Apply same logic as non-MPI version to MPI version in output_device_info Co-authored-by: dzzz2001 <153698752+dzzz2001@users.noreply.github.com>
1 parent 6dea7c7 commit 996199b

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

source/source_base/module_device/output_device.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,13 @@ void output_device_info(std::ostream &output)
115115
int local_rank = get_node_rank_with_mpi_shared(MPI_COMM_WORLD);
116116

117117
// Get local hardware info
118-
int local_gpu_count = local_rank == 0 ? get_device_num("gpu") : 0;
118+
int local_gpu_count = 0;
119+
#if defined(__CUDA) || defined(__ROCM)
120+
if(PARAM.inp.device == "gpu" && local_rank == 0)
121+
{
122+
local_gpu_count = get_device_num("gpu");
123+
}
124+
#endif
119125
int local_cpu_sockets = local_rank == 0 ? get_device_num("cpu") : 0;
120126

121127
// Prepare vectors to gather data from all ranks
@@ -133,7 +139,13 @@ void output_device_info(std::ostream &output)
133139

134140
// Get device model names (from rank 0 node)
135141
std::string cpu_name = get_device_name("cpu");
136-
std::string gpu_name = get_device_name("gpu");
142+
std::string gpu_name;
143+
#if defined(__CUDA) || defined(__ROCM)
144+
if(PARAM.inp.device == "gpu" && total_gpus > 0)
145+
{
146+
gpu_name = get_device_name("gpu");
147+
}
148+
#endif
137149

138150
// Output all collected information
139151
output << " RUNNING WITH DEVICE : " << "CPU" << " / "

0 commit comments

Comments
 (0)