OWL
Loading...
Searching...
No Matches
cuda.h
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 OWL_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 OWL_RAISE("fatal cuda error"); \
30 } \
31 }
32
33#define OWL_CUDA_CALL(call) OWL_CUDA_CHECK(cuda##call)
34
35#define OWL_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 OWL_RAISE("fatal cuda error"); \
47 } \
48 }
49
50#define OWL_CUDA_SYNC_CHECK() \
51 { \
52 cudaError_t rc = cudaDeviceSynchronize(); \
53 if (rc != cudaSuccess) { \
54 fprintf(stderr, "error (%s: line %d): %s\n", \
55 __FILE__, __LINE__, cudaGetErrorString(rc)); \
56 OWL_RAISE("fatal cuda error"); \
57 } \
58 }
59
60#define OWL_CUDA_SYNC_CHECK_STREAM(s) \
61 { \
62 cudaError_t rc = cudaStreamSynchronize(s); \
63 if (rc != cudaSuccess) { \
64 fprintf(stderr, "error (%s: line %d): %s\n", \
65 __FILE__, __LINE__, cudaGetErrorString(rc)); \
66 OWL_RAISE("fatal cuda error"); \
67 } \
68 }
69
70
71
72#define OWL_CUDA_CHECK_NOTHROW( call ) \
73 { \
74 cudaError_t rc = call; \
75 if (rc != cudaSuccess) { \
76 fprintf(stderr, \
77 "CUDA call (%s) failed with code %d (line %d): %s\n", \
78 #call, rc, __LINE__, cudaGetErrorString(rc)); \
79 exit(2); \
80 } \
81 }
82
83#define OWL_CUDA_CALL_NOTHROW(call) OWL_CUDA_CHECK_NOTHROW(cuda##call)
84
85#define OWL_CUDA_CHECK2_NOTHROW( where, call ) \
86 { \
87 cudaError_t rc = call; \
88 if(rc != cudaSuccess) { \
89 if (where) \
90 fprintf(stderr, "at %s: CUDA call (%s) " \
91 "failed with code %d (line %d): %s\n", \
92 where,#call, rc, __LINE__, cudaGetErrorString(rc)); \
93 fprintf(stderr, \
94 "CUDA call (%s) failed with code %d (line %d): %s\n", \
95 #call, rc, __LINE__, cudaGetErrorString(rc)); \
96 exit(2); \
97 } \
98 }
99