Skip to main content

cudaMalloc

Function cudaMalloc 

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

Allocate memory on the device.

Allocates size bytes of linear memory on the device and returns in *devPtr a pointer to the allocated memory. The allocated memory is suitably aligned for any kind of variable. The memory is not cleared. cudaMalloc returns cudaError_t::CUDA_ERROR_OUT_OF_MEMORY in case of failure.

The device version of cudaFree cannot be used with a *devPtr allocated using the host API, and vice versa.

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

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: Pointer to allocated device memory.
  • size: Requested allocation size in bytes.

§Return value

See also: cudaMallocPitch, cudaFree, cudaMallocArray, cudaFreeArray, cudaMalloc3D, cudaMalloc3DArray, cudaMallocHost (C API), cudaFreeHost, cudaHostAlloc, cuMemAlloc.