Skip to content

Commit a2fe732

Browse files
committed
Use different exit codes for different conditions
1 parent c91a0dd commit a2fe732

File tree

6 files changed

+56
-14
lines changed

6 files changed

+56
-14
lines changed

HeterogeneousCore/CUDAUtilities/bin/cudaIsEnabled.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,28 @@
44
// CUDA headers
55
#include <cuda_runtime.h>
66

7+
// CMSSW headers
8+
#include "HeterogeneousCore/Common/interface/PlatformStatus.h"
9+
710
// local headers
811
#include "isCudaDeviceSupported.h"
912

10-
// returns EXIT_SUCCESS if at least one visible CUDA device can be used, or EXIT_FAILURE otherwise
13+
// returns PlatformStatus::Success if at least one visible CUDA device can be used,
14+
// or different failure codes depending on the problem.
1115
int main() {
1216
int devices = 0;
1317
auto status = cudaGetDeviceCount(&devices);
1418
if (status != cudaSuccess) {
15-
return EXIT_FAILURE;
19+
// could not initialise the CUDA runtime
20+
return PlatformStatus::RuntimeNotAvailable;
1621
}
1722

1823
// check that at least one visible CUDA device can be used
1924
for (int i = 0; i < devices; ++i) {
2025
if (isCudaDeviceSupported(i))
21-
return EXIT_SUCCESS;
26+
return PlatformStatus::Success;
2227
}
2328

24-
// no visible usable devices
25-
return EXIT_FAILURE;
29+
// could not find any usable CUDA devices
30+
return PlatformStatus::DevicesNotAvailable;
2631
}
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
// C/C++ headers
22
#include <cstdlib>
33

4-
// always returns EXIT_FAILURE
5-
int main() { return EXIT_FAILURE; }
4+
// CMSSW headers
5+
#include "HeterogeneousCore/Common/interface/PlatformStatus.h"
6+
7+
int main() {
8+
// CUDA is not available on this architecture, OS and compiler combination
9+
return PlatformStatus::PlatformNotAvailable;
10+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#ifndef HeterogeneousCore_Common_interface_PlatformStatus_h
2+
#define HeterogeneousCore_Common_interface_PlatformStatus_h
3+
4+
// Please note: these values must be kept in sync with HeterogeneousCore/Common/python/PlatformStatus.py
5+
6+
enum PlatformStatus : int {
7+
Success = 0,
8+
PlatformNotAvailable = 1, // the platform is not available for this architecture, OS or compiler
9+
RuntimeNotAvailable = 2, // the runtime could not be initialised
10+
DevicesNotAvailable = 3, // there are no visible, usable devices
11+
};
12+
13+
#endif // HeterogeneousCore_Common_interface_PlatformStatus_h
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import enum
2+
3+
# Please note: these values must be kept in sync with HeterogeneousCore/Common/interface/PlatformStatus.h
4+
5+
class PlatformStatus(enum.IntEnum):
6+
Success = 0
7+
PlatformNotAvailable = 1 # the platform is not available for this architecture, OS or compiler
8+
RuntimeNotAvailable = 2 # the runtime could not be initialised
9+
DevicesNotAvailable = 3 # there are no visible, usable devices

HeterogeneousCore/ROCmUtilities/bin/rocmIsEnabled.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,28 @@
44
// ROCm headers
55
#include <hip/hip_runtime.h>
66

7+
// CMSSW headers
8+
#include "HeterogeneousCore/Common/interface/PlatformStatus.h"
9+
710
// local headers
811
#include "isRocmDeviceSupported.h"
912

10-
// returns EXIT_SUCCESS if at least one visible ROCm device can be used, or EXIT_FAILURE otherwise
13+
// returns PlatformStatus::Success if at least one visible ROCm device can be used,
14+
// or different failure codes depending on the problem.
1115
int main() {
1216
int devices = 0;
1317
auto status = hipGetDeviceCount(&devices);
1418
if (status != hipSuccess) {
15-
return EXIT_FAILURE;
19+
// could not initialise the ROCm runtime
20+
return PlatformStatus::RuntimeNotAvailable;
1621
}
1722

1823
// check that at least one visible ROCm device can be used
1924
for (int i = 0; i < devices; ++i) {
2025
if (isRocmDeviceSupported(i))
21-
return EXIT_SUCCESS;
26+
return PlatformStatus::Success;
2227
}
2328

24-
// no visible usable devices
25-
return EXIT_FAILURE;
29+
// no usable ROCm devices were found
30+
return PlatformStatus::DevicesNotAvailable;
2631
}
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
// C/C++ headers
22
#include <cstdlib>
33

4-
// always returns EXIT_FAILURE
5-
int main() { return EXIT_FAILURE; }
4+
// CMSSW headers
5+
#include "HeterogeneousCore/Common/interface/PlatformStatus.h"
6+
7+
int main() {
8+
// ROCm is not available on this architecture, OS and compiler combination
9+
return PlatformStatus::PlatformNotAvailable;
10+
}

0 commit comments

Comments
 (0)