|
#define | CS_MALLOC_HD(_ptr, _ni, _type, _mode) |
|
#define | CS_REALLOC_HD(_ptr, _ni, _type, _mode) |
|
#define | CS_FREE_HD(_ptr) cs_free_hd(_ptr, #_ptr, __FILE__, __LINE__), _ptr = NULL |
|
#define | CS_FREE(_ptr) cs_free(_ptr, #_ptr, __FILE__, __LINE__), _ptr = NULL |
|
#define | cs_alloc_mode CS_ALLOC_HOST |
|
#define | cs_associate_device_ptr(_host_ptr, _ni, _size) ; |
| Associate device memory with a given host memory pointer. More...
|
|
#define | cs_disassociate_device_ptr(_host_ptr) ; |
| Detach device memory from a given host memory pointer. More...
|
|
#define | cs_set_alloc_mode(_host_ptr, mode) ; |
| Set allocation mode for an already allocated pointer. More...
|
|
|
static int | cs_get_device_id (void) |
| Return currently associated device id. More...
|
|
static void * | cs_malloc_hd (cs_alloc_mode_t mode, size_t ni, size_t size, const char *var_name, const char *file_name, int line_num) |
| Allocate memory on host and device for ni elements of size bytes. More...
|
|
static void * | cs_realloc_hd (void *ptr, cs_alloc_mode_t mode, size_t ni, size_t size, const char *var_name, const char *file_name, int line_num) |
| Reallocate memory on host and device for ni elements of size bytes. More...
|
|
static void | cs_free_hd (void *ptr, const char *var_name, const char *file_name, int line_num) |
| Free memory on host and device for a given host pointer. More...
|
|
static void | cs_free (void *ptr, const char *var_name, const char *file_name, int line_num) |
| Free memory on host and device for a given pointer. More...
|
|
static void * | cs_get_device_ptr (void *ptr) |
| Return matching device pointer for a given pointer. More...
|
|
static const void * | cs_get_device_ptr_const (const void *ptr) |
| Return matching device pointer for a given constant pointer. More...
|
|
static const void * | cs_get_device_ptr_const_pf (const void *ptr) |
| Return matching device pointer for a given constant pointer, prefetching if applicable. More...
|
|
static cs_alloc_mode_t | cs_check_device_ptr (const void *ptr) |
| Check if a pointer is associated with a device. More...
|
|
static void | cs_sync_h2d (const void *ptr) |
| Synchronize data from host to device. More...
|
|
static void | cs_sync_h2d_future (const void *ptr) |
| Initiate synchronization of data from host to device for future access. More...
|
|
static void | cs_sync_d2h (void *ptr) |
| Synchronize data from device to host. More...
|
|
static void | cs_prefetch_h2d (void *ptr, size_t size) |
| Prefetch data from host to device. More...
|
|
static void | cs_prefetch_d2h (void *ptr, size_t size) |
| Prefetch data from device to host. More...
|
|
static int | cs_get_n_allocations_hd (void) |
| Return number of host-device allocations. More...
|
|
static size_t | cs_get_allocation_hd_size (void *host_ptr) |
| Check if a given host pointer is allocated with associated with cs_alloc_hd or cs_realloc_hd. More...
|
|
static void* cs_get_device_ptr |
( |
void * |
ptr | ) |
|
|
inlinestatic |
Return matching device pointer for a given pointer.
If separate pointers are used on the host and device, the host pointer should be used with this function.
If memory is not allocated on device yet at the call site, it will be allocated automatically by this function.
- Parameters
-
- Returns
- pointer to device memory.
static const void* cs_get_device_ptr_const |
( |
const void * |
ptr | ) |
|
|
inlinestatic |
Return matching device pointer for a given constant pointer.
If separate pointers are used on the host and device, the host pointer should be used with this function.
If memory is not allocated on device yet at the call site, it will be allocated automatically by this function.
- Parameters
-
- Returns
- pointer to device memory.
static const void* cs_get_device_ptr_const_pf |
( |
const void * |
ptr | ) |
|
|
inlinestatic |
Return matching device pointer for a given constant pointer, prefetching if applicable.
If separate pointers are used on the host and device, the host pointer should be used with this function. In this case, it is assumed that the host and device values have already been synchronized, unless memory is not allocated on device yet at the call site, in which case it will be allocated automatically by this function.
- Parameters
-
- Returns
- pointer to device memory.
static void* cs_malloc_hd |
( |
cs_alloc_mode_t |
mode, |
|
|
size_t |
ni, |
|
|
size_t |
size, |
|
|
const char * |
var_name, |
|
|
const char * |
file_name, |
|
|
int |
line_num |
|
) |
| |
|
inlinestatic |
Allocate memory on host and device for ni elements of size bytes.
This function calls the appropriate allocation function based on the requested mode, and allows introspection of the allocated memory.
If separate pointers are used on the host and device, the host pointer is returned.
- Parameters
-
[in] | mode | allocation mode |
[in] | ni | number of elements |
[in] | size | element size |
[in] | var_name | allocated variable name string |
[in] | file_name | name of calling source file |
[in] | line_num | line number in calling source file |
- Returns
- pointer to allocated memory.
static void* cs_realloc_hd |
( |
void * |
ptr, |
|
|
cs_alloc_mode_t |
mode, |
|
|
size_t |
ni, |
|
|
size_t |
size, |
|
|
const char * |
var_name, |
|
|
const char * |
file_name, |
|
|
int |
line_num |
|
) |
| |
|
inlinestatic |
Reallocate memory on host and device for ni elements of size bytes.
This function calls the appropriate reallocation function based on the requested mode, and allows introspection of the allocated memory.
If separate pointers are used on the host and device, the host pointer should be used with this function.
If the allocation parameters are unchanged, no actual reallocation occurs on the host.
If the device uses a separate allocation, it is freed, and a new allocation is delayed (as per initial allocation) so as to invalidate copies which will not be up to date anymore after the associated values modification.
- Parameters
-
[in] | ptr | pointer to previously allocated memory |
[in] | mode | allocation mode |
[in] | ni | number of elements |
[in] | size | element size |
[in] | var_name | allocated variable name string |
[in] | file_name | name of calling source file |
[in] | line_num | line number in calling source file |
- Returns
- pointer to allocated memory.
static void cs_sync_d2h |
( |
void * |
ptr | ) |
|
|
inlinestatic |
Synchronize data from device to host.
If separate allocations are used on the host and device (mode == CS_ALLOC_HOST_DEVICE), the host pointer should be passed to this function.
Depending on the allocaton type, this can imply a copy, data prefetch, or a no-op.
This function assumes the provided pointer was allocated using CS_MALLOC_HD or CS_REALLOC_HD, as it uses the associated mapping to determine associated metadata.
- Parameters
-
[in,out] | ptr | pointer to values to copy or prefetch |
static void cs_sync_h2d |
( |
const void * |
ptr | ) |
|
|
inlinestatic |
Synchronize data from host to device.
If separate pointers are used on the host and device, the host pointer should be used with this function.
Depending on the allocation type, this can imply a copy, data prefetch, or a no-op.
This function assumes the provided pointer was allocated using CS_MALLOC_HD or CS_REALLOC_HD, as it uses the associated mapping to determine associated metadata.
- Parameters
-
[in,out] | ptr | host pointer to values to copy or prefetch |
static void cs_sync_h2d_future |
( |
const void * |
ptr | ) |
|
|
inlinestatic |
Initiate synchronization of data from host to device for future access.
If separate pointers are used on the host and device, the host pointer should be used with this function. In this case, synchronization is started (asynchronously if the allocation mode supports it).
In other cases, synchronization will be delayed until actual use. the host pointer should be used with this function.
Depending on the allocation type, this can imply a copy, data prefetch, or a no-op.
This function assumes the provided pointer was allocated using CS_MALLOC_HD or CS_REALLOC_HD, as it uses the associated mapping to determine associated metadata.
- Parameters
-
[in,out] | ptr | host pointer to values to copy or prefetch |