fixed: division by zero if no gpu device was found

This commit is contained in:
Arne Morten Kvarving 2024-11-01 10:29:51 +01:00
parent e81cf62e79
commit 8b21902f74

View File

@ -37,7 +37,7 @@ namespace Opm::gpuistl {
into problems with this code when using multiple MPI ranks. into problems with this code when using multiple MPI ranks.
The simulation might hang because the integrated GPU in the CPU The simulation might hang because the integrated GPU in the CPU
is detected has Radeon compute units, but it does not support ROCM. is detected has Radeon compute units, but it does not support ROCM.
This is fixable my making only the GPUS on your system visible with This is fixable by making only the GPUS on your system visible with
ROCR_VISIBLE_DEVICES environment variable. ROCR_VISIBLE_DEVICES environment variable.
*/ */
void printDevice() void printDevice()
@ -51,22 +51,23 @@ namespace Opm::gpuistl {
int deviceCount = -1; int deviceCount = -1;
OPM_GPU_WARN_IF_ERROR(cudaGetDeviceCount(&deviceCount)); OPM_GPU_WARN_IF_ERROR(cudaGetDeviceCount(&deviceCount));
const auto deviceId = mpiRank % deviceCount;
struct cudaDeviceProp props;
OPM_GPU_WARN_IF_ERROR(cudaGetDeviceProperties(&props, deviceId));
std::string out;
out = fmt::format("rank: {}, GPU: {}, Compute Capability: {}.{} (device {} out of {})\n",
mpiRank, props.name, props.major, props.minor, deviceId, deviceCount);
auto deferred_logger = ::Opm::DeferredLogger(); auto deferred_logger = ::Opm::DeferredLogger();
deferred_logger.info(out); if (deviceCount > 0) {
const auto deviceId = mpiRank % deviceCount;
struct cudaDeviceProp props;
OPM_GPU_WARN_IF_ERROR(cudaGetDeviceProperties(&props, deviceId));
std::string out;
out = fmt::format("rank: {}, GPU: {}, Compute Capability: {}.{} (device {} out of {})\n",
mpiRank, props.name, props.major, props.minor, deviceId, deviceCount);
deferred_logger.info(out);
}
DeferredLogger global = gatherDeferredLogger(deferred_logger, FlowGenericVanguard::comm()); DeferredLogger global = gatherDeferredLogger(deferred_logger, FlowGenericVanguard::comm());
if (mpiRank == 0) { if (mpiRank == 0) {
global.logMessages(); global.logMessages();
} }
#endif #endif
} }