Merge pull request #5705 from akva2/fix_div_by_zero_no_gpus

fixed: division by zero if no gpu device was found
This commit is contained in:
Bård Skaflestad 2024-11-01 13:09:24 +01:00 committed by GitHub
commit fadc96da44
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

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
} }