MimIR
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
normalizers.cpp
Go to the documentation of this file.
1#include <mim/def.h>
2#include <mim/world.h>
3
5
6namespace mim::plug::btensor {
7
8/// btensor.map_reduce is btensor.map_reduce_post without the epilogue and with the neutral schedule:
9/// delegate with `post = btensor.id` (so `Tp = To`), no epilogue inputs (`nps = 0`), no vector dim
10/// (`vdim = Rn`, the out-of-range sentinel), and no unrolling.
11/// The delegation lives in a normalizer (rather than a wrapping `lam`) so that call sites keep axm-style
12/// implicit inference: the stuck axm application lets the checker solve the `{Tis, Ris, Sis}` holes from the
13/// operands, whereas applying a `lam` would eagerly β-reduce `buffer.Buf` over still-unsolved holes.
14const Def* normalize_map_reduce(const Def*, const Def* c, const Def* arg) {
15 auto& w = c->world();
16
17 auto [nis, meta, shapes, TisRisSis, comb_init, map_out, maps] = c->as<App>()->uncurry_args<7>();
18 auto [To, Ro, Rn] = meta->projs<3>();
19 auto [So, Sr] = shapes->projs<2>();
20 auto [Tis, Ris, Sis] = TisRisSis->projs<3>();
21 auto [comb, init] = comb_init->projs<2>();
22 auto [mem, is] = arg->projs<2>();
23
24 auto sched = w.app(w.annex<btensor::mk_sched>(), {Rn, w.lit_nat_0()});
25 auto post = w.app(w.annex<btensor::id>(), To);
26 auto unit = w.tuple();
27
28 auto op = w.annex<btensor::map_reduce_post>();
29 op = w.app(op, {nis, w.lit_nat_0()});
30 op = w.app(op, {To, To, Ro, Rn, sched->type()});
31 op = w.app(op, {So, Sr, sched});
32 op = w.app(op, {Tis, Ris, Sis, unit, unit, unit});
33 op = w.app(op, {comb, init, post});
34 op = w.app(op, map_out);
35 op = w.app(op, {maps, unit});
36 return w.app(op, {mem, is, unit});
37}
38
40
41} // namespace mim::plug::btensor
#define MIM_btensor_NORMALIZER_IMPL
Definition autogen.h:127
Base class for all Defs.
Definition def.h:273
auto projs(F f) const
Splits this Def via Def::projections into an Array (if A == std::dynamic_extent) or std::array (other...
Definition def.h:440
The btensor Plugin
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: del...
The mem Plugin
Definition mem.h:11