ONE - On-device Neural Engine
Loading...
Searching...
No Matches
entry.cpp File Reference
#include <nncc/core/ADT/tensor/Shape.h>
#include <nncc/core/ADT/tensor/LexicalLayout.h>
#include <nncc/core/ADT/tensor/IndexEnumerator.h>
#include <H5Cpp.h>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <iostream>
#include <set>
#include <stdexcept>
#include <string>
#include <vector>

Go to the source code of this file.

Functions

int entry (int argc, char **argv)
 Dump IR for given arguments.
 

Function Documentation

◆ entry()

int entry ( int  argc,
char **  argv 
)

Dump IR for given arguments.

Call example: $ ./build/compiler/encodump/encodump \ –frontend build/compiler/enco/frontend/caffe/libenco_caffe_frontend.so \ –frontend-arg build/compiler/enco/test/caffe/Convolution_003.prototxt \ –frontend-arg build/compiler/enco/test/caffe/Convolution_003.caffemodel

HDF5 layout is like below

GROUP "/" ㄴGROUP "name" ㄴATTRIBUTE "0" ㄴDATA (0): "input_01:0" ㄴATTRIBUTE "1" ㄴDATA (0): "input_02:0" ㄴGROUP "value" ㄴDATASET "0" ㄴDATA ... ㄴDATASET "1" ㄴDATA ...

Definition at line 193 of file entry.cpp.

194{
195 // The current implementation works only for command-line of the following form:
196 //
197 // i5diff -d 0.001 /path/to/left.h5 /path/to/right.h5
198 //
199 // TODO Support more options
200 assert(argc == 5);
201 assert(std::string(argv[1]) == "-d");
202 assert(std::string(argv[2]) == "0.001");
203
204 H5::H5File lhs{argv[3], H5F_ACC_RDONLY};
205 H5::H5File rhs{argv[4], H5F_ACC_RDONLY};
206
207 ExitcodeTracker exitcode_tracker;
208
209 Mux mux;
210 mux.attach(&exitcode_tracker);
211
212 // Compare values
213 do
214 {
215 // NOTE The name of value group SHOULD BE aligned with nnkit HDF5 actions
216 const std::string value_grpname{"value"};
217
218 H5::Group lhs_value_grp = lhs.openGroup(value_grpname);
219 H5::Group rhs_value_grp = rhs.openGroup(value_grpname);
220
221 // Compare value count
222 int64_t value_count = -1;
223 {
224 uint32_t lhs_value_count = static_cast<uint32_t>(lhs_value_grp.getNumObjs());
225 uint32_t rhs_value_count = static_cast<uint32_t>(rhs_value_grp.getNumObjs());
226
227 if (lhs_value_count != rhs_value_count)
228 {
229 ErrorDetail<ErrorCode::CountMismatch> error{};
230 mux.notify(error);
231 break;
232 }
233
234 value_count = std::max<int64_t>(lhs_value_count, rhs_value_count);
235 }
236 assert(value_count >= 0);
237
238 // Compare each dataset
239 for (int64_t n = 0; n < value_count; ++n)
240 {
241 // NOTE The name of dataset SHOULD BE aligned with nnkit HDF5 actions
242 const std::string dataset_name = std::to_string(n);
243
244 auto lhs_dataset = lhs_value_grp.openDataSet(dataset_name);
245 auto rhs_dataset = rhs_value_grp.openDataSet(dataset_name);
246
247 auto lhs_dtype = to_internal_dtype(lhs_dataset.getDataType());
248 auto rhs_dtype = to_internal_dtype(rhs_dataset.getDataType());
249
250 // TODO Support other data types
251 assert(rhs_dtype == DataType::FLOAT32);
252 assert(lhs_dtype == DataType::FLOAT32);
253
254 if (lhs_dtype != rhs_dtype)
255 {
256 ErrorDetail<ErrorCode::TypeMismatch> error{};
257 mux.notify(error);
258 continue;
259 }
260
261 auto lhs_shape = to_internal_shape(lhs_dataset.getSpace());
262 auto rhs_shape = to_internal_shape(rhs_dataset.getSpace());
263
264 if (!(lhs_shape == rhs_shape))
265 {
266 ErrorDetail<ErrorCode::ShapeMismatch> error{};
267 mux.notify(error);
268 continue;
269 }
270
271 assert(lhs_shape == rhs_shape);
272 assert(lhs_dtype == rhs_dtype);
273 const auto &shape = lhs_shape;
274 const auto &dtype = lhs_dtype;
275
276 switch (dtype)
277 {
278 case DataType::FLOAT32:
279 {
280 auto lhs_vector = as_float_vector(lhs_dataset);
281 auto rhs_vector = as_float_vector(rhs_dataset);
282
283 assert(lhs_vector.size() == rhs_vector.size());
284
285 LexicalLayout layout;
286
287 for (TensorIndexEnumerator e{shape}; e.valid(); e.advance())
288 {
289 const auto &ind = e.current();
290 auto lhs_value = lhs_vector.at(layout.offset(shape, ind));
291 auto rhs_value = rhs_vector.at(layout.offset(shape, ind));
292
293 // TODO Abstract equality criterion
294 if (std::abs(lhs_value - rhs_value) >= 0.001f)
295 {
296 ErrorDetail<ErrorCode::ValueMismatch> error{};
297 mux.notify(error);
298 continue;
299 }
300 }
301
302 break;
303 }
304 default:
305 throw std::runtime_error{"Not supported, yet"};
306 };
307 }
308 } while (false);
309
310 // TODO Compare names (if requested)
311
312 return exitcode_tracker.exitcode();
313}
Severity error(void)
Definition Severity.h:76
std::string value_grpname(void)
Return the name of "value group".
Definition Common.cpp:34

References value_grpname().