8#ifndef SE_CLASS1_CUDA_HPP_
9#define SE_CLASS1_CUDA_HPP_
11#include "util/se_util.hpp"
22template<
typename T,
typename Sfinae =
void>
46template<typename T, int type_of_t=has_check_device_pointer<T>::value>
66 return arg.check_device_pointer(ptr);
76template<
typename ArgL>
77pos_pc error_args_impl(
void * ptr,
int prp, ArgL argl)
93template<
typename ArgL,
typename ... Args>
94pos_pc error_args_impl(
void * ptr,
int prp, ArgL argl, Args ... args)
100 pp.pos =
sizeof...(args);
104 return error_args_impl(ptr, prp, args ...);
107template<
typename ... Args>
pos_pc error_arg(
void * ptr,
int prp, Args ... args)
110 pp = error_args_impl(ptr, prp, args ... );
111 pp.pos =
sizeof...(args) - pp.pos - 1;
115#include <boost/algorithm/string.hpp>
117#if defined(SE_CLASS1) && !defined(__clang__)
118#define CUDA_LAUNCH_ERROR_OBJECT std::runtime_error("Runtime vector error");
119#define CHECK_SE_CLASS1_PRE int dev_mem[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
121#if !defined(CUDA_ON_CPU)
123 #define CHECK_SE_CLASS1_POST(kernel_call,...) \
124 cudaError_t e1 = cudaMemcpyFromSymbol(dev_mem,global_cuda_error_array,sizeof(dev_mem)); \
125 if (e1 != cudaSuccess)\
127 std::string error = cudaGetErrorString(e1);\
128 std::cout << "Cuda Error in cudaMemcpyFromSymbol: " << __FILE__ << ":" << __LINE__ << " " << error << std::endl;\
130 if (dev_mem[0] != 0)\
132 void * ptr = (void *)*(size_t *)&dev_mem[1]; \
133 int prp_err = dev_mem[3];\
134 pos_pc ea = error_arg(ptr,prp_err,__VA_ARGS__);\
135 std::string args_s( #__VA_ARGS__ );\
136 std::vector<std::string> results;\
137 boost::split(results, args_s, [](char c){return c == ',';});\
139 if (ea.pos >= results.size())\
140 {data_s = "Internal";}\
142 {data_s = results[ea.pos];}\
143 std::cout << __FILE__ << ":" << __LINE__ << " Overflow detected in Kernel: " << kernel_call << " from the structure: " << data_s << " property: " << prp_err << " index:(" ;\
145 for ( ; i < dev_mem[4]-1 ; i++)\
147 std::cout << dev_mem[5+i] << ",";\
149 std::cout << dev_mem[5+i];\
151 std::cout << " thread: " << "(" << dev_mem[6+i] << "," << dev_mem[7+i] << "," << dev_mem[8+i] << ")*(" << dev_mem[9+i] << "," << dev_mem[10+i] << "," << dev_mem[11+i] << ")+(" << dev_mem[12+i] << "," << dev_mem[13+i] << "," << dev_mem[14+i] << ")" << std::endl;\
152 std::cout << "Internal error report: " << ea.pc.match_str << std::endl;\
153 int dev_mem_null[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};\
154 cudaError_t e2 = cudaMemcpyToSymbol(global_cuda_error_array,dev_mem_null,sizeof(dev_mem_null),0,cudaMemcpyHostToDevice);\
155 if (e2 != cudaSuccess)\
157 std::string error = cudaGetErrorString(e2);\
158 std::cout << "Cuda Error in cudaMemcpyToSymbol: " << __FILE__ << ":" << __LINE__ << " " << error << std::endl;\
160 ACTION_ON_ERROR(CUDA_LAUNCH_ERROR_OBJECT);\
165 #define CHECK_SE_CLASS1_POST(kernel_call,...) \
166 memcpy(dev_mem,global_cuda_error_array,sizeof(dev_mem)); \
167 if (dev_mem[0] != 0)\
169 void * ptr = (void *)*(size_t *)&dev_mem[1]; \
170 int prp_err = dev_mem[3];\
171 pos_pc ea = error_arg(ptr,prp_err,__VA_ARGS__);\
172 std::string args_s( #__VA_ARGS__ );\
173 std::vector<std::string> results;\
174 boost::split(results, args_s, [](char c){return c == ',';});\
176 if (ea.pos >= results.size())\
177 {data_s = "Internal";}\
179 {data_s = results[ea.pos];}\
180 std::cout << __FILE__ << ":" << __LINE__ << " Overflow detected in Kernel: " << kernel_call << " from the structure: " << data_s << " property: " << prp_err << " index:(" ;\
182 for ( ; i < dev_mem[4]-1 ; i++)\
184 std::cout << dev_mem[5+i] << ",";\
186 std::cout << dev_mem[5+i];\
188 std::cout << " thread: " << "(" << dev_mem[6+i] << "," << dev_mem[7+i] << "," << dev_mem[8+i] << ")*(" << dev_mem[9+i] << "," << dev_mem[10+i] << "," << dev_mem[11+i] << ")+(" << dev_mem[12+i] << "," << dev_mem[13+i] << "," << dev_mem[14+i] << ")" << std::endl;\
189 std::cout << "Internal error report: " << ea.pc.match_str << std::endl;\
190 int dev_mem_null[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};\
191 memcpy(global_cuda_error_array,dev_mem_null,sizeof(dev_mem_null));\
192 ACTION_ON_ERROR(CUDA_LAUNCH_ERROR_OBJECT);\
198#define CHECK_SE_CLASS1_PRE
199#define CHECK_SE_CLASS1_POST(kernel_call,...)
void type
define void type
std::string match_str
match string
bool match
Indicate if the pointer match.