1 | /* |
2 | * cuda_launch.hpp |
3 | * |
4 | * Created on: Jan 14, 2019 |
5 | * Author: i-bird |
6 | */ |
7 | |
8 | #ifndef CUDA_LAUNCH_HPP_ |
9 | #define CUDA_LAUNCH_HPP_ |
10 | |
11 | #include "config.h" |
12 | #include "cuda_kernel_error_checker.hpp" |
13 | |
14 | #if defined(CUDA_GPU) && !defined(CUDA_ON_CPU) |
15 | |
16 | #if defined(SE_CLASS1) || defined(CUDA_CHECK_LAUNCH) |
17 | |
18 | #define CUDA_LAUNCH(cuda_call,ite, ...) \ |
19 | {\ |
20 | cudaDeviceSynchronize(); \ |
21 | {\ |
22 | cudaError_t e = cudaGetLastError();\ |
23 | if (e != cudaSuccess)\ |
24 | {\ |
25 | std::string error = cudaGetErrorString(e);\ |
26 | std::cout << "Cuda an error has occurred before this CUDA_LAUNCH, detected in: " << __FILE__ << ":" << __LINE__ << " " << error << std::endl;\ |
27 | }\ |
28 | }\ |
29 | CHECK_SE_CLASS1_PRE\ |
30 | if (ite.wthr.x != 0)\ |
31 | {cuda_call<<<ite.wthr,ite.thr>>>(__VA_ARGS__);}\ |
32 | cudaDeviceSynchronize(); \ |
33 | {\ |
34 | cudaError_t e = cudaGetLastError();\ |
35 | if (e != cudaSuccess)\ |
36 | {\ |
37 | std::string error = cudaGetErrorString(e);\ |
38 | std::cout << "Cuda Error in: " << __FILE__ << ":" << __LINE__ << " " << error << std::endl;\ |
39 | }\ |
40 | CHECK_SE_CLASS1_POST(#cuda_call,__VA_ARGS__)\ |
41 | }\ |
42 | } |
43 | |
44 | #define CUDA_LAUNCH_DIM3(cuda_call,wthr,thr, ...) \ |
45 | {\ |
46 | cudaDeviceSynchronize(); \ |
47 | {\ |
48 | cudaError_t e = cudaGetLastError();\ |
49 | if (e != cudaSuccess)\ |
50 | {\ |
51 | std::string error = cudaGetErrorString(e);\ |
52 | std::cout << "Cuda an error has occurred before this CUDA_LAUNCH, detected in: " << __FILE__ << ":" << __LINE__ << " " << error << std::endl;\ |
53 | }\ |
54 | }\ |
55 | CHECK_SE_CLASS1_PRE\ |
56 | cuda_call<<<wthr,thr>>>(__VA_ARGS__);\ |
57 | cudaDeviceSynchronize(); \ |
58 | {\ |
59 | cudaError_t e = cudaGetLastError();\ |
60 | if (e != cudaSuccess)\ |
61 | {\ |
62 | std::string error = cudaGetErrorString(e);\ |
63 | std::cout << "Cuda Error in: " << __FILE__ << ":" << __LINE__ << " " << error << std::endl;\ |
64 | }\ |
65 | CHECK_SE_CLASS1_POST(#cuda_call,__VA_ARGS__)\ |
66 | }\ |
67 | } |
68 | |
69 | #define CUDA_CHECK() \ |
70 | {\ |
71 | cudaDeviceSynchronize(); \ |
72 | {\ |
73 | cudaError_t e = cudaGetLastError();\ |
74 | if (e != cudaSuccess)\ |
75 | {\ |
76 | std::string error = cudaGetErrorString(e);\ |
77 | std::cout << "Cuda an error has occurred before, detected in: " << __FILE__ << ":" << __LINE__ << " " << error << std::endl;\ |
78 | }\ |
79 | }\ |
80 | CHECK_SE_CLASS1_PRE\ |
81 | cudaDeviceSynchronize(); \ |
82 | {\ |
83 | cudaError_t e = cudaGetLastError();\ |
84 | if (e != cudaSuccess)\ |
85 | {\ |
86 | std::string error = cudaGetErrorString(e);\ |
87 | std::cout << "Cuda Error in: " << __FILE__ << ":" << __LINE__ << " " << error << std::endl;\ |
88 | }\ |
89 | CHECK_SE_CLASS1_POST("no call","no args")\ |
90 | }\ |
91 | } |
92 | |
93 | #else |
94 | |
95 | #define CUDA_LAUNCH(cuda_call,ite, ...) \ |
96 | if (ite.wthr.x != 0)\ |
97 | {cuda_call<<<ite.wthr,ite.thr>>>(__VA_ARGS__);} |
98 | |
99 | #define CUDA_LAUNCH_DIM3(cuda_call,wthr,thr, ...) \ |
100 | cuda_call<<<wthr,thr>>>(__VA_ARGS__); |
101 | |
102 | #define CUDA_CHECK() |
103 | |
104 | #endif |
105 | |
106 | #else |
107 | |
108 | #include "util/cudify/cudify.hpp" |
109 | |
110 | #endif |
111 | |
112 | #endif /* CUDA_LAUNCH_HPP_ */ |
113 | |