pub struct GpuMemHandle { /* private fields */ }Expand description
RAII handle to a device memory allocation within a GPU session.
§Ownership model (SDK polish wave, post-Phase 48.15)
GpuMemHandle is a RAII handle. It is Clone but not Copy.
When the last clone is dropped it automatically calls
gpu_session_mem_free for the underlying device allocation, unless
you explicitly freed it first via GpuSession::mem_free.
The intended pattern is:
let h = sess.mem_alloc(1024)?;
sess.mem_write(&h, 0, &data)?;
// either explicitly free:
sess.mem_free(h)?;
// ...or just let `h` go out of scope; Drop frees it.Migration note: prior to the SDK polish wave this type was
Copy, which meant a ? between mem_alloc and mem_free could
silently leak the device allocation until lease expiry. Removing
Copy is what makes the RAII guarantee work — if you previously
relied on copying handles around, clone them explicitly. Cloned
handles share the same underlying allocation and the same freed
state; only the last clone to drop will issue the mem_free.
Drop is best-effort: it silently swallows hostcall errors and never panics. If the lease has already expired, the daemon’s W3.5-validated lease-expiry teardown chain has already freed the device memory, so Drop suppresses the call entirely in that case.
The raw u64 device pointer is exposed via GpuMemHandle::raw for
callers who need to pack it into kernel argument buffers manually.
Prefer KernelArgs::push_buffer which handles the marshalling.
Implementations§
Trait Implementations§
Source§impl Clone for GpuMemHandle
impl Clone for GpuMemHandle
Source§fn clone(&self) -> GpuMemHandle
fn clone(&self) -> GpuMemHandle
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more