cuda-api-wrappers
Thin C++-flavored wrappers for the CUDA Runtime API
cuda::memory::mapped Namespace Reference

Memory regions appearing in both on the host-side and device-side address spaces with the regions in both spaces mapped to each other (i.e. More...

Classes

struct  region_pair_t
 A pair of memory regions, one in system (=host) memory and one on a CUDA device's memory - mapped to each other. More...
 
struct  span_pair_t
 A pair of memory spans, one in device-global memory and one in host/system memory, mapped to it. More...
 

Functions

template<typename T >
T * device_side_pointer_for (T *host_memory_ptr)
 Obtain a pointer in the device-side memory space (= address range) given given a host-side pointer mapped to it. More...
 
region_t device_side_region_for (region_t region)
 Get the memory region mapped to a given host-side region. More...
 
const_region_t device_side_region_for (const_region_t region)
 Get the memory region mapped to a given host-side region. More...
 
region_pair_t allocate (cuda::context_t &context, size_t size_in_bytes, allocation_options options)
 Allocate a memory region on the host, which is also mapped to a memory region in a context of some CUDA device - so that changes to one will be reflected in the other. More...
 
region_pair_t allocate (cuda::device_t &device, size_t size_in_bytes, allocation_options options=allocation_options{})
 Allocate a memory region on the host, which is also mapped to a memory region in the global memory of a CUDA device - so that changes to one will be reflected in the other. More...
 
void free (region_pair_t pair)
 Free a pair of mapped memory regions. More...
 
void free_region_pair_of (void *ptr)
 Free a pair of mapped memory regions using just one of them. More...
 
bool is_part_of_a_region_pair (const void *ptr)
 Determine whether a given stretch of memory was allocated as part of a mapped pair of host and device memory regions. More...
 

Detailed Description

Memory regions appearing in both on the host-side and device-side address spaces with the regions in both spaces mapped to each other (i.e.

guaranteed to have the same contents on access up to synchronization details). Consult the CUDA C programming guide section on mapped memory for more details.

Function Documentation

◆ allocate() [1/2]

region_pair_t cuda::memory::mapped::allocate ( cuda::context_t context,
size_t  size_in_bytes,
allocation_options  options 
)
inline

Allocate a memory region on the host, which is also mapped to a memory region in a context of some CUDA device - so that changes to one will be reflected in the other.

Parameters
contextThe device context in which the device-side region in the pair will be allocated.
size_in_bytesamount of memory to allocate (in each of the regions)
optionssee memory::allocation_options

◆ allocate() [2/2]

region_pair_t cuda::memory::mapped::allocate ( cuda::device_t device,
size_t  size_in_bytes,
allocation_options  options = allocation_options{} 
)
inline

Allocate a memory region on the host, which is also mapped to a memory region in the global memory of a CUDA device - so that changes to one will be reflected in the other.

Parameters
deviceThe device on which the device-side region in the pair will be allocated
size_in_bytesamount of memory to allocate (in each of the regions)
optionssee memory::allocation_options

◆ device_side_pointer_for()

template<typename T >
T* cuda::memory::mapped::device_side_pointer_for ( T *  host_memory_ptr)
inline

Obtain a pointer in the device-side memory space (= address range) given given a host-side pointer mapped to it.

Parameters
[in]host_memory_ptra pointer to host-side memory which has been allocated as one side of a CUDA mapped memory region pair

◆ device_side_region_for() [1/2]

region_t cuda::memory::mapped::device_side_region_for ( region_t  region)
inline

Get the memory region mapped to a given host-side region.

Note
if the input is already a device-side region, this function is idempotent

◆ device_side_region_for() [2/2]

const_region_t cuda::memory::mapped::device_side_region_for ( const_region_t  region)
inline

Get the memory region mapped to a given host-side region.

Note
if the input is already a device-side region, this function is idempotent

◆ free()

void cuda::memory::mapped::free ( region_pair_t  pair)
inline

Free a pair of mapped memory regions.

Parameters
paira pair of mapped host- and device-side regions

◆ free_region_pair_of()

void cuda::memory::mapped::free_region_pair_of ( void *  ptr)
inline

Free a pair of mapped memory regions using just one of them.

Parameters
ptra pointer to one of the mapped regions (can be either the device-side or the host-side)

◆ is_part_of_a_region_pair()

bool cuda::memory::mapped::is_part_of_a_region_pair ( const void *  ptr)
inline

Determine whether a given stretch of memory was allocated as part of a mapped pair of host and device memory regions.

Todo:
What if it's a managed pointer?
Parameters
ptrthe beginning of a memory region - in either host or device memory - to check
Returns
true iff the region was allocated as one side of a mapped memory region pair