4 #ifndef NANOVDB_CUDA_UTILS_H_HAS_BEEN_INCLUDED
5 #define NANOVDB_CUDA_UTILS_H_HAS_BEEN_INCLUDED
8 #include <cuda_runtime_api.h>
11 static inline void gpuAssert(cudaError_t code,
const char* file,
int line,
bool abort =
true)
13 if (code != cudaSuccess) {
14 fprintf(stderr,
"CUDA error %u: %s (%s:%d)\n",
unsigned(code), cudaGetErrorString(code), file, line);
16 if (abort) exit(code);
19 static inline void ptrAssert(
const void*
ptr,
const char* msg,
const char* file,
int line,
bool abort =
true)
22 fprintf(stderr,
"NULL pointer error: %s %s %d\n", msg, file, line);
25 fprintf(stderr,
"Pointer misalignment error: %s %s %d\n", msg, file, line);
36 #define cudaCheck(ans) \
38 gpuAssert((ans), __FILE__, __LINE__); \
41 #define checkPtr(ptr, msg) \
43 ptrAssert((ptr), (msg), __FILE__, __LINE__); \
48 cudaCheck(cudaDeviceSynchronize()); \
51 #define cudaCheckError() \
53 cudaCheck(cudaGetLastError()); \
56 #if CUDART_VERSION < 11020 // 11.2 introduced cudaMallocAsync and cudaFreeAsync
73 #if defined(__CUDACC__)// the following functions only run on the GPU!
76 template<
typename Func,
typename... Args>
79 const int tid = blockIdx.x * blockDim.x + threadIdx.x;
80 if (tid >= numItems)
return;
92 do {*p++ = *
src;}
while(*src++);
102 __device__ inline char* cudaStrcat(
char *dst,
const char *src)
116 __device__ inline int cudaStrcmp(
const char *lhs,
const char *rhs)
118 while(*lhs && (*lhs == *rhs)){
122 return *(
const unsigned char*)lhs - *(
const unsigned char*)rhs;
129 __device__ inline bool cudaStrEq(
const char *lhs,
const char *rhs)
131 return cudaStrcmp(lhs, rhs) == 0;
136 #endif// NANOVDB_CUDA_UTILS_H_HAS_BEEN_INCLUDED
cudaError_t cudaFreeAsync(void *d_ptr, cudaStream_t)
Dummy implementation of cudaFreeAsync that calls cudaFree.
#define NANOVDB_DATA_ALIGNMENT
cudaError_t cudaMallocAsync(void **d_ptr, size_t size, cudaStream_t)
Dummy implementation of cudaMallocAsync that calls cudaMalloc.
struct CUstream_st * cudaStream_t
auto fprintf(std::FILE *f, const S &fmt, const T &...args) -> int
**If you just want to fire and args