Skip to main content

cudaMallocAsync

Function cudaMallocAsync 

Source
pub unsafe extern "C" fn cudaMallocAsync(
    devPtr: *mut *mut c_void,
    size: size_t,
    hStream: cudaStream_t,
) -> cudaError_t
Expand description

Allocates memory with stream ordered semantics.

Inserts an allocation operation into hStream. A pointer to the allocated memory is returned immediately in *dptr. The allocation must not be accessed until the allocation operation completes. The allocation comes from the memory pool associated with the stream’s device.

Note: The default memory pool of a device contains device memory from that device.

Note: Basic stream ordering allows future work submitted into the same stream to use the allocation. Stream query, stream synchronize, and CUDA events can be used to guarantee that the allocation operation completes before work submitted in a separate stream runs.

Note: During stream capture, this function results in the creation of an allocation node. In this case, the allocation is owned by the graph instead of the memory pool. The memory pool’s properties are used to set the node’s creation parameters.

Note that this function may also return error codes from previous, asynchronous launches.

Note: This function uses standard default stream semantics.

Note that this function may also return cudaError_t::CUDA_ERROR_NOT_INITIALIZED, cudaErrorInsufficientDriver or cudaError_t::CUDA_ERROR_NO_DEVICE if this call tries to initialize internal CUDA RT state.

Note that as specified by cudaStreamAddCallback no CUDA function may be called from callback. cudaError_t::CUDA_ERROR_NOT_PERMITTED may, but is not guaranteed to, be returned as a diagnostic in such case.

§Parameters

  • devPtr: Returned device pointer.
  • size: Number of bytes to allocate.
  • hStream: The stream establishing the stream ordering contract and the memory pool to allocate from.

§Return value

See also: cuMemAllocAsync, cudaMallocAsync (C++ API), cudaMallocFromPoolAsync, cudaFreeAsync, cudaDeviceSetMemPool, cudaDeviceGetDefaultMemPool, cudaDeviceGetMemPool, cudaMemPoolSetAccess, cudaMemPoolSetAttribute, cudaMemPoolGetAttribute.