AttnV41

Struct AttnV41 

Source
pub struct AttnV41 {
    pub cfg: AttnV41Cfg,
    /* private fields */
}
Expand description

The attention runtime: kernels, RoPE tables, and workspaces for up to max_tokens positions per call.

Fields§

§cfg: AttnV41Cfg

Implementations§

Source§

impl AttnV41

Source

pub fn decode_capturable(&self, w: &AttnV41LayerWeights) -> bool

Can this layer’s single-token step be captured into a CUDA graph? The kv and index sources compute the position’s compressor group and the index top-k on the host in the middle of the forward (position parity, a score download); every other layer is kernels and copies from end to end once its per-token inputs are read from the device.

Source

pub fn decode_fixed_topk(&self, w: &AttnV41LayerWeights) -> usize

The topk a captured step launches sparse_attn with: the widest selection the layer can ever see, so the launch argument is constant and the selection is padded with -1 (which the kernel skips: a padded entry adds a zero to the denominator sum and nothing to the output, so the result is the eager step’s bit for bit).

Source

pub fn invalidate_decode_uploads(&mut self)

Forget what the captured decode step last uploaded; the next Self::decode_prep re-uploads. Call after any eager forward (it writes pos / head_pos / idx_dev for itself) and at a new step.

Source

pub fn decode_prep( &mut self, w: &AttnV41LayerWeights, shared: &SharedV41, gpu: &dyn GpuBackend, start_pos: usize, stream: u64, ) -> Result<Option<DevicePtr>>

The HOST half of a capturable layer’s single-token step at start_pos: the position into pos / head_pos and the padded selection (window slots, then the shared index selection, then -1) into idx_dev, each only when it differs from what is already there. Returns the compressed rows the captured sparse_attn reads (None on ratio-0 layers) — a pointer the graph bakes, for the caller to verify on every replay.

Source

pub fn decode_prep_role( &mut self, ratio_positive: bool, shared: &SharedV41, gpu: &dyn GpuBackend, start_pos: usize, stream: u64, ) -> Result<Option<DevicePtr>>

Self::decode_prep by selection class: ratio_positive layers read the window plus the shared index selection from idx_dev, the others the window alone from idx_dev_win; both classes can be prepared for one multi-layer capture.

Source

pub fn decode_body( &self, gpu: &dyn GpuBackend, w: &AttnV41LayerWeights, st: &AttnV41LayerState, x: DevicePtr, rows_b: Option<DevicePtr>, stream: u64, ) -> Result<DevicePtr>

The DEVICE half of a capturable layer’s single-token step: the projections, the window ring write at pos % window (slot read on the device), sparse attention over the padded selection and the output projection into the returned buffer. No host work, no per-token scalar arguments: capturable into a CUDA graph and replayed for any position once decode_prep has updated pos / head_pos / idx_dev.

Source§

impl AttnV41

Source

pub fn forward( &self, gpu: &dyn GpuBackend, w: &AttnV41LayerWeights, st: &mut AttnV41LayerState, shared: &mut SharedV41, x: DevicePtr, m: usize, start_pos: usize, stream: u64, ) -> Result<AttnV41Run>

One layer’s attention for m tokens at start_pos: x is the normed input [m, dim] bf16; the output is [m, dim] bf16 in run.out.

Source§

impl AttnV41

Source

pub fn new(gpu: &dyn GpuBackend, cfg: AttnV41Cfg) -> Result<Self>

Source

pub fn out_ptr(&self) -> DevicePtr

The layer output buffer, bf16 [max_tokens, dim]: a pointer a captured decode step bakes.

Source

pub fn free(self, gpu: &dyn GpuBackend) -> Result<()>

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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
§

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

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

§

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

§

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