[][src]Function rustacuda::memory::cuda_malloc

pub unsafe fn cuda_malloc<T>(count: usize) -> CudaResult<DevicePointer<T>>

Unsafe wrapper around the cuMemAlloc function, which allocates some device memory and returns a DevicePointer pointing to it. The memory is not cleared.

Note that count is in units of T; thus a count of 3 will allocate 3 * size_of::<T>() bytes of memory.

Memory buffers allocated using cuda_malloc must be freed using cuda_free.

Errors

If allocating memory fails, returns the CUDA error value. If the number of bytes to allocate is zero (either because count is zero or because T is a zero-sized type), or if the size of the allocation would overflow a usize, returns InvalidValue.

Safety

Since the allocated memory is not initialized, the caller must ensure that it is initialized before copying it to the host in any way. Additionally, the caller must ensure that the memory allocated is freed using cuda_free, or the memory will be leaked.

Examples

use rustacuda::memory::*;
unsafe {
    // Allocate space for 5 u64s
    let device_buffer = cuda_malloc::<u64>(5).unwrap();
    cuda_free(device_buffer).unwrap();
}