MimIR
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
mim::plug::tensor::phase Namespace Reference

Classes

class  Fuse
class  Lower
 Lowers the high-level tensor axioms into the low-level tensor axioms (map_reduce, …). More...
class  LowerGetSet
 Lowers the tensor axioms (get, set) to their underlying primitives (extract, insert). More...
class  LowerMapReduce
 Lowers the low-level tensor axioms (map_reduce, generate, pad, concat, broadcast) directly to their underlying primitives (loops, extract, insert, pack, …). More...
class  LowerToMem
 Bufferizes the low-level tensor axioms onto the shared buffer layer. More...
class  Reassoc
 Reassociates chains of tensor.product_2d with the classic matrix-chain-order dynamic program, so that a chain is evaluated with the least number of vector-lane slots. More...
struct  Slots
 The five parallel per-slot lists of a map_reduce_post input group: element type, rank, shape, access map, and the tensor itself. More...
struct  Split
 One node of a bracketing: ij splits after s. More...

Typedefs

using Splits = fe::Vector<Split>
 A bracketing of a matrix chain, innermost node first.

Functions

bool check_gather_shape_constraints (const Def *rank, const Def *dim, const Def *source_shape, const Def *index_shape)
 Checks statically decidable gather constraints. Returns false for unresolved relations.
bool check_scatter_shape_constraints (const Def *rank, const Def *dim, const Def *source_shape, const Def *index_shape, const Def *updates_shape)
 Checks statically decidable scatter constraints. Returns false for unresolved relations.
static std::optional< u64injective_coord (const Def *var, const Def *e)
 If e reads coordinate var#i injectively, returns i: a plain extract, possibly strided (affine.semiop.mul by a non-zero literal) and/or shifted (affine.op.add/sub with a loop-invariant affine.lit on the other side).
static bool reads_injectively (const Def *mapmap)
 Checks that map provably reads through every loop index of its domain: its body is the identity, or each result coordinate is an injective read of one loop index (see injective_coord) and together they cover all indices.
static const Defcompose_map (World &w, const Def *inner, const Def *outer)
 inner ∘ outer: feeds the outer op's read coordinates for one input into the inner op's access map.
static std::optional< PureReadread_through (World &w, const Def *value, const Def *slot_map)
 If value is a pure re-indexed read — a copy-combiner map_reduce (reshape/transpose/slice/ flip/repeat lower to these) or a tensor.broadcast — returns its source and access map, to be composed behind the consuming slot's map.
static bool is_unpack_read (World &w, const Def *mapmap, const Def *r_in, const Def *s_in, const Def *r_out, const Def *s_out)
 Is map the row-major reshape read tensor.reshape_map (s_in, s_out) — the map that reads a PACKED producer (its output strip-mined to s_in) at the unpacked coordinates s_out?

Class Documentation

◆ mim::plug::tensor::phase::Split

struct mim::plug::tensor::phase::Split

One node of a bracketing: ij splits after s.

Spelling the fields out keeps size_t out of the type - it is not mim::u64 everywhere.

Definition at line 11 of file reassoc.h.

Class Members
u64 i
u64 j
u64 s

Typedef Documentation

◆ Splits

A bracketing of a matrix chain, innermost node first.

Definition at line 16 of file reassoc.h.

Function Documentation

◆ check_gather_shape_constraints()

bool mim::plug::tensor::phase::check_gather_shape_constraints ( const Def * rank,
const Def * dim,
const Def * source_shape,
const Def * index_shape )

Checks statically decidable gather constraints. Returns false for unresolved relations.

Definition at line 22 of file constraints.cpp.

References check_gather_shape_constraints(), mim::Lit::isa(), and mim::Def::proj().

Referenced by check_gather_shape_constraints().

◆ check_scatter_shape_constraints()

bool mim::plug::tensor::phase::check_scatter_shape_constraints ( const Def * rank,
const Def * dim,
const Def * source_shape,
const Def * index_shape,
const Def * updates_shape )

Checks statically decidable scatter constraints. Returns false for unresolved relations.

Definition at line 42 of file constraints.cpp.

References check_scatter_shape_constraints(), mim::Lit::isa(), and mim::Def::proj().

Referenced by check_scatter_shape_constraints().

◆ compose_map()

const Def * mim::plug::tensor::phase::compose_map ( World & w,
const Def * inner,
const Def * outer )
static

inner ∘ outer: feeds the outer op's read coordinates for one input into the inner op's access map.

Definition at line 89 of file fuse.cpp.

References compose_map(), mim::Def::type(), and mim::Def::var().

Referenced by compose_map().

◆ injective_coord()

std::optional< u64 > mim::plug::tensor::phase::injective_coord ( const Def * var,
const Def * e )
static

If e reads coordinate var#i injectively, returns i: a plain extract, possibly strided (affine.semiop.mul by a non-zero literal) and/or shifted (affine.op.add/sub with a loop-invariant affine.lit on the other side).

Everything else — mod/div, sums of two loop indices (convolution windows), symbolic strides (which may be 0 at runtime) — yields nothing.

Definition at line 26 of file fuse.cpp.

References mim::plug::affine::add, injective_coord(), mim::Axm::isa(), mim::Lit::isa(), mim::plug::affine::mul, mim::plug::affine::sub, and mim::Extract::tuple().

Referenced by injective_coord(), and reads_injectively().

◆ is_unpack_read()

bool mim::plug::tensor::phase::is_unpack_read ( World & w,
const Def * map,
const Def * r_in,
const Def * s_in,
const Def * r_out,
const Def * s_out )
static

Is map the row-major reshape read tensor.reshape_map (s_in, s_out) — the map that reads a PACKED producer (its output strip-mined to s_in) at the unpacked coordinates s_out?

Decided by normalization: both map and the canonical unpack map are applied to the same probe variable; the reduced bodies are hash-consed, so pointer equality decides alpha-equivalence.

Definition at line 407 of file fuse.cpp.

References is_unpack_read().

Referenced by is_unpack_read().

◆ read_through()

std::optional< PureRead > mim::plug::tensor::phase::read_through ( World & w,
const Def * value,
const Def * slot_map )
static

If value is a pure re-indexed read — a copy-combiner map_reduce (reshape/transpose/slice/ flip/repeat lower to these) or a tensor.broadcast — returns its source and access map, to be composed behind the consuming slot's map.

Such reads perform no computation, so reading through them needs neither an injectivity gate nor a consumer count.

Definition at line 111 of file fuse.cpp.

References mim::plug::tensor::is_pure_read(), mim::Axm::isa(), mim::Lit::isa(), mim::plug::affine::mul, read_through(), and mim::Def::type().

Referenced by read_through().

◆ reads_injectively()

bool mim::plug::tensor::phase::reads_injectively ( const Def * map)
static

Checks that map provably reads through every loop index of its domain: its body is the identity, or each result coordinate is an injective read of one loop index (see injective_coord) and together they cover all indices.

Such a map is injective over the iteration domain, so each element of the input behind it is read (and, after fusion, computed) at most once — strided/shifted reads skip elements entirely, so fusing behind them even drops computations the consumer never looks at. Anything not provably injective — a dropped loop index, a wrapped coordinate (mod, ...), a non-literal rank — is conservatively rejected.

Definition at line 57 of file fuse.cpp.

References injective_coord(), mim::Lit::isa(), reads_injectively(), and mim::Def::var().

Referenced by reads_injectively().