MCPcopy Create free account
hub / github.com/Rust-GPU/rust-cuda / cuda_free

Function cuda_free

crates/cust/src/memory/malloc.rs:174–181  ·  view source on GitHub ↗

Free memory allocated with [`cuda_malloc`](fn.cuda_malloc.html). # Errors If freeing memory fails, returns the CUDA error value. If the given pointer is null, returns InvalidValue. # Safety The given pointer must have been allocated with `cuda_malloc`, or null. The caller is responsible for ensuring that no other pointers to the deallocated buffer exist. # Examples ``` # let _context = cust:

(ptr: DevicePointer<T>)

Source from the content-addressed store, hash-verified

172/// }
173/// ```
174pub unsafe fn cuda_free<T: DeviceCopy>(ptr: DevicePointer<T>) -> CudaResult<()> {
175 if ptr.is_null() {
176 return Err(CudaError::InvalidMemoryAllocation);
177 }
178
179 cuda::cuMemFree_v2(ptr.as_raw()).to_result()?;
180 Ok(())
181}
182
183/// Free memory allocated with [`cuda_malloc_unified`](fn.cuda_malloc_unified.html).
184///

Callers 3

test_cuda_mallocFunction · 0.85
dropMethod · 0.85
dropMethod · 0.85

Calls 3

is_nullMethod · 0.80
to_resultMethod · 0.45
as_rawMethod · 0.45

Tested by 1

test_cuda_mallocFunction · 0.68