1 | #include <c10/cuda/CUDAException.h> |
---|---|
2 | |
3 | #include <c10/cuda/CUDADeviceAssertionHost.h> |
4 | #include <c10/util/Exception.h> |
5 | #include <cuda_runtime.h> |
6 | |
7 | #include <string> |
8 | |
9 | namespace c10 { |
10 | namespace cuda { |
11 | |
12 | void c10_cuda_check_implementation( |
13 | const int32_t err, |
14 | const char* filename, |
15 | const char* function_name, |
16 | const int line_number, |
17 | const bool include_device_assertions) { |
18 | const auto cuda_error = static_cast<cudaError_t>(err); |
19 | const auto cuda_kernel_failure = include_device_assertions |
20 | ? c10::cuda::CUDAKernelLaunchRegistry::get_singleton_ref().has_failed() |
21 | : false; |
22 | |
23 | if (C10_LIKELY(cuda_error == cudaSuccess && !cuda_kernel_failure)) { |
24 | return; |
25 | } |
26 | |
27 | auto error_unused C10_UNUSED = cudaGetLastError(); |
28 | (void)error_unused; |
29 | |
30 | std::string check_message; |
31 | #ifndef STRIP_ERROR_MESSAGES |
32 | check_message.append("CUDA error: "); |
33 | check_message.append(cudaGetErrorString(cuda_error)); |
34 | check_message.append(c10::cuda::get_cuda_check_suffix()); |
35 | check_message.append("\n"); |
36 | if (include_device_assertions) { |
37 | check_message.append(c10_retrieve_device_side_assertion_info()); |
38 | } else { |
39 | check_message.append( |
40 | "Device-side assertions were explicitly omitted for this error check; the error probably arose while initializing the DSA handlers."); |
41 | } |
42 | #endif |
43 | |
44 | TORCH_CHECK(false, check_message); |
45 | } |
46 | |
47 | } // namespace cuda |
48 | } // namespace c10 |
49 |