14 #ifndef __cudaInlineFunctions_h
15 #define __cudaInlineFunctions_h
17 #include <cuda_runtime.h>
26 #define cudaCheckMsg( msg ) __cudaCheckMsg( msg, __FILE__, __LINE__ )
28 inline void __cudaCheckMsg(
const char *msg,
const char *file,
const int line )
30 cudaError_t err = ::cudaGetLastError();
31 if ( err != cudaSuccess )
33 const char* errcmsg = ::cudaGetErrorString( err );
34 fprintf( stderr,
"CUDA error: %s in file <%s>, line %i : %s.\n",
35 msg, file, line, errcmsg );
38 std::string errmsg = std::string( msg ) +
":: " + std::string( errcmsg );
43 err = ::cudaThreadSynchronize();
44 if ( err != cudaSuccess )
46 const char* errcmsg = ::cudaGetErrorString( err );
47 fprintf( stderr,
"cudaThreadSynchronize error: %s in file <%s>, line %i : %s.\n",
48 msg, file, line, errcmsg );
51 std::string errmsg = std::string( msg ) +
":: " + std::string( errcmsg );
62 size_t size = nof_elems *
sizeof( T );
71 inline T*
cudaHostAlloc(
size_t nof_elems,
unsigned int flags = cudaHostAllocDefault )
74 size_t size = nof_elems *
sizeof( T );
82 inline cudaError_t
cudaMemcpy(
void* dst,
const void* src,
83 size_t nof_elems,
size_t sizeof_elem, cudaMemcpyKind direction )
85 cudaError err =
::cudaMemcpy( dst, src, nof_elems * sizeof_elem, direction );
93 size_t nof_elems, cudaMemcpyKind direction )
95 size_t size = nof_elems *
sizeof( T );
102 inline void cudaMemset( T* dst,
int value,
size_t nof_elems )
104 size_t size = nof_elems *
sizeof( T );
110 template <
typename T,
typename Q>
112 cudaMemcpyKind direction )
120 template <
typename T>
122 const cudaChannelFormatDesc desc )
130 template <
typename T>
143 DBG_FUNC( cudaFreeArray, (
struct cudaArray *array), (array) );
144 DBG_FUNC( cudaFree, (
void *devPtr), (devPtr) );
145 DBG_FUNC( cudaMalloc3DArray, (
struct cudaArray** arrayPtr,
146 const struct cudaChannelFormatDesc* desc,
struct cudaExtent extent),
147 (arrayPtr, desc, extent) );
148 DBG_FUNC( cudaMemcpy3D, (
const struct cudaMemcpy3DParms *p), (p) );
149 DBG_FUNC( cudaSetDevice, (
int device), (device) );
150 DBG_FUNC( cudaGetDeviceProperties, (
struct cudaDeviceProp *prop,
int device),
155 #endif // end #ifndef __cudaInlineFunctions_h