cuda-api-wrappers
Thin C++-flavored wrappers for the CUDA Runtime API
pointer.hpp File Reference

A wrapper class for host and/or device pointers, allowing easy access to CUDA's pointer attributes. More...

#include "constants.hpp"
#include "error.hpp"
#include "types.hpp"
#include <cassert>
Include dependency graph for pointer.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  cuda::memory::pointer_t< T >
 A convenience wrapper around a raw pointer "known" to the CUDA runtime and which thus has various kinds of associated information which this wrapper allows access to. More...
 

Namespaces

 cuda
 Definitions and functionality wrapping CUDA APIs.
 
 cuda::memory
 Representation, allocation and manipulation of CUDA-related memory, of different.
 

Enumerations

enum  cuda::memory::type_t : ::std::underlying_type< CUmemorytype >::type {
  host_ = CU_MEMORYTYPE_HOST,
  device_ = CU_MEMORYTYPE_DEVICE,
  array = CU_MEMORYTYPE_ARRAY,
  unified_ = CU_MEMORYTYPE_UNIFIED,
  managed_ = CU_MEMORYTYPE_UNIFIED,
  non_cuda = ~(::std::underlying_type<CUmemorytype>::type{0})
}
 The CUDA execution ecosystem involves different memory spaces in their relation to a GPU device or their treatment by the CUDA driver; this type distinguishes among them.
 

Functions

memory::type_t cuda::memory::type_of (const void *ptr)
 Determine the type of memory at a given address vis-a-vis the CUDA ecosystem: Was it allocated by the CUDA driver? Does it reside solely on a GPU device'? Solely on the host? Movable between locations? etc.
 
context_t cuda::memory::context_of (void const *ptr)
 Obtain (a non-owning wrapper for) the CUDA context with which a memory address is associated (e.g. More...
 
template<typename T >
pointer_t< T > cuda::memory::pointer::wrap (T *ptr) noexcept
 Wraps an existing pointer in a pointer_t wrapper. More...
 

Detailed Description

A wrapper class for host and/or device pointers, allowing easy access to CUDA's pointer attributes.

Note
at the moment, this class is not used by other sections of the API wrappers; specifically, freestanding functions and methods returning pointers return raw T*'s rather than pointer_t<T>'s. This may change in the future.
Todo:
Consider allowing for storing attributes within the class, lazily (e.g. with an ::std::optional).

Function Documentation

◆ wrap()

template<typename T >
pointer_t<T> cuda::memory::pointer::wrap ( T *  ptr)
inlinenoexcept

Wraps an existing pointer in a pointer_t wrapper.

Parameters
ptra pointer - into either device or host memory - to be wrapped.