-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathacl_prof.cpp
More file actions
230 lines (189 loc) · 4.58 KB
/
acl_prof.cpp
File metadata and controls
230 lines (189 loc) · 4.58 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
#include <stdio.h>
#include <sys/time.h>
#include <unistd.h>
#include <vector>
double getTime()
{
struct timeval tv;
gettimeofday(&tv, NULL);
return (double)tv.tv_sec + (double)1.0e-6*tv.tv_usec;
}
class IOperation
{
public:
// Destructor
virtual ~IOperation() = default;
virtual void profile(TensorShape input_shape, TensorShape weights_shape, TensorShape output_shape);
private:
};
class ConvolutionLayerOperation final : public IOperation
{
public:
ConvolutionLayerOperation();
void profile(TensorShape input_shape, TensorShape weights_shape, TensorShape output_shape) override
{
TensorInfo info_input = TensorInfo(input_shape, 1, DataType::F32, QuantizationInfo());
TensorInfo info_weights = TensorInfo(input_shape, 1, DataType::F32, QuantizationInfo());
TensorInfo info_output = TensorInfo(input_shape, 1, DataType::F32, QuantizationInfo());
info_input.set_data_layout = DataLayout::NCHW;
info_weights.set_data_layout = DataLayout::NCHW;
info_output.set_data_layout = DataLayout::NCHW;
input.allocator()->init(info_input);
weights.allocator()->init(info_weights);
output.allocator()->init(info_output);
convolution_layer.configure(
}
private:
CLConvolutionLayer convolution_layer;
CLTensor input;
CLTensor weights;
CLTensor output;
CLTuner tuner;
};
class ProfInfo
{
public:
ProfInfo();
void set_operation(char *operation)
{
if (!strcmp(operation, "ConvolutionLayer"))
{
_operation = new ConvolutionLayerOperation();
}
}
void set_input_shape(char *input_shape)
{
int c, h, w;
sscanf(input_shape, "%dx%dx%d", &w, &h, &c);
_input_shape = TensorShape(w, h, c);
}
void set_output_shape(char *output_shape)
{
int c, h, w;
sscanf(output_shape, "%dx%dx%d", &w, &h, &c);
_output_shape = TensorShape(w, h, c);
}
void set_weights_shape(char *weights_shape)
{
int n, c, h, w;
sscanf(weights_shape, "%dx%dx%dx%d", &w, &h, &c, &n);
_weights_shape = TensorShape(w, h, c, n);
}
void set_activation(char *activation)
{
if (!strcmp(activation, "RELU"))
{
}
else if (!strcmp(activation, "BOUNDED_RELU"))
{
}
}
void run()
{
operation->profile();
}
private:
IOperation* _operation;
TensorShape _input_shape;
TensorShape _output_shape;
TensorShape _weights_shape;
};
class Profiler
{
public:
Profiler();
bool do_setup(int argc, char **argv)
{
//cmd_parser(argc, argv);
filename = "test.txt";
return true;
}
bool profile()
{
FILE *fp = fopen(filename, "r");
if (fp == NULL)
{
fprintf(stderr, "Input file is not exist\n");
return false;
}
char buf[256];
while (fgets(fp, buf))
{
if (!strstr(buf, "Instantiated")
continue;
char *ptr = strtok(buf, " ");
do {
ptr = strtok(NULL, " ");
} while (strstr(ptr, "Layer") == NULL);
ProfInfo prof_info;
prof_info.set_operation(ptr);
while (ptr = strtok(NULL, " "))
{
if (!strncmp(ptr, "Input", 256))
{
ptr = strtok(NULL, " ");
ptr = strtok(NULL, " ");
prof_info.set_input_shape(ptr);
}
else if (!strncmp(ptr, "Weights", 256))
{
ptr = strtok(NULL, " ");
ptr = strtok(NULL, " ");
prof_info.set_weights_shape(ptr);
}
else if (!strncmp(ptr, "Shape:", 256))
{
ptr = strtok(NULL, " ");
prof_info.set_input_shape(ptr);
}
else if (!strncmp(ptr, "Output", 256))
{
ptr = strtok(NULL, " ");
ptr = strtok(NULL, " ");
prof_info.set_output_shape(ptr);
}
//else if (!strncmp(ptr, "Epsilon", 256))
//{
//}
else if (strstr(ptr, "RELU"))
{
prof_info.set_activation(ptr);
}
}
v_prof_info.push_back(prof_info);
}
return true;
}
bool profile_success()
{
return true;
}
void print_results()
{
}
private:
//CommmandLinerParser cmd_parser;
//CommonProfilerOptions common_opts;
//CommonProfilerParams common_params;
std::string filename;
vector<ProfInfo> v_prof_info;
};
int main(int argc, char **argv)
{
// Initialize profiling tool
Profiler profiler;
// Profiler setup
profiler.do_setup();
// Run each layer for profiling
profiler.profile();
// Print profiling results
if (profiler.profile_success())
{
profiler.print_results();
}
else
{
std::cout << "Profiling Fail" << std::endl;
}
return 0;
}