Skip to content

Commit

Permalink
Use different exit codes for different conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
fwyzard committed Feb 23, 2023
1 parent c91a0dd commit a2fe732
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 14 deletions.
15 changes: 10 additions & 5 deletions HeterogeneousCore/CUDAUtilities/bin/cudaIsEnabled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,28 @@
// CUDA headers
#include <cuda_runtime.h>

// CMSSW headers
#include "HeterogeneousCore/Common/interface/PlatformStatus.h"

// local headers
#include "isCudaDeviceSupported.h"

// returns EXIT_SUCCESS if at least one visible CUDA device can be used, or EXIT_FAILURE otherwise
// returns PlatformStatus::Success if at least one visible CUDA device can be used,
// or different failure codes depending on the problem.
int main() {
int devices = 0;
auto status = cudaGetDeviceCount(&devices);
if (status != cudaSuccess) {
return EXIT_FAILURE;
// could not initialise the CUDA runtime
return PlatformStatus::RuntimeNotAvailable;
}

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

// no visible usable devices
return EXIT_FAILURE;
// could not find any usable CUDA devices
return PlatformStatus::DevicesNotAvailable;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
// C/C++ headers
#include <cstdlib>

// always returns EXIT_FAILURE
int main() { return EXIT_FAILURE; }
// CMSSW headers
#include "HeterogeneousCore/Common/interface/PlatformStatus.h"

int main() {
// CUDA is not available on this architecture, OS and compiler combination
return PlatformStatus::PlatformNotAvailable;
}
13 changes: 13 additions & 0 deletions HeterogeneousCore/Common/interface/PlatformStatus.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef HeterogeneousCore_Common_interface_PlatformStatus_h
#define HeterogeneousCore_Common_interface_PlatformStatus_h

// Please note: these values must be kept in sync with HeterogeneousCore/Common/python/PlatformStatus.py

enum PlatformStatus : int {
Success = 0,
PlatformNotAvailable = 1, // the platform is not available for this architecture, OS or compiler
RuntimeNotAvailable = 2, // the runtime could not be initialised
DevicesNotAvailable = 3, // there are no visible, usable devices
};

#endif // HeterogeneousCore_Common_interface_PlatformStatus_h
9 changes: 9 additions & 0 deletions HeterogeneousCore/Common/python/PlatformStatus.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import enum

# Please note: these values must be kept in sync with HeterogeneousCore/Common/interface/PlatformStatus.h

class PlatformStatus(enum.IntEnum):
Success = 0
PlatformNotAvailable = 1 # the platform is not available for this architecture, OS or compiler
RuntimeNotAvailable = 2 # the runtime could not be initialised
DevicesNotAvailable = 3 # there are no visible, usable devices
15 changes: 10 additions & 5 deletions HeterogeneousCore/ROCmUtilities/bin/rocmIsEnabled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,28 @@
// ROCm headers
#include <hip/hip_runtime.h>

// CMSSW headers
#include "HeterogeneousCore/Common/interface/PlatformStatus.h"

// local headers
#include "isRocmDeviceSupported.h"

// returns EXIT_SUCCESS if at least one visible ROCm device can be used, or EXIT_FAILURE otherwise
// returns PlatformStatus::Success if at least one visible ROCm device can be used,
// or different failure codes depending on the problem.
int main() {
int devices = 0;
auto status = hipGetDeviceCount(&devices);
if (status != hipSuccess) {
return EXIT_FAILURE;
// could not initialise the ROCm runtime
return PlatformStatus::RuntimeNotAvailable;
}

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

// no visible usable devices
return EXIT_FAILURE;
// no usable ROCm devices were found
return PlatformStatus::DevicesNotAvailable;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
// C/C++ headers
#include <cstdlib>

// always returns EXIT_FAILURE
int main() { return EXIT_FAILURE; }
// CMSSW headers
#include "HeterogeneousCore/Common/interface/PlatformStatus.h"

int main() {
// ROCm is not available on this architecture, OS and compiler combination
return PlatformStatus::PlatformNotAvailable;
}

0 comments on commit a2fe732

Please sign in to comment.