ONE - On-device Neural Engine
Loading...
Searching...
No Matches
minmax_embedder::h5::Reader Class Reference

#include <Reader.h>

Public Member Functions

 Reader (const std::string &filepath)
 
MinMaxVectors read (int model_idx, int subg_idx, int op_idx) const
 Returns minmax recording for op {model_idx, subg_idx, op_idx}.
 
MinMaxVectors read_input (int model_idx, int subg_idx, int input_idx) const
 Returns minmax recording for input {model_idx, subg_idx, input_idx}.
 

Detailed Description

Definition at line 59 of file Reader.h.

Constructor & Destructor Documentation

◆ Reader()

minmax_embedder::h5::Reader::Reader ( const std::string &  filepath)

Definition at line 33 of file Reader.cpp.

33 : _file(filepath, H5F_ACC_RDONLY)
34{
35 _val_grp = _file.openGroup(h5_value_grpname);
36}

Member Function Documentation

◆ read()

MinMaxVectors minmax_embedder::h5::Reader::read ( int  model_idx,
int  subg_idx,
int  op_idx 
) const

Returns minmax recording for op {model_idx, subg_idx, op_idx}.

Returns
MinMaxVectors

Definition at line 39 of file Reader.cpp.

40{
41 MinMaxVectors mmv;
42 float minmax[2];
43 auto num_run = _val_grp.getNumObjs();
44 for (uint32_t r = 0; r < num_run; ++r)
45 {
46 // check whether minmax exists
47 char path[128]; // 128 is enough to print "/value/run_%d/model_%d/subg_%d/op_%d" + null
48 snprintf(path, 128, "/value/run_%d/model_%d/subg_%d/op_%d", r, model_idx, subg_idx, op_idx);
49 if (!exists(_file.getId(), path))
50 continue;
51 auto run_grp = _val_grp.openGroup(std::string("run_") + std::to_string(r));
52 auto model_grp = run_grp.openGroup(std::string("model_") + std::to_string(model_idx));
53 auto subg_grp = model_grp.openGroup(std::string("subg_") + std::to_string(subg_idx));
54 auto op_dset = subg_grp.openDataSet(std::string("op_") + std::to_string(op_idx));
55 H5::DataType dtype = op_dset.getDataType();
56 if (not(dtype == H5::PredType::IEEE_F32BE || dtype == H5::PredType::IEEE_F32LE))
57 throw std::runtime_error{"dtype of min, max in h5 is not float."};
58 op_dset.read(minmax, H5::PredType::NATIVE_FLOAT);
59 mmv.min_vector.emplace_back(minmax[0]);
60 mmv.max_vector.emplace_back(minmax[1]);
61 }
62 return mmv;
63}

References minmax_embedder::h5::MinMaxVectors::max_vector, and minmax_embedder::h5::MinMaxVectors::min_vector.

◆ read_input()

MinMaxVectors minmax_embedder::h5::Reader::read_input ( int  model_idx,
int  subg_idx,
int  input_idx 
) const

Returns minmax recording for input {model_idx, subg_idx, input_idx}.

Returns
MinMaxVectors

Definition at line 65 of file Reader.cpp.

66{
67 MinMaxVectors mmv;
68 float minmax[2];
69 auto num_run = _val_grp.getNumObjs();
70 for (uint32_t r = 0; r < num_run; ++r)
71 {
72 // check whether minmax exists
73 char path[128]; // 128 is enough to print "/value/run_%d/model_%d/subg_%d/input_%d" + null
74 snprintf(path, 128, "/value/run_%d/model_%d/subg_%d/input_%d", r, model_idx, subg_idx,
75 input_idx);
76 if (!exists(_file.getId(), path))
77 continue;
78 auto run_grp = _val_grp.openGroup(std::string("run_") + std::to_string(r));
79 auto model_grp = run_grp.openGroup(std::string("model_") + std::to_string(model_idx));
80 auto subg_grp = model_grp.openGroup(std::string("subg_") + std::to_string(subg_idx));
81 auto op_dset = subg_grp.openDataSet(std::string("input_") + std::to_string(input_idx));
82
83 H5::DataType dtype = op_dset.getDataType();
84 if (not(dtype == H5::PredType::IEEE_F32BE || dtype == H5::PredType::IEEE_F32LE))
85 throw std::runtime_error{"dtype of min, max in h5 is not float."};
86 op_dset.read(minmax, H5::PredType::NATIVE_FLOAT);
87 mmv.min_vector.emplace_back(minmax[0]);
88 mmv.max_vector.emplace_back(minmax[1]);
89 }
90 return mmv;
91}

References minmax_embedder::h5::MinMaxVectors::max_vector, and minmax_embedder::h5::MinMaxVectors::min_vector.


The documentation for this class was generated from the following files: