diff options
author | Jan Alexander Steffens (heftig) <jan.steffens@gmail.com> | 2020-01-07 23:48:18 +0100 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2020-01-24 14:28:06 +0200 |
commit | 03065f2f008bbc5feb732412c41fc61848a6725f (patch) | |
tree | 0e6cb91e17c9ce3d44bc85d785f363c675b0b9e6 /test cases/cuda | |
parent | 8be4802b0b241acc83c16cc1e00e41fcf3a301fa (diff) | |
download | meson-03065f2f008bbc5feb732412c41fc61848a6725f.zip meson-03065f2f008bbc5feb732412c41fc61848a6725f.tar.gz meson-03065f2f008bbc5feb732412c41fc61848a6725f.tar.bz2 |
Fix CUDA test without devices.
Getting the runtime version fails when no devices are present.
Diffstat (limited to 'test cases/cuda')
-rw-r--r-- | test cases/cuda/11 cuda dependency (nvcc)/version_reqs/prog.cu | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/test cases/cuda/11 cuda dependency (nvcc)/version_reqs/prog.cu b/test cases/cuda/11 cuda dependency (nvcc)/version_reqs/prog.cu index 5668830..bc90081 100644 --- a/test cases/cuda/11 cuda dependency (nvcc)/version_reqs/prog.cu +++ b/test cases/cuda/11 cuda dependency (nvcc)/version_reqs/prog.cu @@ -9,20 +9,21 @@ int cuda_devices(void) { int main(void) { std::cout << "Compiled against CUDA version: " << CUDART_VERSION << "\n"; + int runtime_version = 0; - cudaError_t r = cudaRuntimeGetVersion(&runtime_version); - if (r != cudaSuccess) { - std::cout << "Couldn't obtain CUDA runtime version (error " << r << "). Exiting.\n"; - return -1; + switch (cudaError_t r = cudaRuntimeGetVersion(&runtime_version)) { + case cudaSuccess: + std::cout << "CUDA runtime version: " << runtime_version << "\n"; + break; + case cudaErrorNoDevice: + std::cout << "No CUDA hardware found. Exiting.\n"; + return 0; + default: + std::cout << "Couldn't obtain CUDA runtime version (error " << r << "). Exiting.\n"; + return -1; } - std::cout << "CUDA runtime version: " << runtime_version << "\n"; int n = cuda_devices(); - if (n == 0) { - std::cout << "No CUDA hardware found. Exiting.\n"; - return 0; - } - std::cout << "Found " << n << " CUDA devices.\n"; return 0; } |