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

The tensor Plugin More...

Namespaces

namespace  phase

Classes

struct  PureRead
 A pure re-indexed read: the source tensor, the access map into it (over the read's output coordinates), and the source's element type/rank/shape. More...

Typedefs

using Ring = plug::btensor::Ring
using Sched = plug::btensor::Sched
using SchedT = plug::btensor::SchedT
using mk_sched = plug::btensor::mk_sched
using proj_map = plug::btensor::proj_map

Enumerations

<tt>tensor.generate</tt>
enum class  generate : flags_t
<tt>tensor.splat</tt>
enum class  splat : flags_t
<tt>tensor.buf</tt>
enum class  buf : flags_t
<tt>tensor.id</tt>
enum class  id : flags_t
<tt>tensor.map_reduce_post</tt>
enum class  map_reduce_post : flags_t
<tt>tensor.map_reduce</tt>
enum class  map_reduce : flags_t
<tt>tensor.transpose_2d</tt>
enum class  transpose_2d : flags_t
<tt>tensor.binary</tt>
enum class  binary : flags_t
<tt>tensor.map</tt>
enum class  map : flags_t
<tt>tensor.select</tt>
enum class  select : flags_t
<tt>tensor.unary</tt>
enum class  unary : flags_t
<tt>tensor.bmm</tt>
enum class  bmm : flags_t
<tt>tensor.conv</tt>
enum class  conv : flags_t
<tt>tensor.conv_grouped</tt>
enum class  conv_grouped : flags_t
<tt>tensor.dot_product</tt>
enum class  dot_product : flags_t
<tt>tensor.pool</tt>
enum class  pool : flags_t
<tt>tensor.product_2d</tt>
enum class  product_2d : flags_t
<tt>tensor.gather</tt>
enum class  gather : flags_t
<tt>tensor.scatter</tt>
enum class  scatter : flags_t
<tt>tensor.interchange</tt>
enum class  interchange : flags_t
<tt>tensor.materialize</tt>
enum class  materialize : flags_t
<tt>tensor.mr_tileable</tt>
enum class  mr_tileable : flags_t
<tt>tensor.strip_mine_par</tt>
enum class  strip_mine_par : flags_t
<tt>tensor.strip_mine_red</tt>
enum class  strip_mine_red : flags_t
<tt>tensor.broadcast_in_dim_impl</tt>
enum class  broadcast_in_dim_impl : flags_t
<tt>tensor.flip_impl</tt>
enum class  flip_impl : flags_t
<tt>tensor.gather_pointwise_elem_impl</tt>
enum class  gather_pointwise_elem_impl : flags_t
<tt>tensor.map_impl</tt>
enum class  map_impl : flags_t
<tt>tensor.pool_impl</tt>
enum class  pool_impl : flags_t
<tt>tensor.repeat_impl</tt>
enum class  repeat_impl : flags_t
<tt>tensor.reshape_map</tt>
enum class  reshape_map : flags_t
<tt>tensor.reshape_impl</tt>
enum class  reshape_impl : flags_t
<tt>tensor.conv_impl</tt>
enum class  conv_impl : flags_t
<tt>tensor.conv_grouped_impl</tt>
enum class  conv_grouped_impl : flags_t
<tt>tensor.dot_product_impl</tt>
enum class  dot_product_impl : flags_t
<tt>tensor.bmm_impl</tt>
enum class  bmm_impl : flags_t
<tt>tensor.product_2d_impl</tt>
enum class  product_2d_impl : flags_t
<tt>tensor.scatter_step_impl</tt>
enum class  scatter_step_impl : flags_t
<tt>tensor.slice_impl</tt>
enum class  slice_impl : flags_t
<tt>tensor.transpose_impl</tt>
enum class  transpose_impl : flags_t
<tt>tensor.binary_impl</tt>
enum class  binary_impl : flags_t
<tt>tensor.select_impl</tt>
enum class  select_impl : flags_t
<tt>tensor.unary_impl</tt>
enum class  unary_impl : flags_t
<tt>tensor.reassoc</tt>
enum class  reassoc : flags_t
<tt>tensor.lower_tensor</tt>
enum class  lower_tensor : flags_t
<tt>tensor.lower_map_reduce</tt>
enum class  lower_map_reduce : flags_t
<tt>tensor.fuse_tensor</tt>
enum class  fuse_tensor : flags_t
<tt>tensor.lower_to_mem</tt>
enum class  lower_to_mem : flags_t

Functions

bool is_identity_map (const Def *mapmap)
 Is map the identity access map λ x. x?
bool is_copy_comb (const Def *comb)
 Recognizes the (rebuilt) tensor_copy combiner (acc, ys) ↦ ys#0: the result is exactly the single input element, so a map_reduce built on it is a pure re-indexed read of that input.
bool is_identity_post (const Def *post)
 Is post the (rebuilt) CPS identity tensor.id, i.e.
std::optional< PureRead > is_pure_read (const Def *value)
 If value is a pure re-indexed read — a copy-combiner map_reduce without reduction loops that writes its full loop domain through the identity output map (reshape/transpose/slice/flip/repeat lower to these) — returns its single access map and source.
std::optional< fe::Vector< u64 > > lit_projs (const Def *def, u64 n)
 The literal values of def's n projections, or nothing if one of them is not a literal.
std::optional< fe::Vector< u64 > > lit_perm (const Def *perm)
 perm as literals, if it is literal.
std::optional< fe::Vector< u64 > > transpose_perm (const App *app)
 The permutation of a transpose app, if it is literal.
const Def * isa_transpose_2d (const Def *def)
 The input of a 2-D transpose transpose (1, 0), or nullptr.
DefMap< u64 > count_consumers (const World &world, std::predicate< const Def * > auto pred)
 Counts the consumers of every def of world matched by pred.
static void reg_phases (Flags2Phases &phases)
void register_normalizers (Normalizers &normalizers)

Variables

constexpr std::array Vec_widths = {1_u64, 4_u64, 8_u64, 16_u64}
 The vector widths -X tensor:vec-width accepts.
static constexpr plugin_t Plugin_Id = 0x5463d44130000000

<tt>tensor.shape</tt>

enum class  shape : flags_t
const Def * normalize_shape (const Def *, const Def *c, const Def *arg)

<tt>tensor.broadcast</tt>

enum class  broadcast : flags_t
const Def * normalize_broadcast (const Def *type, const Def *c, const Def *arg)

<tt>tensor.broadcast_in_dim</tt>

enum class  broadcast_in_dim : flags_t
const Def * normalize_broadcast_in_dim (const Def *, const Def *, const Def *)

<tt>tensor.concat</tt>

enum class  concat : flags_t
const Def * normalize_concat (const Def *, const Def *, const Def *)

<tt>tensor.flip</tt>

enum class  flip : flags_t
const Def * normalize_flip (const Def *, const Def *, const Def *)

<tt>tensor.pad</tt>

enum class  pad : flags_t
const Def * normalize_pad (const Def *, const Def *c, const Def *arg)

<tt>tensor.repeat</tt>

enum class  repeat : flags_t
const Def * normalize_repeat (const Def *type, const Def *c, const Def *arg)

<tt>tensor.reshape</tt>

enum class  reshape : flags_t
const Def * normalize_reshape (const Def *type, const Def *c, const Def *arg)

<tt>tensor.slice</tt>

enum class  slice : flags_t
const Def * normalize_slice (const Def *, const Def *c, const Def *arg)

<tt>tensor.transpose</tt>

enum class  transpose : flags_t
const Def * normalize_transpose (const Def *, const Def *c, const Def *arg)

<tt>tensor.fastest_axis</tt>

enum class  fastest_axis : flags_t
const Def * normalize_fastest_axis (const Def *, const Def *, const Def *arg)

<tt>tensor.if_static</tt>

enum class  if_static : flags_t
const Def * normalize_if_static (const Def *, const Def *, const Def *arg)

<tt>tensor.vec_width</tt>

enum class  vec_width : flags_t
const Def * normalize_vec_width (const Def *, const Def *, const Def *arg)

Detailed Description


Class Documentation

◆ mim::plug::tensor::PureRead

struct mim::plug::tensor::PureRead

A pure re-indexed read: the source tensor, the access map into it (over the read's output coordinates), and the source's element type/rank/shape.

Definition at line 39 of file tensor.h.

Class Members
const Def * map = nullptr
const Def * R = nullptr
const Def * S = nullptr
const Def * src = nullptr
const Def * T = nullptr

Typedef Documentation

◆ mk_sched

Definition at line 17 of file autogen.h.

◆ proj_map

Definition at line 18 of file autogen.h.

◆ Ring

Definition at line 14 of file autogen.h.

◆ Sched

Definition at line 15 of file autogen.h.

◆ SchedT

Definition at line 16 of file autogen.h.

Enumeration Type Documentation

◆ binary

enum class mim::plug::tensor::binary : flags_t
strong

Definition at line 151 of file autogen.h.

◆ binary_impl

Definition at line 406 of file autogen.h.

◆ bmm

enum class mim::plug::tensor::bmm : flags_t
strong

Definition at line 179 of file autogen.h.

◆ bmm_impl

enum class mim::plug::tensor::bmm_impl : flags_t
strong

Definition at line 371 of file autogen.h.

◆ broadcast

Definition at line 72 of file autogen.h.

◆ broadcast_in_dim

Definition at line 80 of file autogen.h.

◆ broadcast_in_dim_impl

Definition at line 294 of file autogen.h.

◆ buf

enum class mim::plug::tensor::buf : flags_t
strong

Definition at line 36 of file autogen.h.

◆ concat

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

Definition at line 88 of file autogen.h.

◆ conv

enum class mim::plug::tensor::conv : flags_t
strong

Definition at line 186 of file autogen.h.

◆ conv_grouped

Definition at line 193 of file autogen.h.

◆ conv_grouped_impl

Definition at line 357 of file autogen.h.

◆ conv_impl

Definition at line 350 of file autogen.h.

◆ dot_product

Definition at line 200 of file autogen.h.

◆ dot_product_impl

Definition at line 364 of file autogen.h.

◆ fastest_axis

Definition at line 235 of file autogen.h.

◆ flip

enum class mim::plug::tensor::flip : flags_t
strong

Definition at line 96 of file autogen.h.

◆ flip_impl

Definition at line 301 of file autogen.h.

◆ fuse_tensor

Definition at line 448 of file autogen.h.

◆ gather

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

Definition at line 221 of file autogen.h.

◆ gather_pointwise_elem_impl

Definition at line 308 of file autogen.h.

◆ generate

enum class mim::plug::tensor::generate : flags_t
strong

Definition at line 22 of file autogen.h.

◆ id

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

Definition at line 51 of file autogen.h.

◆ if_static

Definition at line 243 of file autogen.h.

◆ interchange

Definition at line 259 of file autogen.h.

◆ lower_map_reduce

Definition at line 441 of file autogen.h.

◆ lower_tensor

Definition at line 434 of file autogen.h.

◆ lower_to_mem

Definition at line 455 of file autogen.h.

◆ map

enum class mim::plug::tensor::map : flags_t
strong

Definition at line 158 of file autogen.h.

◆ map_impl

enum class mim::plug::tensor::map_impl : flags_t
strong

Definition at line 315 of file autogen.h.

◆ map_reduce

Definition at line 65 of file autogen.h.

◆ map_reduce_post

Definition at line 58 of file autogen.h.

◆ materialize

Definition at line 266 of file autogen.h.

◆ mr_tileable

Definition at line 273 of file autogen.h.

◆ pad

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

Definition at line 104 of file autogen.h.

◆ pool

enum class mim::plug::tensor::pool : flags_t
strong

Definition at line 207 of file autogen.h.

◆ pool_impl

Definition at line 322 of file autogen.h.

◆ product_2d

Definition at line 214 of file autogen.h.

◆ product_2d_impl

Definition at line 378 of file autogen.h.

◆ reassoc

enum class mim::plug::tensor::reassoc : flags_t
strong

Definition at line 427 of file autogen.h.

◆ repeat

enum class mim::plug::tensor::repeat : flags_t
strong

Definition at line 112 of file autogen.h.

◆ repeat_impl

Definition at line 329 of file autogen.h.

◆ reshape

enum class mim::plug::tensor::reshape : flags_t
strong

Definition at line 120 of file autogen.h.

◆ reshape_impl

Definition at line 343 of file autogen.h.

◆ reshape_map

Definition at line 336 of file autogen.h.

◆ scatter

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

Definition at line 228 of file autogen.h.

◆ scatter_step_impl

Definition at line 385 of file autogen.h.

◆ select

enum class mim::plug::tensor::select : flags_t
strong

Definition at line 165 of file autogen.h.

◆ select_impl

Definition at line 413 of file autogen.h.

◆ shape

enum class mim::plug::tensor::shape : flags_t
strong

Definition at line 43 of file autogen.h.

◆ slice

enum class mim::plug::tensor::slice : flags_t
strong

Definition at line 128 of file autogen.h.

◆ slice_impl

Definition at line 392 of file autogen.h.

◆ splat

enum class mim::plug::tensor::splat : flags_t
strong

Definition at line 29 of file autogen.h.

◆ strip_mine_par

Definition at line 280 of file autogen.h.

◆ strip_mine_red

Definition at line 287 of file autogen.h.

◆ transpose

Definition at line 136 of file autogen.h.

◆ transpose_2d

Definition at line 144 of file autogen.h.

◆ transpose_impl

Definition at line 399 of file autogen.h.

◆ unary

enum class mim::plug::tensor::unary : flags_t
strong

Definition at line 172 of file autogen.h.

◆ unary_impl

Definition at line 420 of file autogen.h.

◆ vec_width

Definition at line 251 of file autogen.h.

Function Documentation

◆ count_consumers()

DefMap< u64 > mim::plug::tensor::count_consumers ( const World & world,
std::predicate< const Def * > auto pred )

Counts the consumers of every def of world matched by pred.

Tuples and packs are transparent argument wrappers, so a wrapped def is charged to the enclosing non-tuple consumer - a shared argument tuple charges each of its users, and a def used twice in one argument list counts twice. A phase whose world does not track uses needs this up front.

Definition at line 109 of file tensor.h.

References count_consumers(), mim::World::externals(), and mim::World::Externals::muts().

Referenced by count_consumers(), mim::plug::tensor::phase::Fuse::start(), and mim::plug::tensor::phase::Reassoc::start().

◆ is_copy_comb()

bool mim::plug::tensor::is_copy_comb ( const Def * comb)
inline

Recognizes the (rebuilt) tensor_copy combiner (acc, ys) ↦ ys#0: the result is exactly the single input element, so a map_reduce built on it is a pure re-indexed read of that input.

Definition at line 25 of file tensor.h.

References mim::Def::as_mut(), is_copy_comb(), mim::Lam::isa_ret_arg(), and mim::Def::proj().

Referenced by is_copy_comb(), and is_pure_read().

◆ is_identity_map()

bool mim::plug::tensor::is_identity_map ( const Def * map)
inline

Is map the identity access map λ x. x?

Definition at line 18 of file tensor.h.

References is_identity_map(), and mim::Def::is_set().

Referenced by is_identity_map(), and is_pure_read().

◆ is_identity_post()

bool mim::plug::tensor::is_identity_post ( const Def * post)
inline

Is post the (rebuilt) CPS identity tensor.id, i.e.

a lam (x, extras) ↦ x that returns its first argument (and hence has no epilogue inputs)?

Definition at line 32 of file tensor.h.

References mim::Def::as_mut(), is_identity_post(), mim::Lam::isa_ret_arg(), and mim::Def::proj().

Referenced by is_identity_post(), and is_pure_read().

◆ is_pure_read()

std::optional< PureRead > mim::plug::tensor::is_pure_read ( const Def * value)
inline

If value is a pure re-indexed read — a copy-combiner map_reduce without reduction loops that writes its full loop domain through the identity output map (reshape/transpose/slice/flip/repeat lower to these) — returns its single access map and source.

fuse_tensor's read-through absorbs exactly these into the consuming op's access maps.

Definition at line 51 of file tensor.h.

References is_copy_comb(), is_identity_map(), is_identity_post(), is_pure_read(), mim::Axm::isa(), and mim::Lit::isa().

Referenced by is_pure_read(), normalize_fastest_axis(), mim::plug::tensor::phase::read_through(), and mim::plug::tensor::phase::Fuse::rewrite_imm_App().

◆ isa_transpose_2d()

const Def * mim::plug::tensor::isa_transpose_2d ( const Def * def)
inline

The input of a 2-D transpose transpose (1, 0), or nullptr.

Definition at line 93 of file tensor.h.

References mim::Axm::isa(), mim::Lit::isa(), and isa_transpose_2d().

Referenced by isa_transpose_2d(), and mim::plug::tensor::phase::Reassoc::start().

◆ lit_perm()

std::optional< fe::Vector< u64 > > mim::plug::tensor::lit_perm ( const Def * perm)
inline

perm as literals, if it is literal.

Definition at line 82 of file tensor.h.

References mim::Lit::isa(), lit_perm(), and lit_projs().

Referenced by lit_perm(), normalize_transpose(), and transpose_perm().

◆ lit_projs()

std::optional< fe::Vector< u64 > > mim::plug::tensor::lit_projs ( const Def * def,
u64 n )
inline

The literal values of def's n projections, or nothing if one of them is not a literal.

Definition at line 71 of file tensor.h.

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

Referenced by lit_perm(), and lit_projs().

◆ normalize_broadcast()

const Def * mim::plug::tensor::normalize_broadcast ( const Def * type,
const Def * c,
const Def * arg )

Definition at line 18 of file normalizers.cpp.

References mim::App::args(), normalize_broadcast(), and mim::Def::projs().

Referenced by normalize_broadcast().

◆ normalize_broadcast_in_dim()

const Def * mim::plug::tensor::normalize_broadcast_in_dim ( const Def * ,
const Def * ,
const Def *  )

Definition at line 32 of file normalizers.cpp.

References normalize_broadcast_in_dim().

Referenced by normalize_broadcast_in_dim().

◆ normalize_concat()

const Def * mim::plug::tensor::normalize_concat ( const Def * ,
const Def * ,
const Def *  )

Definition at line 99 of file normalizers.cpp.

References normalize_concat().

Referenced by normalize_concat().

◆ normalize_fastest_axis()

const Def * mim::plug::tensor::normalize_fastest_axis ( const Def * ,
const Def * ,
const Def * arg )

◆ normalize_flip()

const Def * mim::plug::tensor::normalize_flip ( const Def * ,
const Def * ,
const Def *  )

Definition at line 83 of file normalizers.cpp.

References normalize_flip().

Referenced by normalize_flip().

◆ normalize_if_static()

const Def * mim::plug::tensor::normalize_if_static ( const Def * ,
const Def * ,
const Def * arg )

Definition at line 101 of file normalizers.cpp.

References mim::Lit::isa(), normalize_if_static(), and mim::Def::projs().

Referenced by normalize_if_static().

◆ normalize_pad()

const Def * mim::plug::tensor::normalize_pad ( const Def * ,
const Def * c,
const Def * arg )

Definition at line 85 of file normalizers.cpp.

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

Referenced by normalize_pad().

◆ normalize_repeat()

const Def * mim::plug::tensor::normalize_repeat ( const Def * type,
const Def * c,
const Def * arg )

Definition at line 34 of file normalizers.cpp.

References normalize_repeat(), and mim::Def::type().

Referenced by normalize_repeat().

◆ normalize_reshape()

const Def * mim::plug::tensor::normalize_reshape ( const Def * type,
const Def * c,
const Def * arg )

Definition at line 42 of file normalizers.cpp.

References normalize_reshape(), and mim::Def::type().

Referenced by normalize_reshape().

◆ normalize_shape()

const Def * mim::plug::tensor::normalize_shape ( const Def * ,
const Def * c,
const Def * arg )

Definition at line 155 of file normalizers.cpp.

References mim::App::arg(), mim::Lit::isa(), normalize_shape(), and mim::Def::type().

Referenced by normalize_shape().

◆ normalize_slice()

const Def * mim::plug::tensor::normalize_slice ( const Def * ,
const Def * c,
const Def * arg )

Definition at line 68 of file normalizers.cpp.

References mim::Lit::isa(), and normalize_slice().

Referenced by normalize_slice().

◆ normalize_transpose()

const Def * mim::plug::tensor::normalize_transpose ( const Def * ,
const Def * c,
const Def * arg )

Definition at line 50 of file normalizers.cpp.

References mim::Axm::isa(), lit_perm(), normalize_transpose(), and transpose_perm().

Referenced by normalize_transpose().

◆ normalize_vec_width()

const Def * mim::plug::tensor::normalize_vec_width ( const Def * ,
const Def * ,
const Def * arg )

Definition at line 143 of file normalizers.cpp.

References normalize_vec_width(), Vec_widths, and mim::Def::world().

Referenced by normalize_vec_width().

◆ reg_phases()

void mim::plug::tensor::reg_phases ( Flags2Phases & phases)
static

Definition at line 15 of file tensor.cpp.

References mim::Phase::hook(), and reg_phases().

Referenced by MIM_PLUGIN_ENTRY(), and reg_phases().

◆ register_normalizers()

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

◆ transpose_perm()

std::optional< fe::Vector< u64 > > mim::plug::tensor::transpose_perm ( const App * app)
inline

The permutation of a transpose app, if it is literal.

Definition at line 88 of file tensor.h.

References mim::App::arg(), mim::App::decurry(), lit_perm(), and transpose_perm().

Referenced by normalize_transpose(), and transpose_perm().

Variable Documentation

◆ Plugin_Id

plugin_t mim::plug::tensor::Plugin_Id = 0x5463d44130000000
staticconstexpr

Definition at line 12 of file autogen.h.

◆ Vec_widths

std::array mim::plug::tensor::Vec_widths = {1_u64, 4_u64, 8_u64, 16_u64}
constexpr

The vector widths -X tensor:vec-width accepts.

Definition at line 141 of file normalizers.cpp.

Referenced by normalize_vec_width().