OpenVDB 13.1.0
Loading...
Searching...
No Matches
Util.h File Reference

Cuda specific utility functions. More...

#include <cuda.h>
#include <cuda_runtime_api.h>
#include <vector>
#include <nanovdb/util/Util.h>

Go to the source code of this file.

Classes

class  unique_ptr< T >
 Simple (naive) implementation of a unique device pointer using stream ordered memory allocation and deallocation. More...

Namespaces

namespace  nanovdb
 Defines a simple memory pool used to call cub functions that use dynamic temporary storage.
namespace  nanovdb::util
namespace  nanovdb::util::cuda

Macros

#define cudaCheck(ans)
#define checkPtr(ptr, msg)
#define cudaSync()
#define cudaCheckError()

Functions

static void gpuAssert (cudaError_t code, const char *file, int line, bool abort=true)
static void ptrAssert (const void *ptr, const char *msg, const char *file, int line, bool abort=true)
bool memoryPoolsSupported (int device)
 Returns true if device supports stream-ordered memory pools, i.e. cudaMallocAsync/cudaFreeAsync. Queried once per process for all devices and cached; out-of-range device ids return false.
cudaError_t mallocAsync (void **d_ptr, size_t size, cudaStream_t)
 Wrapper forced to synchronous cudaMalloc; see the mode comment above. The trailing stream argument is accepted for signature compatibility and ignored.
cudaError_t freeAsync (void *d_ptr, cudaStream_t)
 Wrapper forced to synchronous cudaFree; see the mode comment above. The trailing stream argument is accepted for signature compatibility and ignored.
int ptrToDevice (void *ptr)
 Returns the device ID associated with the specified pointer.
int currentDevice ()
 Returns the ID of the current device.
int deviceCount ()
 Returns the number of devices with compute capability greater or equal to 1.0 that are available for execution.
void printDevInfo (int device, const char *preMsg=nullptr, std::FILE *file=stderr)
 Print information about a specific device.
size_t blocksPerGrid (size_t numItems, size_t threadsPerBlock)
 Computes the number of blocks per grid given the problem size and number of threads per block.
cudaError_t memAdvise (const void *devPtr, size_t count, cudaMemoryAdvise advice, int device)
 Compatbility wrapper for cudaMemAdvise/cudaMemAdvise.
cudaError_t memPrefetchAsync (const void *devPtr, size_t count, int dstDevice, cudaStream_t stream)
 Compatbility wrapper for cudaMemPrefetchAsync/cudaMemPrefetchAsync.

Detailed Description

Cuda specific utility functions.

Author
Ken Museth
Date
December 20, 2023

Macro Definition Documentation

◆ checkPtr

#define checkPtr ( ptr,
msg )
Value:
{ \
ptrAssert((ptr), (msg), __FILE__, __LINE__); \
}

◆ cudaCheck

#define cudaCheck ( ans)
Value:
{ \
gpuAssert((ans), __FILE__, __LINE__); \
}

◆ cudaCheckError

#define cudaCheckError ( )
Value:
{ \
cudaCheck(cudaGetLastError()); \
}

◆ cudaSync

#define cudaSync ( )
Value:
{ \
cudaCheck(cudaDeviceSynchronize()); \
}

Function Documentation

◆ gpuAssert()

void gpuAssert ( cudaError_t code,
const char * file,
int line,
bool abort = true )
inlinestatic

◆ ptrAssert()

void ptrAssert ( const void * ptr,
const char * msg,
const char * file,
int line,
bool abort = true )
inlinestatic