8 #ifndef CUDA_API_WRAPPERS_MISCELLANY_HPP_ 9 #define CUDA_API_WRAPPERS_MISCELLANY_HPP_ 28 static constexpr
const unsigned dummy_flags{0};
29 auto status = cuInit(dummy_flags);
30 throw_if_error_lazy(status,
"Failed initializing the CUDA driver");
33 inline void ensure_driver_is_initialized()
35 thread_local
bool driver_known_to_be_initialized{
false};
36 if (not driver_known_to_be_initialized) {
38 driver_known_to_be_initialized =
true;
62 status_t result = cuDeviceGetCount(&device_count);
64 case status::no_device:
69 throw runtime_error(result,
"Failed obtaining the number of CUDA devices on the system");
71 if (device_count < 0) {
72 throw ::std::logic_error(
"cudaGetDeviceCount() reports an invalid number of CUDA devices");
82 #endif // CUDA_API_WRAPPERS_MISCELLANY_HPP_ All definitions and functionality wrapping the CUDA Runtime API.
Definition: array.hpp:22
device::id_t count()
Get the number of CUDA devices usable on the system (with the current CUDA library and kernel driver)...
Definition: miscellany.hpp:56
CUdevice id_t
Numeric ID of a CUDA device used by the CUDA Runtime API.
Definition: types.hpp:752
void initialize_driver()
Obtains the CUDA Runtime version.
Definition: miscellany.hpp:26
A (base?) class for exceptions raised by CUDA code; these errors are thrown by essentially all CUDA R...
Definition: error.hpp:280
Facilities for exception-based handling of Runtime and Driver API errors, including a basic exception...
Fundamental CUDA-related type definitions.
CUresult status_t
Indicates either the result (success or error index) of a CUDA Runtime or Driver API call...
Definition: types.hpp:136