cuda_launch.hpp 3.08 KB
Newer Older
incardon's avatar
incardon committed
1
2
3
4
5
6
7
8
9
10
/*
 * cuda_launch.hpp
 *
 *  Created on: Jan 14, 2019
 *      Author: i-bird
 */

#ifndef CUDA_LAUNCH_HPP_
#define CUDA_LAUNCH_HPP_

incardon's avatar
incardon committed
11
#include "config.h"
incardon's avatar
incardon committed
12
13
#include "cuda_kernel_error_checker.hpp"

incardon's avatar
incardon committed
14
#if defined(__NVCC__) && !defined(CUDA_ON_CPU) && !defined(__HIP__)
incardon's avatar
incardon committed
15
16
17

	constexpr int default_kernel_wg_threads_ = 1024;

incardon's avatar
incardon committed
18
19
20
21
22
23
24
25
	#if CUDART_VERSION >= 11000
		#include "cub/util_type.cuh"
		#include "cub/block/block_scan.cuh"
	#else
		#include "cub_old/util_type.cuh"
		#include "cub_old/block/block_scan.cuh"
	#endif

incardon's avatar
incardon committed
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118

	#if defined(SE_CLASS1) || defined(CUDA_CHECK_LAUNCH)

	#define CUDA_LAUNCH(cuda_call,ite, ...) \
			{\
			cudaDeviceSynchronize(); \
			{\
				cudaError_t e = cudaGetLastError();\
				if (e != cudaSuccess)\
				{\
					std::string error = cudaGetErrorString(e);\
					std::cout << "Cuda an error has occurred before this CUDA_LAUNCH, detected in: " << __FILE__ << ":" << __LINE__ << " " << error << std::endl;\
				}\
			}\
			CHECK_SE_CLASS1_PRE\
			if (ite.wthr.x != 0)\
			{cuda_call<<<ite.wthr,ite.thr>>>(__VA_ARGS__);}\
			cudaDeviceSynchronize(); \
			{\
				cudaError_t e = cudaGetLastError();\
				if (e != cudaSuccess)\
				{\
					std::string error = cudaGetErrorString(e);\
					std::cout << "Cuda Error in: " << __FILE__ << ":" << __LINE__ << " " << error << std::endl;\
				}\
				CHECK_SE_CLASS1_POST(#cuda_call,__VA_ARGS__)\
			}\
			}

	#define CUDA_LAUNCH_DIM3(cuda_call,wthr,thr, ...) \
			{\
			cudaDeviceSynchronize(); \
			{\
				cudaError_t e = cudaGetLastError();\
				if (e != cudaSuccess)\
				{\
					std::string error = cudaGetErrorString(e);\
					std::cout << "Cuda an error has occurred before this CUDA_LAUNCH, detected in: " << __FILE__ << ":" << __LINE__ << " " << error << std::endl;\
				}\
			}\
			CHECK_SE_CLASS1_PRE\
			cuda_call<<<wthr,thr>>>(__VA_ARGS__);\
			cudaDeviceSynchronize(); \
			{\
				cudaError_t e = cudaGetLastError();\
				if (e != cudaSuccess)\
				{\
					std::string error = cudaGetErrorString(e);\
					std::cout << "Cuda Error in: " << __FILE__ << ":" << __LINE__ << " " << error << std::endl;\
				}\
				CHECK_SE_CLASS1_POST(#cuda_call,__VA_ARGS__)\
			}\
			}

	#define CUDA_CHECK() \
			{\
			cudaDeviceSynchronize(); \
			{\
				cudaError_t e = cudaGetLastError();\
				if (e != cudaSuccess)\
				{\
					std::string error = cudaGetErrorString(e);\
					std::cout << "Cuda an error has occurred before, detected in: " << __FILE__ << ":" << __LINE__ << " " << error << std::endl;\
				}\
			}\
			CHECK_SE_CLASS1_PRE\
			cudaDeviceSynchronize(); \
			{\
				cudaError_t e = cudaGetLastError();\
				if (e != cudaSuccess)\
				{\
					std::string error = cudaGetErrorString(e);\
					std::cout << "Cuda Error in: " << __FILE__ << ":" << __LINE__ << " " << error << std::endl;\
				}\
				CHECK_SE_CLASS1_POST("no call","no args")\
			}\
			}

	#else

	#define CUDA_LAUNCH(cuda_call,ite, ...) \
			if (ite.wthr.x != 0)\
			{cuda_call<<<ite.wthr,ite.thr>>>(__VA_ARGS__);}

	#define CUDA_LAUNCH_DIM3(cuda_call,wthr,thr, ...) \
			cuda_call<<<wthr,thr>>>(__VA_ARGS__);

	#define CUDA_CHECK()

	#endif

#else

incardon's avatar
incardon committed
119
#include "util/cudify/cudify.hpp"
incardon's avatar
incardon committed
120
121
122
123

#endif

#endif /* CUDA_LAUNCH_HPP_ */