OWL
OptiX7 Wrapper Library
cuda.h
Go to the documentation of this file.
1 // ======================================================================== //
2 // Copyright 2019-2020 Ingo Wald //
3 // //
4 // Licensed under the Apache License, Version 2.0 (the "License"); //
5 // you may not use this file except in compliance with the License. //
6 // You may obtain a copy of the License at //
7 // //
8 // http://www.apache.org/licenses/LICENSE-2.0 //
9 // //
10 // Unless required by applicable law or agreed to in writing, software //
11 // distributed under the License is distributed on an "AS IS" BASIS, //
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //
13 // See the License for the specific language governing permissions and //
14 // limitations under the License. //
15 // ======================================================================== //
16 
17 #pragma once
18 
19 #include "owl/common.h"
20 #include <cuda_runtime.h>
21 
22 #define CUDA_CHECK( call ) \
23  { \
24  cudaError_t rc = call; \
25  if (rc != cudaSuccess) { \
26  fprintf(stderr, \
27  "CUDA call (%s) failed with code %d (line %d): %s\n", \
28  #call, rc, __LINE__, cudaGetErrorString(rc)); \
29  throw std::runtime_error("fatal cuda error"); \
30  } \
31  }
32 
33 #define CUDA_CALL(call) CUDA_CHECK(cuda##call)
34 
35 #define CUDA_CHECK2( where, call ) \
36  { \
37  cudaError_t rc = call; \
38  if(rc != cudaSuccess) { \
39  if (where) \
40  fprintf(stderr, "at %s: CUDA call (%s) " \
41  "failed with code %d (line %d): %s\n", \
42  where,#call, rc, __LINE__, cudaGetErrorString(rc)); \
43  fprintf(stderr, \
44  "CUDA call (%s) failed with code %d (line %d): %s\n", \
45  #call, rc, __LINE__, cudaGetErrorString(rc)); \
46  throw std::runtime_error("fatal cuda error"); \
47  } \
48  }
49 
50 #define CUDA_SYNC_CHECK() \
51  { \
52  cudaDeviceSynchronize(); \
53  cudaError_t rc = cudaGetLastError(); \
54  if (rc != cudaSuccess) { \
55  fprintf(stderr, "error (%s: line %d): %s\n", \
56  __FILE__, __LINE__, cudaGetErrorString(rc)); \
57  throw std::runtime_error("fatal cuda error"); \
58  } \
59  }
60 
61 
62 
63 #define CUDA_CHECK_NOTHROW( call ) \
64  { \
65  cudaError_t rc = call; \
66  if (rc != cudaSuccess) { \
67  fprintf(stderr, \
68  "CUDA call (%s) failed with code %d (line %d): %s\n", \
69  #call, rc, __LINE__, cudaGetErrorString(rc)); \
70  exit(2); \
71  } \
72  }
73 
74 #define CUDA_CALL_NOTHROW(call) CUDA_CHECK_NOTHROW(cuda##call)
75 
76 #define CUDA_CHECK2_NOTHROW( where, call ) \
77  { \
78  cudaError_t rc = call; \
79  if(rc != cudaSuccess) { \
80  if (where) \
81  fprintf(stderr, "at %s: CUDA call (%s) " \
82  "failed with code %d (line %d): %s\n", \
83  where,#call, rc, __LINE__, cudaGetErrorString(rc)); \
84  fprintf(stderr, \
85  "CUDA call (%s) failed with code %d (line %d): %s\n", \
86  #call, rc, __LINE__, cudaGetErrorString(rc)); \
87  throw std::runtime_error("fatal cuda error"); \
88  } \
89  }
90 
common.h