forked from dillonhuff/clockwork
-
Notifications
You must be signed in to change notification settings - Fork 0
/
accumulation_memory.cpp
67 lines (56 loc) · 3.38 KB
/
accumulation_memory.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
#include "app.h"
#include "ubuffer.h"
#include "codegen.h"
#include "prog.h"
prog accumulation() {
prog prg;
prg.compute_unit_file = "accumulation_compute.h";
prg.name = "accumulation";
// Stencil<uint16_t, 64, 64> &input_copy_stencil = arg_0;
prg.add_input("input_copy_stencil");
prg.buffer_port_widths["input_copy_stencil"] = 16;
// Stencil<uint8_t, 62, 62> &hw_output_stencil = arg_1;
prg.add_output("hw_output_stencil");
prg.buffer_port_widths["hw_output_stencil"] = 16;
////producing hw_input.stencil
auto hw_input_s0_y = prg.add_loop("hw_input_s0_y", 0, 64);
auto hw_input_s0_x = hw_input_s0_y->add_loop("hw_input_s0_x", 0, 64);
//store is: hw_input.stencil(hw_input.s0.x, hw_input.s0.y) = input_copy.stencil(hw_input.s0.x, hw_input.s0.y)
auto hcompute_hw_input_stencil = hw_input_s0_x->add_op("op_hcompute_hw_input_stencil");
hcompute_hw_input_stencil->add_function("hcompute_hw_input_stencil");
hcompute_hw_input_stencil->add_load("input_copy_stencil", "hw_input_s0_x", "hw_input_s0_y");
prg.buffer_port_widths["hw_input_stencil"] = 16;
hcompute_hw_input_stencil->add_store("hw_input_stencil", "hw_input_s0_x", "hw_input_s0_y");
//consuming hw_input.stencil
////producing conv.stencil
auto conv_s0_y = prg.add_loop("conv_s0_y", 0, 62);
auto conv_s0_x = conv_s0_y->add_loop("conv_s0_x", 0, 62);
//store is: conv.stencil(conv.s0.x, conv.s0.y) = (uint16)0
auto hcompute_conv_stencil = conv_s0_x->add_op("op_hcompute_conv_stencil");
hcompute_conv_stencil->add_function("hcompute_conv_stencil");
prg.buffer_port_widths["conv_stencil"] = 16;
hcompute_conv_stencil->add_store("conv_stencil", "conv_s0_x", "conv_s0_y");
auto conv_s1_y = prg.add_loop("conv_s1_y", 0, 62);
auto conv_s1_x = conv_s1_y->add_loop("conv_s1_x", 0, 62);
////producing kernel.stencil
//consuming kernel.stencil
auto conv_s1_r_y = conv_s1_x->add_loop("conv_s1_r_y", 0, 3);
auto conv_s1_r_x = conv_s1_r_y->add_loop("conv_s1_r_x", 0, 3);
//store is: conv.stencil(conv.s1.x, conv.s1.y) = (conv.stencil(conv.s1.x, conv.s1.y) + (hw_input.stencil((conv.s1.r$x + conv.s1.x), (conv.s1.r$y + conv.s1.y))*uint16(kernel.stencil((conv.s1.r$x + (conv.s1.r$y*3))))))
auto hcompute_conv_stencil_1 = conv_s1_r_x->add_op("op_hcompute_conv_stencil_1");
hcompute_conv_stencil_1->add_function("hcompute_conv_stencil_1");
hcompute_conv_stencil_1->add_load("conv_stencil", "conv_s1_x", "conv_s1_y");
hcompute_conv_stencil_1->add_load("hw_input_stencil", "(conv_s1_r_x + conv_s1_x)", "(conv_s1_r_y + conv_s1_y)");
hcompute_conv_stencil_1->add_store("conv_stencil", "conv_s1_x", "conv_s1_y");
hcompute_conv_stencil_1->compute_unit_needs_index_variable("conv_s1_r_x");
hcompute_conv_stencil_1->compute_unit_needs_index_variable("conv_s1_r_y");
//consuming conv.stencil
auto hw_output_s0_y_yi = prg.add_loop("hw_output_s0_y_yi", 0, 62);
auto hw_output_s0_x_xi = hw_output_s0_y_yi->add_loop("hw_output_s0_x_xi", 0, 62);
//store is: hw_output.stencil(hw_output.s0.x.xi, hw_output.s0.y.yi) = uint8(conv.stencil(hw_output.s0.x.xi, hw_output.s0.y.yi))
auto hcompute_hw_output_stencil = hw_output_s0_x_xi->add_op("op_hcompute_hw_output_stencil");
hcompute_hw_output_stencil->add_function("hcompute_hw_output_stencil");
hcompute_hw_output_stencil->add_load("conv_stencil", "hw_output_s0_x_xi", "hw_output_s0_y_yi");
hcompute_hw_output_stencil->add_store("hw_output_stencil", "hw_output_s0_x_xi", "hw_output_s0_y_yi");
return prg;
}