39 #ifndef ECUDA_GLOBAL_HPP
40 #define ECUDA_GLOBAL_HPP
55 #define ECUDA_SUPPRESS_HD_WARNINGS \
56 #pragma hd_warning_disable
58 #define ECUDA_SUPPRESS_HD_WARNINGS
65 #if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) // latter check works for GCC 4.6 because it has a bad __cplusplus flag
66 #define ECUDA_CPP11_AVAILABLE
69 #if defined(_MSC_VER) && _MSC_VER >= 1800 // Visual Studio 2013
70 #define ECUDA_CPP11_AVAILABLE
76 #define CUDA_CALL(x) do { if((x)!=cudaSuccess) { std::ostringstream oss; oss << __FILE__; oss << ":"; oss << __LINE__; oss << " "; oss << cudaGetErrorString(cudaGetLastError()); throw ::ecuda::cuda_error(x,oss.str()); }} while(0);
78 #define CUDA_CALL(x) x // cannot do CUDA calls when emulating with host only
88 #define S__LINE__ S_(__LINE__)
89 #define EXCEPTION_MSG(x) "" __FILE__ ":" S__LINE__ " " x
95 #define CUDA_CHECK_ERRORS() do { cudaError_t error = cudaGetLastError(); if( error != cudaSuccess ) throw ::ecuda::cuda_error(error,std::string(cudaGetErrorString(error))); } while(0);
97 #define CUDA_CHECK_ERRORS() do {} while(0); // cannot check CUDA errors when emulating with host only
107 #define CUDA_CALL_KERNEL_AND_WAIT(...) do {\
109 { cudaError_t error = cudaGetLastError(); if( error != cudaSuccess ) throw ::ecuda::cuda_error(error,std::string(cudaGetErrorString(error))); }\
110 cudaDeviceSynchronize();\
111 { cudaError_t error = cudaGetLastError(); if( error != cudaSuccess ) throw ::ecuda::cuda_error(error,std::string(cudaGetErrorString(error))); }\
114 #define CUDA_CALL_KERNEL_AND_WAIT(...) do {\
120 } while( 0 ); // cannot do CUDA calls when emulating with host only
124 #ifndef ECUDA_CPP11_AVAILABLE
129 #ifdef ECUDA_CPP11_AVAILABLE
130 #if defined(_MSC_VER) && _MSC_VER == 1800 // Visual Studio 2013 has only partial C++11 support and doesn't know these
132 #define __CONSTEXPR__
134 #define __NOEXCEPT__ noexcept
135 #define ECUDA_NOEXCEPT_KEYWORD_ENABLED
136 #define __CONSTEXPR__ constexpr
137 #define ECUDA_CONSTEXPR_KEYWORD_ENABLED
141 #define __CONSTEXPR__
145 #define __HOST__ __host__
146 #define __DEVICE__ __device__
147 #define __CONSTANT__ __constant__
162 #ifdef ECUDA_CPP11_AVAILABLE
163 #define ECUDA_STATIC_ASSERT(x,msg) static_assert(x,#msg)
171 template<
bool condition>
struct static_assertion {};
172 template<>
struct static_assertion<true>
175 CANNOT_USE_NONCONTIGUOUS_DEVICE_ITERATOR_AS_SOURCE_FOR_COPY,
176 CANNOT_USE_NONCONTIGUOUS_DEVICE_ITERATOR_AS_DESTINATION_FOR_COPY,
177 CANNOT_FILL_RANGE_REPRESENTED_BY_NONCONTIGUOUS_DEVICE_ITERATOR,
178 CANNOT_LEXICOGRAPHICALLY_COMPARE_RANGE_REPRESENTED_BY_NONCONTIGUOUS_DEVICE_MEMORY,
179 CANNOT_FIND_MAX_ELEMENT_IN_RANGE_REPRESENTED_BY_NONCONTIGUOUS_DEVICE_MEMORY,
180 CANNOT_REVERSE_RANGE_REPRESENTED_BY_NONCONTIGUOUS_DEVICE_MEMORY,
181 CANNOT_ACCUMULATE_RANGE_REPRESENTED_BY_NONCONTIGUOUS_DEVICE_MEMORY,
182 CANNOT_CALCULATE_DISTANCE_OF_NONCONTIGUOUS_DEVICE_ITERATOR_FROM_HOST_CODE
191 #define ECUDA_STATIC_ASSERT(x,msg) if(ecuda::impl::static_assertion<static_cast<bool>(x)>::msg) {}
193 #endif // ECUDA_CPP11_AVAILABLE