Function rustacuda::memory::cuda_malloc_unified[][src]

pub unsafe fn cuda_malloc_unified<T: DeviceCopy>(
    count: usize
) -> CudaResult<UnifiedPointer<T>>
Expand description

Unsafe wrapper around the cuMemAllocManaged function, which allocates some unified memory and returns a UnifiedPointer 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_unified must be freed using cuda_free.


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.


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


use rustacuda::memory::*;
unsafe {
    // Allocate space for a u64
    let mut unified_buffer = cuda_malloc_unified::<u64>(1).unwrap();
    // Write to it
    *unified_buffer.as_raw_mut() = 5u64;