ONE - On-device Neural Engine
Loading...
Searching...
No Matches
circle_eval_diff Namespace Reference

Data Structures

class  CircleEvalDiff
 
class  DirectoryLoader
 
class  HDF5Loader
 
class  InputDataLoader
 
class  MAEPrinter
 
class  MAPEPrinter
 
class  MetricPrinter
 
class  MPEIRPrinter
 
class  MSEPrinter
 
struct  Tensor
 
struct  TensorDataType
 
struct  TensorShape
 
class  TopKMatchPrinter
 

Enumerations

enum class  Metric {
  Undefined , MAE , MAPE , MPEIR ,
  MTOP1 , MTOP5 , MSE
}
 
enum class  InputFormat { Undefined , H5 , DIR }
 

Functions

std::vector< std::shared_ptr< Tensor > > interpret (const luci::Module *module, const InputDataLoader::Data &data)
 
void verifyTypeShape (const luci::CircleInput *input_node, const DataType &dtype, const Shape &shape)
 
std::vector< size_t > getEachByteSizeOf (const std::vector< loco::Node * > &nodes)
 
size_t getTotalByteSizeOf (const std::vector< loco::Node * > &nodes)
 
std::unique_ptr< InputDataLoadermakeDataLoader (const std::string &file_path, const InputFormat &format, const std::vector< loco::Node * > &input_nodes)
 
void verifyTypeShape (const luci::CircleInput *input_node, const loco::DataType &dtype, const std::vector< loco::Dimension > &shape)
 
 INSTANTIATE (loco::DataType::S64)
 
 INSTANTIATE (loco::DataType::S32)
 
 INSTANTIATE (loco::DataType::S16)
 
 INSTANTIATE (loco::DataType::U8)
 
 INSTANTIATE (loco::DataType::FLOAT32)
 
std::shared_ptr< TensorcreateEmptyTensor (const luci::CircleNode *node)
 

Enumeration Type Documentation

◆ InputFormat

enum class circle_eval_diff::InputFormat
strong
Enumerator
Undefined 
H5 
DIR 

Definition at line 40 of file InputDataLoader.h.

41{
42 Undefined, // For debugging
43 H5,
44 DIR, // directory
45 // TODO Implement Random, Directory
46};

◆ Metric

enum class circle_eval_diff::Metric
strong
Enumerator
Undefined 
MAE 
MAPE 
MPEIR 
MTOP1 
MTOP5 
MSE 

Definition at line 36 of file CircleEvalDiff.h.

37{
38 Undefined, // For debugging
39 MAE, // Mean Absolute Error
40 MAPE, // Mean Percentage Absolute Error
41 MPEIR, // Mean Peak Error to Interval Ratio
42 MTOP1, // Mean Top-1 Match Ratio
43 MTOP5, // Mean Top-5 Match Ratio
44 MSE, // Mean Squared Error
45};

Function Documentation

◆ createEmptyTensor()

std::shared_ptr< Tensor > circle_eval_diff::createEmptyTensor ( const luci::CircleNode node)

Definition at line 90 of file Tensor.cpp.

91{
92 auto tensor = std::make_shared<Tensor>();
93 {
94 tensor->dtype(node->dtype());
95 tensor->rank(node->rank());
96 for (uint32_t i = 0; i < node->rank(); i++)
97 tensor->dim(i) = node->dim(i);
98
99 switch (node->dtype())
100 {
101 case loco::DataType::FLOAT32:
102 tensor->size<loco::DataType::FLOAT32>(numElements(node));
103 break;
104 case loco::DataType::U8:
105 tensor->size<loco::DataType::U8>(numElements(node));
106 break;
107 case loco::DataType::S16:
108 tensor->size<loco::DataType::S16>(numElements(node));
109 break;
110 case loco::DataType::S32:
111 tensor->size<loco::DataType::S32>(numElements(node));
112 break;
113 case loco::DataType::S64:
114 tensor->size<loco::DataType::S64>(numElements(node));
115 break;
116 default:
117 throw std::runtime_error("Unsupported input tensor dtype for " + node->name());
118 }
119 }
120
121 return tensor;
122}
NodeName name(void) const

References luci::CircleNode::name().

Referenced by circle_eval_diff::HDF5Loader::get(), circle_eval_diff::DirectoryLoader::get(), and interpret().

◆ getEachByteSizeOf()

std::vector< size_t > circle_eval_diff::getEachByteSizeOf ( const std::vector< loco::Node * > &  nodes)

Definition at line 52 of file InputDataLoader.cpp.

53{
54 std::vector<size_t> vec;
55
56 for (const auto node : nodes)
57 {
58 const auto input_node = loco::must_cast<const luci::CircleInput *>(node);
59 const auto dtype_size = luci::size(input_node->dtype());
60 size_t element_size = 1;
61
62 for (uint32_t index = 0; index < input_node->rank(); index++)
63 {
64 element_size *= input_node->dim(index).value();
65 }
66
67 vec.push_back(element_size * dtype_size);
68 }
69
70 return vec;
71}
uint32_t size(loco::DataType data_type)
Returns the size of the data type.

References luci::size().

Referenced by circle_eval_diff::DirectoryLoader::get().

◆ getTotalByteSizeOf()

size_t circle_eval_diff::getTotalByteSizeOf ( const std::vector< loco::Node * > &  nodes)

Definition at line 73 of file InputDataLoader.cpp.

74{
75 size_t total_byte_size = 0;
76
77 for (const auto node : nodes)
78 {
79 const auto input_node = loco::must_cast<const luci::CircleInput *>(node);
80 size_t byte_size = luci::size(input_node->dtype());
81
82 for (uint32_t index = 0; index < input_node->rank(); index++)
83 {
84 byte_size *= input_node->dim(index).value();
85 }
86
87 total_byte_size += byte_size;
88 }
89
90 return total_byte_size;
91}

References luci::size().

Referenced by circle_eval_diff::DirectoryLoader::DirectoryLoader(), and circle_eval_diff::DirectoryLoader::get().

◆ INSTANTIATE() [1/5]

circle_eval_diff::INSTANTIATE ( loco::DataType::FLOAT32  )

◆ INSTANTIATE() [2/5]

circle_eval_diff::INSTANTIATE ( loco::DataType::S16  )

◆ INSTANTIATE() [3/5]

circle_eval_diff::INSTANTIATE ( loco::DataType::S32  )

◆ INSTANTIATE() [4/5]

circle_eval_diff::INSTANTIATE ( loco::DataType::S64  )

◆ INSTANTIATE() [5/5]

circle_eval_diff::INSTANTIATE ( loco::DataType::U8  )

◆ interpret()

std::vector< std::shared_ptr< Tensor > > circle_eval_diff::interpret ( const luci::Module module,
const InputDataLoader::Data data 
)

Definition at line 109 of file CircleEvalDiff.cpp.

111{
112 auto interpreter = std::make_unique<luci_interpreter::Interpreter>(module);
113
114 auto input_nodes = ::inputs_of(module);
115 auto output_nodes = ::outputs_of(module);
116
117 for (uint32_t input_idx = 0; input_idx < data.size(); input_idx++)
118 {
119 auto input_node = loco::must_cast<const luci::CircleInput *>(input_nodes[input_idx]);
120 assert(input_node->index() == input_idx);
121
122 auto input_data = data.at(input_idx);
123 interpreter->writeInputTensor(input_node, input_data.buffer(), input_data.byte_size());
124 }
125
126 interpreter->interpret();
127
128 std::vector<std::shared_ptr<Tensor>> outputs;
129 for (uint32_t output_idx = 0; output_idx < output_nodes.size(); output_idx++)
130 {
131 auto output_node = loco::must_cast<const luci::CircleOutput *>(output_nodes[output_idx]);
132 assert(output_node->index() == output_idx);
133
134 auto tensor = createEmptyTensor(output_node);
135 interpreter->readOutputTensor(output_node, tensor->buffer(), tensor->byte_size());
136 outputs.emplace_back(tensor);
137 }
138
139 return outputs;
140}
void index(const loco::GraphInputIndex &index)
void index(const loco::GraphOutputIndex &index)

References createEmptyTensor(), luci::CircleInput::index(), and luci::CircleOutput::index().

Referenced by circle_eval_diff::CircleEvalDiff::evalDiff().

◆ makeDataLoader()

std::unique_ptr< InputDataLoader > circle_eval_diff::makeDataLoader ( const std::string &  file_path,
const InputFormat format,
const std::vector< loco::Node * > &  input_nodes 
)

Definition at line 220 of file InputDataLoader.cpp.

223{
224 switch (format)
225 {
226 case InputFormat::H5:
227 {
228 return std::make_unique<HDF5Loader>(file_path, input_nodes);
229 }
230 case InputFormat::DIR:
231 {
232 return std::make_unique<DirectoryLoader>(file_path, input_nodes);
233 }
234 default:
235 throw std::runtime_error{"Unsupported input format."};
236 }
237}

References DIR, and H5.

Referenced by circle_eval_diff::CircleEvalDiff::evalDiff().

◆ verifyTypeShape() [1/2]

void circle_eval_diff::verifyTypeShape ( const luci::CircleInput input_node,
const DataType dtype,
const Shape shape 
)

Definition at line 36 of file InputDataLoader.cpp.

37{
38 // Type check
39 if (dtype != input_node->dtype())
40 throw std::runtime_error("Wrong input type.");
41
42 if (shape.size() != input_node->rank())
43 throw std::runtime_error("Input rank mismatch.");
44
45 for (uint32_t i = 0; i < shape.size(); i++)
46 {
47 if (not(shape.at(i) == input_node->dim(i)))
48 throw std::runtime_error("Input shape mismatch.");
49 }
50}

Referenced by circle_eval_diff::HDF5Loader::get().

◆ verifyTypeShape() [2/2]

void circle_eval_diff::verifyTypeShape ( const luci::CircleInput input_node,
const loco::DataType dtype,
const std::vector< loco::Dimension > &  shape 
)