Skip to content

Commit c5c0944

Browse files
committed
Handle CUDA_ERROR_NO_DEVICE returned from cuInit()
During testing of intel/llvm#14145 the CUDA adapter was returning a hard error when being initialized on a system with no NVIDIA GPU. This corner case should not be an error condition so this patch specially handles `CUDA_ERROR_NO_DEVICE` being returned from `cuInit()` (which is an undocumented error code) to exit early from the CUDA adapter initialization.
1 parent 7e38af7 commit c5c0944

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

source/adapters/cuda/platform.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,11 @@ urPlatformGet(ur_adapter_handle_t *, uint32_t, uint32_t NumEntries,
6969
std::call_once(
7070
InitFlag,
7171
[](ur_result_t &Result) {
72-
UR_CHECK_ERROR(cuInit(0));
72+
CUresult InitResult = cuInit(0);
73+
if (InitResult == CUDA_ERROR_NO_DEVICE) {
74+
return; // No devices found which is not an error so exit early.
75+
}
76+
UR_CHECK_ERROR(InitResult);
7377
int NumDevices = 0;
7478
UR_CHECK_ERROR(cuDeviceGetCount(&NumDevices));
7579
try {

0 commit comments

Comments
 (0)