ONE - On-device Neural Engine
Loading...
Searching...
No Matches
circle_eval_diff::MPEIRPrinter Class Referencefinal

#include <MetricPrinter.h>

Collaboration diagram for circle_eval_diff::MPEIRPrinter:

Public Member Functions

void init (const luci::Module *first, const luci::Module *second)
 
void accumulate (const std::vector< std::shared_ptr< Tensor > > &first, const std::vector< std::shared_ptr< Tensor > > &second)
 
void dump (std::ostream &os) const
 
- Public Member Functions inherited from circle_eval_diff::MetricPrinter
virtual ~MetricPrinter ()=default
 

Detailed Description

Definition at line 139 of file MetricPrinter.h.

Member Function Documentation

◆ accumulate()

void circle_eval_diff::MPEIRPrinter::accumulate ( const std::vector< std::shared_ptr< Tensor > > &  first,
const std::vector< std::shared_ptr< Tensor > > &  second 
)
virtual

Implements circle_eval_diff::MetricPrinter.

Definition at line 366 of file MetricPrinter.cpp.

368{
369 assert(first.size() == second.size()); // FIX_CALLER_UNLESS
370 assert(first.size() == _intermediate.size()); // FIX_CALLER_UNLESS
371
372 for (uint32_t output_idx = 0; output_idx < _intermediate.size(); output_idx++)
373 {
374 const auto first_output = first[output_idx];
375 const auto second_output = second[output_idx];
376
377 // Cast data to fp32 for ease of computation
378 const auto fp32_first_output = fp32(first_output);
379 const auto fp32_second_output = fp32(second_output);
380
381 accum_peir(output_idx, fp32_first_output, fp32_second_output);
382 }
383
384 _num_data++;
385}

◆ dump()

void circle_eval_diff::MPEIRPrinter::dump ( std::ostream &  os) const
virtual

Implements circle_eval_diff::MetricPrinter.

Definition at line 387 of file MetricPrinter.cpp.

388{
389 os << "Mean Peak Error to Interval Ratio (MPEIR)" << std::endl;
390
391 for (uint32_t output_idx = 0; output_idx < _intermediate.size(); output_idx++)
392 {
393 const auto name = _output_names.at(output_idx);
394 const auto sum_of_peir = _intermediate.at(output_idx);
395
396 // Compute MPEIR
397 float mpeir = sum_of_peir / _num_data;
398
399 os << "MPEIR for " << name << " is " << mpeir << std::endl;
400 }
401}

◆ init()

void circle_eval_diff::MPEIRPrinter::init ( const luci::Module first,
const luci::Module second 
)
virtual

Reimplemented from circle_eval_diff::MetricPrinter.

Definition at line 300 of file MetricPrinter.cpp.

301{
302 THROW_UNLESS(first != nullptr, "Invalid module.");
303 THROW_UNLESS(second != nullptr, "Invalid module.");
304
305 const auto first_output = loco::output_nodes(first->graph());
306 const auto second_output = loco::output_nodes(second->graph());
307
308 assert(first_output.size() == second_output.size()); // FIX_CALLER_UNLESS
309
310 for (uint32_t i = 0; i < first_output.size(); i++)
311 {
312 const auto first_node = loco::must_cast<luci::CircleOutput *>(first_output[i]);
313 const auto second_node = loco::must_cast<luci::CircleOutput *>(second_output[i]);
314
315 // Create places to store intermediate results
316 _intermediate.emplace_back(0.0);
317
318 // Save output names for logging
319 _output_names.emplace_back(first_node->name());
320 }
321}
#define THROW_UNLESS(COND, MSG)
loco::Graph * graph(void) const
provide main graph
Definition Module.cpp:32
std::vector< Node * > output_nodes(Graph *)
Definition Graph.cpp:101

References luci::Module::graph(), loco::output_nodes(), and THROW_UNLESS.


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