-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
95 lines (78 loc) · 2.86 KB
/
Copy pathmain.cpp
File metadata and controls
95 lines (78 loc) · 2.86 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <iostream>
#include <memory>
#include <cstdlib>
#include <chrono>
#include "tilt/pass/printer.h"
#include "tilt/pass/codegen/loopgen.h"
#include "tilt/pass/codegen/llvmgen.h"
#include "tilt/pass/codegen/vinstr.h"
#include "tilt/engine/engine.h"
#include "tilt/builder/tilder.h"
using namespace tilt;
using namespace tilt::tilder;
using namespace std;
using namespace std::chrono;
Op _Select(_sym in, function<Expr(_sym)> selector)
{
auto e = in[_pt(0)];
auto e_sym = _sym("e", e);
auto res = selector(e_sym);
auto res_sym = _sym("res", res);
auto sel_op = _op(
_iter(0, 1),
Params{in},
SymTable{{e_sym, e}, {res_sym, res}},
_exists(e_sym),
res_sym);
return sel_op;
}
int main(int argc, char* argv[])
{
int dlen = (argc > 1) ? atoi(argv[1]) : 30;
int len = (argc > 2) ? atoi(argv[2]) : 10;
// input stream
auto in_sym = _sym("in", tilt::Type(types::FLOAT32, _iter(0, -1)));
auto query_op = _Select(in_sym, [](_sym e) { return e + _f32(10); });
auto query_op_sym = _sym("query", query_op);
cout << endl << "TiLT IR:" << endl;
cout << IRPrinter::Build(query_op) << endl;
auto loop = LoopGen::Build(query_op_sym, query_op.get());
cout << endl << "Loop IR:" << endl;
cout << IRPrinter::Build(loop);
auto jit = ExecEngine::Get();
auto& llctx = jit->GetCtx();
auto llmod = LLVMGen::Build(loop, llctx);
cout << endl << "LLVM IR:" << endl;
cout << IRPrinter::Build(llmod.get()) << endl;
jit->AddModule(move(llmod));
auto loop_addr = (region_t* (*)(ts_t, ts_t, region_t*, region_t*)) jit->Lookup(loop->get_name());
uint32_t dur = 1;
auto buf_size = get_buf_size(dlen);
auto in_tl = new ival_t[dlen];
auto in_data = new float[dlen];
region_t in_reg;
init_region(&in_reg, 0, buf_size, in_tl, reinterpret_cast<char*>(in_data));
for (int i = 0; i < dlen; i++) {
auto t = dur * (i + 1);
commit_data(&in_reg, t);
auto* ptr = reinterpret_cast<float*>(fetch(&in_reg, t, get_end_idx(&in_reg), sizeof(float)));
*ptr = i%1000;
}
auto out_tl = new ival_t[dlen];
auto out_data = new float[dlen];
region_t out_reg;
init_region(&out_reg, 0, buf_size, out_tl, reinterpret_cast<char*>(out_data));
auto start_time = high_resolution_clock::now();
auto* res_reg = loop_addr(0, dur*dlen, &out_reg, &in_reg);
auto end_time = high_resolution_clock::now();
int out_count = dlen;
if (argc == 1) {
for (int i = 0; i < dlen; i++) {
cout << "(" << in_tl[i].t << "," << in_tl[i].d << ") " << in_data[i] << " -> "
<< "(" << out_tl[i].t << "," << out_tl[i].d << ") " << out_data[i] << endl;
}
}
auto time = duration_cast<microseconds>(end_time - start_time).count();
cout << "Data size: " << out_count << " Time: " << time << endl;
return 0;
}