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

Method drop

crates/cust/src/memory/device/device_buffer.rs:189–209  ·  view source on GitHub ↗

Destroy a `DeviceBuffer`, returning an error. Deallocating device memory can return errors from previous asynchronous work. This function destroys the given buffer and returns the error and the un-destroyed buffer on failure. # Example ``` # let _context = cust::quick_init().unwrap(); use cust::memory::*; let x = DeviceBuffer::from_slice(&[10, 20, 30]).unwrap(); match DeviceBuffer::drop(x) { Ok

(mut dev_buf: DeviceBuffer<T>)

Source from the content-addressed store, hash-verified

187 /// }
188 /// ```
189 pub fn drop(mut dev_buf: DeviceBuffer<T>) -> DropResult<DeviceBuffer<T>> {
190 if dev_buf.buf.is_null() {
191 return Ok(());
192 }
193
194 if dev_buf.len > 0 && size_of::<T>() > 0 {
195 let capacity = dev_buf.len;
196 let ptr = mem::replace(&mut dev_buf.buf, DevicePointer::null());
197 unsafe {
198 match cuda_free(ptr) {
199 Ok(()) => {
200 mem::forget(dev_buf);
201 Ok(())
202 }
203 Err(e) => Err((e, DeviceBuffer::from_raw_parts(ptr, capacity))),
204 }
205 }
206 } else {
207 Ok(())
208 }
209 }
210}
211
212#[cfg(feature = "bytemuck")]

Callers

nothing calls this directly

Calls 3

cuda_freeFunction · 0.85
is_nullMethod · 0.80
from_raw_partsFunction · 0.50

Tested by

no test coverage detected