Skip to main content

EncKernels

Struct EncKernels 

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

The compiled encoder kernel set. Built once per device; the f16 GEMM twin exists only when the adapter reports SHADER_F16.

Implementations§

Source§

impl EncKernels

Source

pub fn new(ctx: &GpuCtx) -> Self

Compile all encoder pipelines on ctx.

Source

pub fn rope_for_tests( &self, ctx: &GpuCtx, x: &[f32], seq_starts: &[u32], n_heads: usize, hd: usize, theta: f32, ) -> Result<Vec<f32>>

One-shot rope for the kernel parity tests: rotate a [T, nh·hd] buffer in place.

Source

pub fn glu_for_tests( &self, ctx: &GpuCtx, mid: &[f32], i_width: usize, act: Act, ) -> Result<Vec<f32>>

One-shot GLU split for the kernel parity tests.

Source

pub fn gemm_for_tests( &self, ctx: &GpuCtx, x: &[f32], w: &[f32], bias: Option<&[f32]>, m: usize, n: usize, k: usize, act: Option<Act>, w_f16: bool, ) -> Result<Vec<f32>>

One-shot GEMM (upload → dispatch → read back) for the kernel parity tests. w arrives as f32 and is converted to f16 on upload when w_f16 — the caller’s CPU reference must consume the same round-tripped values.

Source

pub fn gemm_resident( &self, ctx: &GpuCtx, x: &[f32], wb: &Buffer, bb: &Buffer, m: usize, n: usize, k: usize, act: Option<Act>, ) -> Result<Vec<f32>>

GEMM against weights that are ALREADY on the device.

gemm_for_tests uploads w every call; at gliner2’s span_rep shapes that is ~9 MB of weights per GEMM and it dominates — measured, the one-shot runs 0.0164 s where the kernel itself sustains 0.0021 s (tests/gemm_probe.rs). Hoisting the weights out is the first half of closing that gap; the second half (keeping the ACTIVATIONS resident too) needs the whole chain on device and is tracked separately.

wb/bb are caller-owned and expected to live across calls — see Linear::gpu_weights.

Source

pub fn gemm_resident_into( &self, ctx: &GpuCtx, xb: &Buffer, wb: &Buffer, bb: &Buffer, yb: &Buffer, m: usize, n: usize, k: usize, act: Option<Act>, ) -> Result<()>

GEMM entirely in device buffers: x and y stay resident, nothing is read back.

gemm_resident still uploads the activations and reads the result; chaining several GEMMs through it therefore pays a full round-trip PER STEP. For gliner2’s span_rep the middle tensor (hbuf) is ~22.8 MB per call, which is exactly what capped the device port at 1.53x of the ~30x the kernel sustains. This variant is what lets the whole chain stay on-device.

yb must be at least m * n f32s.

Source

pub fn gemm_bench( &self, ctx: &GpuCtx, m: usize, n: usize, k: usize, w_f16: bool, v2: bool, reps: usize, ) -> Result<f64>

Steady-state GFLOP/s of the GEMM at one shape — the STOP INSTRUMENT for kernel tuning.

Weights and activations upload once; reps dispatches then run in ONE submit, so the number is the kernel’s throughput and not the readback, the allocation, or the submit. Min of the timed reps (a mean on a shared box measures the contention, not the code).

Source

pub fn gemm3_bench( &self, ctx: &GpuCtx, m: usize, n: usize, k: usize, bm: usize, bn: usize, bk: usize, reps: usize, ) -> Result<f64>

[gemm_bench]’s v3 twin — the STOP instrument for deciding whether the vec4/transposed kernel earns a place in the TEXT-encoder plan (its wins were proven at vision shapes, m≈912; the text shapes are m∈{64,192} where occupancy, not instruction count, may rule). The pipeline is created ad hoc (a lab probe, not a plan resident); weight contents are irrelevant to throughput so zeros stand in for the [k, n] transposed upload.

Source

pub fn gemm3_sk_bench( &self, ctx: &GpuCtx, m: usize, n: usize, k: usize, bm: usize, bn: usize, bk: usize, chunks: u32, reps: usize, ) -> Result<f64>

[gemm3_bench]’s split-K twin: the partial+reduce PAIR, timed as the plan would run it (both dispatches in one pass, in-pass ordering supplying the dependency). The lab probe for whether the k-dimension can rescue thin-grid shapes OUTSIDE the wired mid-band — e.g. /score’s n=384 bucket, whose best plain tile runs only 72 workgroups.

Source

pub fn layernorm_for_tests( &self, ctx: &GpuCtx, x: &[f32], res: Option<&[f32]>, w: &[f32], b: Option<&[f32]>, t: usize, h: usize, eps: f32, ) -> Result<Vec<f32>>

One-shot LayerNorm(+residual)(+bias) for the kernel parity tests.

Source

pub fn attention_for_tests( &self, ctx: &GpuCtx, q: &[f32], k: &[f32], v: &[f32], seq_starts: &[u32], n_heads: usize, n_kv_heads: usize, hd: usize, mask: MaskKind, window: u32, ) -> Result<Vec<f32>>

One-shot ragged attention for the kernel parity tests.

Source

pub fn mean_pool_l2_for_tests( &self, ctx: &GpuCtx, hidden: &[f32], h: usize, seq_starts: &[u32], ) -> Result<Vec<Vec<f32>>>

One-shot mean-pool + L2-normalize for the kernel parity tests.

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,