cuLite v0.3.1
A lite CUDA C++ Interface
Loading...
Searching...
No Matches
Allocators

Memory management and allocation strategies for GPU computing. More...

Functions

alloc_t culite::detect_allocation_type (const void *ptr)
 Detects the allocation type of a given memory pointer.
void * culite::device_alloc (std::size_t size)
 Allocates memory on the device.
void culite::device_free (void *ptr) noexcept
 Frees a block of memory on the device.
template<typename T>
T * culite::device_alloc_t (std::size_t n)
 Allocates typed memory on the device.
void * culite::pinned_alloc (std::size_t size)
 Allocates page-locked (pinned) host memory.
void culite::pinned_free (void *ptr) noexcept
 Frees a block of pinned host memory.
template<typename T>
T * culite::pinned_alloc_t (std::size_t n)
 Allocates typed pinned host memory.
void culite::auto_free (void *ptr)
 Automatically detects and frees memory based on allocation type.

Detailed Description

Memory management and allocation strategies for GPU computing.

Allocators handle the lifecycle of memory on the device. This module provides specialized routines for standard device allocation, unified memory (managed) access, and pinned host memory to optimize data transfer throughput between the CPU and GPU.

Classes:

Function Documentation

◆ detect_allocation_type()

alloc_t culite::detect_allocation_type ( const void * ptr)

Detects the allocation type of a given memory pointer.

This function queries the CUDA runtime to determine the allocation type of the provided pointer. It identifies whether the memory is allocated on the device, pinned on the host, managed (unified memory), or unregistered (unknown origin).

Parameters
[in]ptrPointer to the memory whose allocation type is to be detected.
Returns
The culite::alloc_t enumeration value indicating the allocation type:
Note
This function incurs significant performance overhead due to CUDA runtime queries and should be avoided in performance-critical loops. Cache the result when possible.
See also
alloc_t, auto_free()

◆ device_alloc()

void * culite::device_alloc ( std::size_t size)

Allocates memory on the device.

This function reserves a block of memory of the specified size on the underlying device.

Parameters
[in]sizeThe number of bytes to allocate.
Returns
A pointer to the allocated memory on success; nullptr if the allocation fails.
Note
Memory allocated by this function must be freed using the corresponding device free function.
See also
device_free()

◆ device_free()

void culite::device_free ( void * ptr)
noexcept

Frees a block of memory on the device.

This function releases the memory previously allocated by device_alloc. If ptr is nullptr, no action is performed.

Parameters
[in]ptrPointer to the device memory to be freed.
Note
This function is marked noexcept and is guaranteed not to throw exceptions during the deallocation process.
See also
device_alloc()
Examples
ex01c_dense_vector_create_from_aux_data.cpp, ex02d_dense_matrix_create_from_aux_data.cpp, and ex06d_sparse_matrix_create_from_aux_data.cpp.

◆ device_alloc_t()

template<typename T>
T * culite::device_alloc_t ( std::size_t n)

Allocates typed memory on the device.

This function reserves a block of memory for n elements of type T on the underlying device.

Template Parameters
TThe type of elements to allocate.
Parameters
[in]nThe number of elements to allocate.
Returns
A pointer to the allocated memory on success; nullptr if the allocation fails.
Note
Memory allocated by this function must be freed using the corresponding device free function.
See also
device_free()
Examples
ex01c_dense_vector_create_from_aux_data.cpp, ex02d_dense_matrix_create_from_aux_data.cpp, and ex06d_sparse_matrix_create_from_aux_data.cpp.

◆ pinned_alloc()

void * culite::pinned_alloc ( std::size_t size)

Allocates page-locked (pinned) host memory.

Reserves a block of host memory that is page-locked and accessible to the device.

Parameters
[in]sizeThe number of bytes to allocate.
Returns
A pointer to the pinned host memory on success; nullptr if the allocation fails.
Note
Must be freed using the corresponding pinned memory deallocation function.
See also
pinned_free()

◆ pinned_free()

void culite::pinned_free ( void * ptr)
noexcept

Frees a block of pinned host memory.

Releases the memory previously allocated by pinned_alloc. If ptr is nullptr, no action is performed.

Parameters
[in]ptrPointer to the pinned host memory to be freed.
Note
This function is marked noexcept and is guaranteed not to throw exceptions during the deallocation process.
See also
pinned_alloc()

◆ pinned_alloc_t()

template<typename T>
T * culite::pinned_alloc_t ( std::size_t n)

Allocates typed pinned host memory.

This function reserves a block of host memory for n elements of type T that is page-locked and accessible to the device.

Template Parameters
TThe type of elements to allocate.
Parameters
[in]nThe number of elements to allocate.
Returns
A pointer to the allocated pinned host memory on success; nullptr if the allocation fails.
Note
Must be freed using the corresponding pinned memory deallocation function.
See also
pinned_free()

◆ auto_free()

void culite::auto_free ( void * ptr)

Automatically detects and frees memory based on allocation type.

This function detects the allocation type of the given pointer (device memory, pinned host memory, or managed memory) and automatically calls the appropriate deallocation function. If ptr is nullptr or if the allocation type is unregistered (unknown origin), no action is performed.

Parameters
[in]ptrPointer to the memory to be freed.
Note
This function incurs performance overhead due to allocation type detection and should be avoided in performance-critical loops. Prefer using explicit device_free() or pinned_free() when the allocation type is known.
See also
device_free(), pinned_free(), detect_allocation_type()