xref: /aosp_15_r20/external/pytorch/c10/cuda/impl/CUDATest.cpp (revision da0073e96a02ea20f0ac840b70461e3646d07c45)
1 // Just a little test file to make sure that the CUDA library works
2 
3 #include <c10/cuda/CUDAException.h>
4 #include <c10/cuda/impl/CUDATest.h>
5 
6 #include <cuda_runtime.h>
7 
8 namespace c10::cuda::impl {
9 
has_cuda_gpu()10 bool has_cuda_gpu() {
11   int count = 0;
12   C10_CUDA_IGNORE_ERROR(cudaGetDeviceCount(&count));
13 
14   return count != 0;
15 }
16 
c10_cuda_test()17 int c10_cuda_test() {
18   int r = 0;
19   if (has_cuda_gpu()) {
20     C10_CUDA_CHECK(cudaGetDevice(&r));
21   }
22   return r;
23 }
24 
25 // This function is not exported
c10_cuda_private_test()26 int c10_cuda_private_test() {
27   return 2;
28 }
29 
30 } // namespace c10::cuda::impl
31