cubecl_hip_sys

Function hipHostMalloc

Source
pub unsafe extern "C" fn hipHostMalloc(
    ptr: *mut *mut c_void,
    size: usize,
    flags: c_uint,
) -> hipError_t
Expand description

@brief Allocates device accessible page locked (pinned) host memory

This API allocates pinned host memory which is mapped into the address space of all GPUs in the system, the memory can be accessed directly by the GPU device, and can be read or written with much higher bandwidth than pageable memory obtained with functions such as malloc().

Using the pinned host memory, applications can implement faster data transfers for HostToDevice and DeviceToHost. The runtime tracks the hipHostMalloc allocations and can avoid some of the setup required for regular unpinned memory.

When the memory accesses are infrequent, zero-copy memory can be a good choice, for coherent allocation. GPU can directly access the host memory over the CPU/GPU interconnect, without need to copy the data.

Currently the allocation granularity is 4KB for the API.

Developers need to choose proper allocation flag with consideration of synchronization.

@param[out] ptr Pointer to the allocated host pinned memory @param[in] size Requested memory size in bytes If size is 0, no memory is allocated, *ptr returns nullptr, and hipSuccess is returned. @param[in] flags Type of host memory allocation

If no input for flags, it will be the default pinned memory allocation on the host.

@return #hipSuccess, #hipErrorOutOfMemory

@see hipSetDeviceFlags, hipHostFree