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

The btensor Plugin More...

Namespaces

namespace  phase

Classes

struct  MapRedPost
 The curried meta arguments of a tensor.map_reduce_post or btensor.map_reduce_post callee (same layout). More...
struct  Ring_field
 The fields of btensor.Ring, by index. More...
struct  Sched_field
 The fields of btensor.Sched, by index. More...

Enumerations

<tt>btensor.Ring</tt>
enum class  Ring : flags_t
<tt>btensor.id</tt>
enum class  id : flags_t
<tt>btensor.map_reduce_post</tt>
enum class  map_reduce_post : flags_t
<tt>btensor.Sched</tt>
enum class  Sched : flags_t
<tt>btensor.SchedT</tt>
enum class  SchedT : flags_t
<tt>btensor.mk_sched</tt>
enum class  mk_sched : flags_t
<tt>btensor.proj_map</tt>
enum class  proj_map : flags_t
<tt>btensor.broadcast</tt>
enum class  broadcast : flags_t
<tt>btensor.concat</tt>
enum class  concat : flags_t
<tt>btensor.pad</tt>
enum class  pad : flags_t
<tt>btensor.gather</tt>
enum class  gather : flags_t
<tt>btensor.scatter</tt>
enum class  scatter : flags_t
<tt>btensor.NestT</tt>
enum class  NestT : flags_t
<tt>btensor.mr_nest</tt>
enum class  mr_nest : flags_t
<tt>btensor.map_reduce_post_impl</tt>
enum class  map_reduce_post_impl : flags_t
<tt>btensor.lower_map_reduce</tt>
enum class  lower_map_reduce : flags_t

Functions

const Def * op_affine_map (const Def *f, const Def *m, const Def *n, const Def *s_in, const Def *s_out, const Def *idxs, const Def *mem)
 affine.map @(m, n) @(s_in, s_out) f idxs as mem with the address space as of mem ↦ [mem', coords].
void app_cps (Lam *caller, const Def *f, DefVec args, const Def *ret)
 Calls the combiner/epilogue f from caller with args and the continuation ret.
std::pair< Lam *, const Def * > ds_splice (const Def *arg, const Def *codom, std::string name)
 A fresh fun: Fn arg->type() → codom named name, spliced into direct style as cps.cps2ds_dep fun arg.
DefVec to_idxs (World &w, Defs extents, Defs iters)
 Converts the raw i64 loop counters iters into indices Idx extents[d].
const Def * folded_idx (const Def *shape, Defs iters)
 The raw i64 loop counters iters as a buffer index into shape, with its literal size-1 axes folded away.
const Def * clamp (const Def *x, const Def *hi)
 Clamps the i64 x into [0, hi].
std::pair< DefVec, const Def * > pad_coords (Defs iters, const Def *lo, const Def *s_in, bool replicate)
 The read coordinates o#d − lo#d of a pad into Idx s_in#d - clamped to the nearest edge if replicate, or else zeroed out of range - together with the all-axes in-range flag (nullptr if replicate).
std::optional< fe::Vector< u64 > > concat_extents (const Def *Sis, u64 nis, u64 r, u64 ax)
 The literal extents of the nis input shapes Sis along the concat axis ax; std::nullopt if one is not literal.
const Def * concat_select (const Def *o_ax, const fe::Vector< u64 > &exts, auto read)
 The concat cell at the i64 axis coordinate o_ax: read(i, loc) of the input i owning it - the highest one whose prefix offset is ≤ o_ax - at the axis coordinate loc clamped into that input.
const Def * build_pointwise (const Def *result_ty, const Def *mem, const Def *dst, const Def *ins, const Def *s_out, u64 rn, const std::string &name, auto compute)
 A [mem, dst, ins] → [mem, Buf] fun spliced via cps.cps2ds_dep that loops over s_out carrying [mem, dst] and writes compute's element at the loop's (identity) output coordinates.
void register_normalizers (Normalizers &normalizers)

Variables

static constexpr plugin_t Plugin_Id = 0xd518f5104c00000

<tt>btensor.map_reduce</tt>

enum class  map_reduce : flags_t
const Def * normalize_map_reduce (const Def *, const Def *c, const Def *arg)
 btensor.map_reduce is btensor.map_reduce_post without the epilogue and with the neutral schedule: delegate with post = btensor.id (so Tp = To), no epilogue inputs (nps = 0), no vector dim (vdim = Rn, the out-of-range sentinel), and no unrolling.

Detailed Description

Enumeration Type Documentation

◆ broadcast

Definition at line 77 of file autogen.h.

◆ concat

enum class mim::plug::btensor::concat : flags_t
strong

Definition at line 84 of file autogen.h.

◆ gather

enum class mim::plug::btensor::gather : flags_t
strong

Definition at line 98 of file autogen.h.

◆ id

enum class mim::plug::btensor::id : flags_t
strong

Definition at line 24 of file autogen.h.

◆ lower_map_reduce

Definition at line 133 of file autogen.h.

◆ map_reduce

Definition at line 31 of file autogen.h.

◆ map_reduce_post

Definition at line 39 of file autogen.h.

◆ map_reduce_post_impl

Definition at line 126 of file autogen.h.

◆ mk_sched

Definition at line 63 of file autogen.h.

◆ mr_nest

enum class mim::plug::btensor::mr_nest : flags_t
strong

Definition at line 119 of file autogen.h.

◆ NestT

enum class mim::plug::btensor::NestT : flags_t
strong

Definition at line 112 of file autogen.h.

◆ pad

enum class mim::plug::btensor::pad : flags_t
strong

Definition at line 91 of file autogen.h.

◆ proj_map

Definition at line 70 of file autogen.h.

◆ Ring

enum class mim::plug::btensor::Ring : flags_t
strong

Definition at line 14 of file autogen.h.

◆ scatter

enum class mim::plug::btensor::scatter : flags_t
strong

Definition at line 105 of file autogen.h.

◆ Sched

enum class mim::plug::btensor::Sched : flags_t
strong

Definition at line 46 of file autogen.h.

◆ SchedT

enum class mim::plug::btensor::SchedT : flags_t
strong

Definition at line 56 of file autogen.h.

Function Documentation

◆ app_cps()

void mim::plug::btensor::app_cps ( Lam * caller,
const Def * f,
DefVec args,
const Def * ret )
inline

Calls the combiner/epilogue f from caller with args and the continuation ret.

Scalarize may have flattened f's domain Cn [[args], Cn ret] to Cn [args…, Cn ret]; the call matches either.

Definition at line 73 of file btensor.h.

References mim::Lam::app(), app_cps(), mim::Pi::dom(), mim::Def::num_projs(), and mim::Def::world().

Referenced by app_cps().

◆ build_pointwise()

const Def * mim::plug::btensor::build_pointwise ( const Def * result_ty,
const Def * mem,
const Def * dst,
const Def * ins,
const Def * s_out,
u64 rn,
const std::string & name,
auto compute )
inline

A [mem, dst, ins] → [mem, Buf] fun spliced via cps.cps2ds_dep that loops over s_out carrying [mem, dst] and writes compute's element at the loop's (identity) output coordinates.

compute(iters, ins, mem) receives the raw i64 loop counters, the fun's inputs var, and the current mem; it returns {mem', elem}.

Definition at line 172 of file btensor.h.

References build_pointwise(), mim::plug::affine::counting_nest(), ds_splice(), folded_idx(), mim::plug::buffer::op_write(), mim::Def::proj(), mim::Def::projs(), and mim::Def::var().

Referenced by build_pointwise().

◆ clamp()

const Def * mim::plug::btensor::clamp ( const Def * x,
const Def * hi )
inline

Clamps the i64 x into [0, hi].

Definition at line 104 of file btensor.h.

References clamp(), mim::plug::core::smax, mim::plug::core::smin, and mim::Def::world().

Referenced by clamp(), concat_select(), and pad_coords().

◆ concat_extents()

std::optional< fe::Vector< u64 > > mim::plug::btensor::concat_extents ( const Def * Sis,
u64 nis,
u64 r,
u64 ax )
inline

The literal extents of the nis input shapes Sis along the concat axis ax; std::nullopt if one is not literal.

Definition at line 140 of file btensor.h.

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

Referenced by concat_extents().

◆ concat_select()

const Def * mim::plug::btensor::concat_select ( const Def * o_ax,
const fe::Vector< u64 > & exts,
auto read )
inline

The concat cell at the i64 axis coordinate o_ax: read(i, loc) of the input i owning it - the highest one whose prefix offset is ≤ o_ax - at the axis coordinate loc clamped into that input.

Definition at line 152 of file btensor.h.

References clamp(), concat_select(), mim::plug::core::none, mim::plug::core::sub, mim::plug::core::uge, and mim::Def::world().

Referenced by concat_select().

◆ ds_splice()

std::pair< Lam *, const Def * > mim::plug::btensor::ds_splice ( const Def * arg,
const Def * codom,
std::string name )
inline

A fresh fun: Fn arg->type() → codom named name, spliced into direct style as cps.cps2ds_dep fun arg.

Returns
{fun, call}.

Definition at line 85 of file btensor.h.

References ds_splice(), mim::plug::cps::op_cps2ds_dep(), mim::Def::type(), and mim::Def::world().

Referenced by build_pointwise(), and ds_splice().

◆ folded_idx()

const Def * mim::plug::btensor::folded_idx ( const Def * shape,
Defs iters )
inline

The raw i64 loop counters iters as a buffer index into shape, with its literal size-1 axes folded away.

Definition at line 98 of file btensor.h.

References folded_idx(), mim::Shape::Shape(), and to_idxs().

Referenced by build_pointwise(), and folded_idx().

◆ normalize_map_reduce()

const Def * mim::plug::btensor::normalize_map_reduce ( const Def * ,
const Def * c,
const Def * arg )

btensor.map_reduce is btensor.map_reduce_post without the epilogue and with the neutral schedule: delegate with post = btensor.id (so Tp = To), no epilogue inputs (nps = 0), no vector dim (vdim = Rn, the out-of-range sentinel), and no unrolling.

The delegation lives in a normalizer (rather than a wrapping lam) so that call sites keep axm-style implicit inference: the stuck axm application lets the checker solve the {Tis, Ris, Sis} holes from the operands, whereas applying a lam would eagerly β-reduce buffer.Buf over still-unsolved holes.

Definition at line 14 of file normalizers.cpp.

References normalize_map_reduce(), and mim::Def::projs().

Referenced by normalize_map_reduce().

◆ op_affine_map()

const Def * mim::plug::btensor::op_affine_map ( const Def * f,
const Def * m,
const Def * n,
const Def * s_in,
const Def * s_out,
const Def * idxs,
const Def * mem )
inline

affine.map @(m, n) @(s_in, s_out) f idxs as mem with the address space as of mem ↦ [mem', coords].

Definition at line 55 of file btensor.h.

References mim::App::arg(), and op_affine_map().

Referenced by op_affine_map().

◆ pad_coords()

std::pair< DefVec, const Def * > mim::plug::btensor::pad_coords ( Defs iters,
const Def * lo,
const Def * s_in,
bool replicate )
inline

The read coordinates o#d − lo#d of a pad into Idx s_in#d - clamped to the nearest edge if replicate, or else zeroed out of range - together with the all-axes in-range flag (nullptr if replicate).

Definition at line 111 of file btensor.h.

References mim::plug::core::and_, clamp(), mim::plug::core::none, pad_coords(), mim::Def::proj(), mim::plug::core::sub, mim::plug::core::u, mim::plug::core::ul, and mim::Def::world().

Referenced by pad_coords().

◆ register_normalizers()

void mim::plug::btensor::register_normalizers ( Normalizers & normalizers)

◆ to_idxs()

DefVec mim::plug::btensor::to_idxs ( World & w,
Defs extents,
Defs iters )
inline

Converts the raw i64 loop counters iters into indices Idx extents[d].

Definition at line 93 of file btensor.h.

References to_idxs().

Referenced by folded_idx(), and to_idxs().

Variable Documentation

◆ Plugin_Id

plugin_t mim::plug::btensor::Plugin_Id = 0xd518f5104c00000
staticconstexpr

Definition at line 10 of file autogen.h.