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

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

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.

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 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.

Examples

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;
    cuda_free_unified(unified_buffer).unwrap();
}