-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdebug-api.cpp
More file actions
159 lines (132 loc) · 4.22 KB
/
Copy pathdebug-api.cpp
File metadata and controls
159 lines (132 loc) · 4.22 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
//
// Licensed under the MIT License. See LICENSE.TXT file in the project root for full license information.
//
#ifdef _MSC_VER
#ifndef _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#endif//_CRT_SECURE_NO_WARNINGS
#endif//_MSC_VER
#include "../include/debug-api.h"
#include "io-broadcast.hpp"
using namespace Halide;
// from 'imgui_main.cpp':
extern bool stdout_echo_toggle;
void run_gui(std::vector<Func> funcs, std::vector<Buffer<>> funcs_outputs);
struct UI
{
void run(std::vector<Func> funcs, std::vector<Buffer<>> funcs_outputs)
{
// redirect stdout to a log file, effectivelly silencing the console output:
const char* logfile = "data/output/log-halide-visdbg.txt";
fprintf(stdout, ">> Redirecting 'stdout' to log file '%s'\n", logfile);
FILE* log = fopen(logfile, "w");
assert(log);
Broadcaster iobc = redirect_broadcast(stdout);
iobc.AddEcho(&stdout_echo_toggle);
iobc.AddFile(log);
run_gui(funcs, funcs_outputs);
iobc.Terminate();
fprintf(stdout, "<< Done with 'stdout' redirection\n");
fclose(log);
}
};
namespace Halide
{
void DebugFunc::realize(Pipeline::RealizationArg outputs, const Target &target,
const ParamMap ¶m_map)
{
Buffer<> output;
if(outputs.size() == 1)
{
halide_buffer_t * buf = outputs.buf;
Buffer<> buffer (*buf);
output = buffer;
}
else
{
output = outputs.buffer_list->at(0);
}
UI ui;
std::vector<Func> funcs;
funcs.push_back(this->f);
ui.run(funcs, { output });
this->f.realize(std::move(outputs), target, param_map);
}
Realization DebugFunc::realize(std::vector<int32_t> sizes, const Target &target,
const ParamMap ¶m_map)
{
// TODO(marcos): maybe this should be the core implementation, instead of
// the one with 'Pipeline::RealizationArg' above...
Realization outputs = this->f.realize(sizes, target, param_map);
realize(outputs, target, param_map);
return outputs;
}
Realization DebugFunc::realize(int x_size, int y_size, int z_size, int w_size, const Target &target,
const ParamMap ¶m_map)
{
return realize({ x_size, y_size, z_size, w_size }, target, param_map);;
}
Realization DebugFunc::realize(int x_size, int y_size, int z_size, const Target &target,
const ParamMap ¶m_map)
{
return realize({ x_size, y_size, z_size }, target, param_map);
}
Realization DebugFunc::realize(int x_size, int y_size, const Target &target,
const ParamMap ¶m_map)
{
return realize({ x_size, y_size }, target, param_map);
}
Realization DebugFunc::realize(Halide::Buffer<> input, int x_size, const Target &target,
const ParamMap ¶m_map)
{
return realize(std::vector<int>{x_size}, target, param_map);
}
Realization DebugFunc::realize(const Target &target,
const ParamMap ¶m_map)
{
return realize(std::vector<int>{}, target, param_map);
}
DebugFunc debug(Func f)
{
DebugFunc debug_f;
debug_f.f = f;
return debug_f;
}
ReplayableFunc::ReplayableFunc(Func f)
: outputs(nullptr)
{
this->f = f;
}
ReplayableFunc&& ReplayableFunc::realize(Pipeline::RealizationArg outputs, const Target &target, const ParamMap ¶m_map)
{
new (&(this->outputs)) Pipeline::RealizationArg(std::move(outputs));
this->target = target;
new (&(this->param_map)) ParamMap(std::move(param_map));
return std::move(*this);
}
void replay(std::vector<ReplayableFunc> &rpfuncs)
{
std::vector<Func> funcs;
std::vector<Buffer<>> funcs_outputs;
for (auto& rpf : rpfuncs)
{
Func& f = rpf.f;
auto& outputs = rpf.outputs;
Buffer<> output;
if (outputs.size() == 1)
{
halide_buffer_t * buf = outputs.buf;
Buffer<> buffer(*buf);
output = buffer;
}
else
{
output = outputs.buffer_list->at(0);
}
funcs.emplace_back(f);
funcs_outputs.emplace_back(output);
}
UI ui;
ui.run(funcs, funcs_outputs);
}
}