-
Notifications
You must be signed in to change notification settings - Fork 133
/
Copy pathtutorial_07.cpp
79 lines (64 loc) · 2.16 KB
/
tutorial_07.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/**
* A more complicated reduction.
*
* We want to represent the following program
*
* for y = 0 to 19
* for x = 0 to 9
* f(y, x) = 1
*
* for y = 0 to 19
* g(y) = 0
* for y = 0 to 19
* for rx = 0 to 9
* g(y) += f(y, rx)
*
*
* In order to implement this program, we create the following
* computations
*
* {f[x,y]: 0<=x<19 and 0<=y<9}: 1
* {g[y,-1]: 0<=y<19}: 0
* {g[y,rx]: 0<=y<19 and 0<=rx<9}: g(y,rx-1) + f(y,rx)
*
*/
#include <tiramisu/tiramisu.h>
#include "wrapper_tutorial_07.h"
using namespace tiramisu;
void generate_function(std::string name, int size, int val0)
{
// Set default tiramisu options.
tiramisu::init();
// -------------------------------------------------------
// Layer I
// -------------------------------------------------------
function function0(name);
var x = var("x");
var y = var("y");
var rx = var("rx");
computation f("{f[y,x]: 0<=y<19 and 0<=x<9}", expr((uint8_t) 1), true, p_uint8, &function0);
computation g_0("{g_0[y,-1]: 0<=y<19}", expr((uint8_t) 0), true, p_uint8, &function0);
computation g_1("{g_1[y,rx]: 0<=y<19 and 0<=rx<9}", g_0(y,rx-1) + f(y,rx), true, p_uint8, &function0);
// -------------------------------------------------------
// Layer II
// -------------------------------------------------------
g_0.after(f, computation::root);
g_1.after(g_0, computation::root);
// -------------------------------------------------------
// Layer III
// -------------------------------------------------------
buffer f_buff("f_buff", {19,size}, p_uint8, a_temporary, &function0);
buffer g_buff("g_buff", {size}, p_uint8, a_output, &function0);
f.set_access("{f[y,x]->f_buff[y,x]}");
g_0.set_access("{g_0[y,rx]->g_buff[y]}");
g_1.set_access("{g_1[y,rx]->g_buff[y]}");
// -------------------------------------------------------
// Code Generation
// -------------------------------------------------------
function0.codegen({&g_buff}, "build/generated_fct_developers_tutorial_07.o");
}
int main(int argc, char **argv)
{
generate_function("tiramisu_generated_code", SIZE1, 0);
return 0;
}