File: CUDAException.cpp

package info (click to toggle)
pytorch 1.13.1%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 139,252 kB
  • sloc: cpp: 1,100,274; python: 706,454; ansic: 83,052; asm: 7,618; java: 3,273; sh: 2,841; javascript: 612; makefile: 323; xml: 269; ruby: 185; yacc: 144; objc: 68; lex: 44
file content (35 lines) | stat: -rw-r--r-- 866 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <c10/cuda/CUDAException.h>

#include <c10/util/Exception.h>
#include <cuda_runtime.h>

#include <string>

namespace c10 {
namespace cuda {

void c10_cuda_check_implementation(
    const std::string& filename,
    const std::string& function_name,
    const int line_number,
    const bool include_device_assertions) {
  // We retrieve the error here in order to keep CUDA data types out of
  // CUDAException.h thereby simplifying including it in other files
  const cudaError_t err = cudaGetLastError();

  if (C10_LIKELY(err == cudaSuccess)) {
    return;
  }

  std::string check_message;
#ifndef STRIP_ERROR_MESSAGES
  check_message.append("CUDA error: ");
  check_message.append(cudaGetErrorString(err));
  check_message.append(c10::cuda::get_cuda_check_suffix());
#endif

  TORCH_CHECK(false, check_message);
}

} // namespace cuda
} // namespace c10