MimIR 0.1
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
lower_matrix_mediumlevel.h
Go to the documentation of this file.
1#pragma once
2
3#include <mim/def.h>
4#include <mim/pass/pass.h>
5
6namespace mim::plug::matrix {
7
8/// In this step, we lower `map_reduce` operations into affine for loops making the iteration scheme explicit.
9/// Pseudo-code:
10/// ```
11/// out_matrix = init
12/// for output_indices:
13/// acc = zero
14/// for input_indices:
15/// element_[0..m] = read(matrix[0..m], indices)
16/// acc = f (acc, elements)
17/// insert (out_matrix, output_indices, acc)
18/// return out_matrix
19/// ```
20///
21/// Detailed pseudo-code:
22/// * out indices = (0,1,2, ..., n)
23/// * bounds in S
24/// * we assume that certain paramters are constant and statically known
25/// to avoid inline-metaprogramming like multiiter
26/// e.g. the number of matrizes, the dimensions, the indices
27/// ```
28/// // iterate over out indices
29/// output = init_matrix (n,S,T)
30/// for i_0 in [0, S#0)
31/// ...
32/// for i_{n-1} in [0, S#(n-1))
33/// s = zero
34/// // iterate over non-out indices
35/// for j in [0, SI#(...)]:
36/// // indices depend on the specified access
37/// // input#k#0
38/// e_0 = read (input#0#1, (i_1, i_0))
39/// ...
40/// e_(m-1) = read (input#(m-1)#1, (i_2, j))
41///
42/// s = add(s, mul (e_0, ..., e_(m-1)) )
43/// write (output, (i_0, ..., i_{n-1}), s)
44/// ```
45class LowerMatrixMediumLevel : public RWPass<LowerMatrixMediumLevel, Lam> {
46public:
48 : RWPass(man, "lower_matrix_mediumlevel") {}
49
50 /// custom rewrite function
51 /// memoized version of rewrite_
52 Ref rewrite(Ref) override;
54
55private:
56 Def2Def rewritten;
57};
58
59} // namespace mim::plug::matrix
An optimizer that combines several optimizations in an optimal way.
Definition pass.h:107
PassMan & man()
Definition pass.h:30
Inherit from this class using CRTP, if your Pass does not need state and a fixed-point iteration.
Definition pass.h:220
Helper class to retrieve Infer::arg if present.
Definition def.h:85
In this step, we lower map_reduce operations into affine for loops making the iteration scheme explic...
Ref rewrite(Ref) override
custom rewrite function memoized version of rewrite_
The matrix Plugin
Definition matrix.h:8
DefMap< const Def * > Def2Def
Definition def.h:59