KernelArgs

Struct KernelArgs 

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

Typed builder for GPU kernel launch arguments.

KernelArgs packs scalar values and device-buffer pointers into the (args, arg_sizes) byte/size pair that the [fabricbios_gpu_v1] bridge expects. Each push_* records the raw bytes and their per-arg size so the daemon can build a CUDA kernelParams array with one pointer per argument.

§Example

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

let lease = GpuBuilder::new().acquire()?;
let mut sess = GpuSession::new(&lease);
let buf = sess.mem_alloc(64)?;
let module = sess.module_load(&[0u8; 8])?;
let args = KernelArgs::new()
    .push_u32(7)
    .push_f32(2.5)
    .push_buffer(&buf);
sess.launch_with_args(&module, "k", [1, 1, 1], [1, 1, 1], args)?;

§Wire format

  • Scalars are written little-endian.
  • Buffer args are written as 8-byte little-endian device pointers (the raw cuMemAlloc return value carried by GpuMemHandle).
  • The daemon’s launch path packs these into a contiguous byte buffer and walks arg_sizes to compute per-arg pointer offsets for kernelParams. See crates/fabricbios-platform-linux/src/gpu.rs::launch.

Implementations§

Source§

impl KernelArgs

Source

pub fn new() -> Self

Create an empty argument list.

Source

pub fn push_u32(self, v: u32) -> Self

Push a u32 argument.

Source

pub fn push_u64(self, v: u64) -> Self

Push a u64 argument.

Source

pub fn push_i32(self, v: i32) -> Self

Push an i32 argument.

Source

pub fn push_i64(self, v: i64) -> Self

Push an i64 argument.

Source

pub fn push_f32(self, v: f32) -> Self

Push an f32 argument.

Source

pub fn push_f64(self, v: f64) -> Self

Push an f64 argument.

Source

pub fn push_buffer(self, handle: &GpuMemHandle) -> Self

Push a device buffer argument (the raw 8-byte device pointer).

This is the typed equivalent of manually appending handle.raw().to_le_bytes() with size 8. The daemon will pass the underlying device pointer to the kernel as the corresponding kernelParams entry.

Source

pub unsafe fn push_raw<T: Copy>(self, value: &T) -> Self

Push a value of arbitrary type by reinterpreting its bytes.

§Safety

T must satisfy all of the following:

  • Copy and trivially-destructible.
  • No interior padding bytes whose value matters to the kernel. For C-ABI structs, this generally means #[repr(C)] plus manual layout review.
  • No interior pointers, references, or non-'static lifetimes.
  • Endianness matches what the kernel expects (host order is little-endian on every platform fabricBIOS targets).

In short: the value must be a “POD” (plain-old-data) blob that can be byte-copied into a CUDA kernelParams slot. Prefer the typed push_* helpers for primitive scalars; reach for push_raw only when packing a #[repr(C)] struct argument.

Source

pub fn build(self) -> (Vec<u8>, Vec<u32>)

Consume the builder and return the raw (bytes, sizes) pair suitable for GpuSession::launch.

Trait Implementations§

Source§

impl Clone for KernelArgs

Source§

fn clone(&self) -> KernelArgs

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for KernelArgs

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for KernelArgs

Source§

fn default() -> KernelArgs

Returns the “default value” for a type. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.