GpuSession

Struct GpuSession 

Source
pub struct GpuSession { /* private fields */ }
Expand description

Persistent GPU session backed by a lease’s CUDA context.

GpuSession provides persistent device memory and loaded modules for multi-kernel workloads. The session is tied to the GpuLease and all resources are freed when the lease expires.

Implementations§

Source§

impl GpuSession

Source

pub fn new(lease: &GpuLease) -> Self

Create a session handle from a GPU lease.

§Canonical lifecycle example

This doctest exercises the full session lifecycle against the host mock so it runs on every cargo test build, with no GPU hardware required.

use grafos_std::gpu::{GpuBuilder, GpuSession, KernelArgs};

// 1. Acquire a GPU lease.
let lease = GpuBuilder::new().min_vram(1024).acquire()?;

// 2. Open a persistent session on the lease.
let mut sess = GpuSession::new(&lease);

// 3. Allocate device memory and write input data.
let buf = sess.mem_alloc(1024)?;
sess.mem_write(&buf, 0, &[1u8, 2, 3, 4])?;

// 4. Load a module (PTX/cubin bytes — placeholder under the mock).
let module = sess.module_load(&[0x7f, 0x45, 0x4c, 0x46])?;

// 5. Launch a kernel using the typed argument builder.
let args = KernelArgs::new()
    .push_u32(42)
    .push_buffer(&buf);
sess.launch_with_args(&module, "vector_add", [256, 1, 1], [64, 1, 1], args)?;

// 6. Synchronize and read results back.
sess.sync()?;
let _out = sess.mem_read(&buf, 0, 4)?;

// 7. `buf` and `module` drop here. Both are RAII-freed (the
//    daemon calls `cuMemFree` / `cuModuleUnload` on real
//    hardware). The lease itself drops at end of scope.
Source

pub fn lease_id(&self) -> u128

Lease ID for this session (session_id == lease_id).

Source

pub fn mem_alloc(&mut self, size: u64) -> Result<GpuMemHandle>

Allocate device memory.

Source

pub fn mem_write( &mut self, handle: &GpuMemHandle, offset: u64, data: &[u8], ) -> Result<()>

Write data to device memory.

Source

pub fn mem_read( &mut self, handle: &GpuMemHandle, offset: u64, size: u32, ) -> Result<Vec<u8>>

Read data from device memory.

Source

pub fn mem_free(&mut self, handle: GpuMemHandle) -> Result<()>

Free a device memory allocation explicitly.

Consumes the handle. After this returns successfully (or even on error), the handle’s Drop will be a no-op — explicit free and Drop are both safe; the latter never double-frees.

Source

pub fn module_load(&mut self, binary: &[u8]) -> Result<GpuModule>

Load a GPU module (PTX/cubin).

Source

pub fn module_unload(&mut self, module: GpuModule) -> Result<()>

Unload a GPU module explicitly (Phase 48.16 SDK polish).

Consumes the handle. After this returns successfully (or even on error), the handle’s Drop will be a no-op — explicit unload and Drop are both safe; the latter never double-unloads.

Source

pub fn launch( &mut self, module: &GpuModule, kernel: &str, grid: [u32; 3], block: [u32; 3], args: &[u8], arg_sizes: &[u32], ) -> Result<()>

Launch a kernel from a loaded module (async — does not wait).

Source

pub fn launch_with_args( &mut self, module: &GpuModule, kernel: &str, grid: [u32; 3], block: [u32; 3], args: KernelArgs, ) -> Result<()>

Launch a kernel using a KernelArgs builder.

Convenience over GpuSession::launch: builds the (args, arg_sizes) byte/size pair from the typed builder and forwards to the same underlying hostcall.

Source

pub fn sync(&mut self) -> Result<()>

Synchronize: wait for all outstanding launches to complete.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.