[all-commits] [llvm/llvm-project] cfa6e7: [Libomptarget] Don't report lack of CUDA devices
Joel E. Denny via All-commits
all-commits at lists.llvm.org
Fri Jul 22 11:50:37 PDT 2022
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: cfa6e79df30c7f9ea319d304670dcce7e9376787
https://github.com/llvm/llvm-project/commit/cfa6e79df30c7f9ea319d304670dcce7e9376787
Author: Joel E. Denny <jdenny.ornl at gmail.com>
Date: 2022-07-22 (Fri, 22 Jul 2022)
Changed paths:
M openmp/libomptarget/plugins/cuda/dynamic_cuda/cuda.h
M openmp/libomptarget/plugins/cuda/src/rtl.cpp
A openmp/libomptarget/test/offloading/cuda_no_devices.c
Log Message:
-----------
[Libomptarget] Don't report lack of CUDA devices
Sometimes libomptarget's CUDA plugin produces unhelpful diagnostics
about a lack of CUDA devices before an application runs:
```
$ clang -fopenmp -fopenmp-targets=amdgcn-amd-amdhsa hello-world.c
$ ./a.out
CUDA error: Error returned from cuInit
CUDA error: no CUDA-capable device is detected
Hello World: 4
```
This can happen when the CUDA plugin was built but all CUDA devices
are currently disabled in some manner, perhaps because
`CUDA_VISIBLE_DEVICES` is set to the empty string. As shown in the
above example, it can even happen when we haven't compiled the
application for offloading to CUDA.
The following code from `openmp/libomptarget/plugins/cuda/src/rtl.cpp`
appears to be intended to handle this case, and it chooses not to
write a diagnostic to stderr unless debugging is enabled:
```
if (NumberOfDevices == 0) {
DP("There are no devices supporting CUDA.\n");
return;
}
```
The problem is that the above code is never reached because the
earlier `cuInit` returns `CUDA_ERROR_NO_DEVICE`. This patch handles
that `cuInit` case in the same manner as the above code handles the
`NumberOfDevices == 0` case.
Reviewed By: tianshilei1992
Differential Revision: https://reviews.llvm.org/D130371
More information about the All-commits
mailing list