Skip to main content

Template

Struct Template 

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

A template under construction: tensors, stages, buffers and local hand-off edges, in id order.

★ THE ONE BUILDER EVERY TEMPLATE COMES FROM — the recognized workloads below, the B-P4 Qwen compositions, and the hand-built probes of spatial_algebra_expansion_lock. Building a stage any other way is how two programs end up disagreeing about what a stage IS.

Implementations§

Source§

impl Template

Source

pub fn new(target: &SpatialTarget) -> Result<Template, SpatialReject>

Source

pub fn trip(&mut self, trip: Trip) -> TripId

Declare a loop count the program reads from its data (Trip).

Source

pub fn tensor( &mut self, name: &str, role: TensorRole, rows: usize, cols: usize, dtype: Precision, init: TensorInit, ) -> TensorId

Source

pub fn buffer( &mut self, name: &str, page_tiles: usize, dtype: Precision, ) -> BufferId

Source

pub fn buffer_deep( &mut self, name: &str, depth_pages: usize, page_tiles: usize, dtype: Precision, ) -> BufferId

A buffer that lives only between two compute stages. It is neither filled by a reader nor drained by a writer, so it takes the intermediate circular-buffer class rather than an operand or output slot. A hand-off of an explicit DEPTH. Double buffering is the right default — it lets a producer fill page n+1 while the consumer drains page n — but it costs twice the local memory, and a stage whose page is consumed by the very next stage in its own item never overlaps anything. A section that fans into many sub-blocks pays that doubling once per operand per sub-block, which is how a 426 KB site budget disappears.

Source

pub fn scratch_deep( &mut self, name: &str, depth_pages: usize, page_tiles: usize, dtype: Precision, ) -> BufferId

Template::scratch with an explicit depth.

Source

pub fn scratch( &mut self, name: &str, page_tiles: usize, dtype: Precision, ) -> BufferId

Source

pub fn stage( &mut self, name: &str, kind: StageKind, ins: Vec<BufferId>, outs: Vec<BufferId>, ) -> StageId

Source

pub fn load( &mut self, name: &str, tensor: TensorId, steps: Vec<(LoopVar, usize)>, block_w: usize, out: BufferId, ) -> StageId

A load of block_w tiles of one tile-row of tensor, addressed by the item’s coordinates.

Source

pub fn load_block( &mut self, name: &str, tensor: TensorId, steps: Vec<(LoopVar, usize)>, block_h: usize, block_w: usize, stride_h: usize, out: BufferId, ) -> StageId

A load of a block_h x block_w TILE BLOCK whose rows are stride_h tiles apart — the shape a strided view needs when the rows it wants are not adjacent in the tensor. A causal conv’s ring is taps x chan flattened, so one channel block’s taps sit chan/tile tiles apart.

Source

pub fn store_block( &mut self, name: &str, tensor: TensorId, base: usize, steps: Vec<(LoopVar, usize)>, block_h: usize, block_w: usize, stride_h: usize, input: BufferId, ) -> StageId

The store twin of Template::load_block, with an explicit tile base — the constant part of an address whose variable part is the item’s coordinate.

Source

pub fn store_block_over( &mut self, name: &str, tensor: TensorId, base: usize, steps: Vec<(LoopVar, usize)>, block_h: usize, block_w: usize, stride_h: usize, sub_blocks: (usize, usize), input: BufferId, ) -> StageId

Template::store_block over the item’s sub_blocks — the extent the pattern’s LV_SUB_H / LV_SUB_W steps walk. ★ A TEMPLATE STATES WHAT ITS PLAN SAYS: placement reshapes only the store of the section’s result to a site’s block, so every other store’s sub-blocks are the template’s, and the coverage check reads them.

Source

pub fn load_block_at( &mut self, name: &str, tensor: TensorId, base: usize, steps: Vec<(LoopVar, usize)>, block_h: usize, block_w: usize, stride_h: usize, out: BufferId, ) -> StageId

Template::load_block with an explicit tile base.

Source

pub fn store( &mut self, name: &str, tensor: TensorId, steps: Vec<(LoopVar, usize)>, block_w: usize, input: BufferId, ) -> StageId

Source

pub fn stage_reads(&self, s: StageId, b: BufferId) -> bool

Whether a stage names a buffer among its operands (a chain wires by this, not by position).

Source

pub fn stage_output(&self, s: StageId) -> BufferId

The buffer a chain stage writes.

Source

pub fn dtype(&self, b: BufferId) -> Precision

The element precision buffer b holds.

Source

pub fn page_tiles(&self, b: BufferId) -> usize

Tiles per page of a buffer — the page WIDTH every flat access map is taken over.

Source

pub fn edge_many(&mut self, from: StageId, buffer: BufferId, to: Vec<StageId>)

One hand-off read by SEVERAL stages. A buffer has exactly one producing EDGE, not one per consumer — a fan-out is a single edge with a list of readers, which is also what the choreography needs in order to pop the page once rather than once per reader.

Source

pub fn edge(&mut self, from: StageId, buffer: BufferId, to: StageId)

Source

pub fn finish( self, name: String, items: Vec<WorkItem>, acc: AccPolicy, claim: NumericsClaim, target: &SpatialTarget, ) -> Result<SpatialProgram, SpatialReject>

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
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
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> Same for T

Source§

type Output = T

Should always be Self
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<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,