ONE - On-device Neural Engine
Loading...
Searching...
No Matches
mio::circle Namespace Reference

Data Structures

class  Reader
 Loads Circle file and provides helpers to access attributes. More...
 

Functions

bool is_valid (const ::circle::OperatorCode *opcode)
 
bool is_custom (const ::circle::OperatorCode *opcode)
 
std::string opcode_name (const ::circle::OperatorCode *opcode)
 
const char * tensor_type (const ::circle::Tensor *tensor)
 
const char * tensor_name (const ::circle::Tensor *tensor)
 
::circle::BuiltinOperator builtin_code_neutral (const ::circle::OperatorCode *opcode)
 
template<typename T >
std::vector< T > as_index_vector (const flatbuffers::Vector< T > *flat_array)
 

Function Documentation

◆ as_index_vector()

template<typename T >
std::vector< T > mio::circle::as_index_vector ( const flatbuffers::Vector< T > *  flat_array)

Definition at line 36 of file Helper.h.

37{
38 if (flat_array == nullptr)
39 {
40 throw std::runtime_error("flat array is nullptr");
41 }
42
43 std::vector<T> ret(flat_array->Length());
44 for (uint32_t i = 0; i < flat_array->Length(); i++)
45 {
46 ret[i] = flat_array->Get(i);
47 }
48 return ret;
49}
return_type Get(uoffset_t i) const

References flatbuffers::Vector< T >::Get().

Referenced by circledump::dump_sub_graph(), circledump::ReshapePrinter::options(), mio::circle::Reader::outputs(), circleinspect::DumpConv2DWeight::run(), and mio::circle::Reader::select_subgraph().

◆ builtin_code_neutral()

circle::BuiltinOperator mio::circle::builtin_code_neutral ( const ::circle::OperatorCode *  opcode)

This will provide v3/v3a/v3b format neutral BuiltinOperator NOTE circle has minus value opcode (252~254 as uint8_t) we cannot use std::max() like tflite as deprecated_builtin_code can be minus and builtin_code being 0 for v0.3 files.

Definition at line 33 of file Helper.cpp.

34{
35 assert(opcode != nullptr);
36 if (opcode->deprecated_builtin_code() == 127)
37 {
38 assert(opcode->builtin_code() >= 127);
39 return opcode->builtin_code();
40 }
41 // There was no 255(-1) value in v0.3
42 assert(opcode->deprecated_builtin_code() != -1);
43 return static_cast<::circle::BuiltinOperator>(opcode->deprecated_builtin_code());
44}

Referenced by mio::circle::Reader::builtin_code(), circlechef::CircleImport::builtin_code(), and luci::CircleReader::builtin_code().

◆ is_custom()

bool mio::circle::is_custom ( const ::circle::OperatorCode *  opcode)

Definition at line 32 of file Helper.cpp.

33{
34 ::circle::BuiltinOperator code = opcode->builtin_code();
35 return (code == ::circle::BuiltinOperator_CUSTOM);
36}

Referenced by opcode_name(), and circlechef::CircleImport::opcode_name().

◆ is_valid()

bool mio::circle::is_valid ( const ::circle::OperatorCode *  opcode)

Definition at line 26 of file Helper.cpp.

27{
28 ::circle::BuiltinOperator code = opcode->builtin_code();
29 return (::circle::BuiltinOperator_MIN <= code && code <= ::circle::BuiltinOperator_MAX);
30}

Referenced by mio::circle::Reader::opcode_name(), opcode_name(), and circlechef::CircleImport::opcode_name().

◆ opcode_name()

std::string mio::circle::opcode_name ( const ::circle::OperatorCode *  opcode)

Definition at line 38 of file Helper.cpp.

39{
40 assert(opcode);
41
42 if (!is_valid(opcode))
43 {
44 std::ostringstream oss;
45 oss << "(invalid)";
46 return oss.str();
47 }
48
49 if (is_custom(opcode))
50 {
51 if (!opcode->custom_code())
52 return "(invalid custom)";
53
54 std::string custom_op = "CUSTOM(";
55 custom_op += opcode->custom_code()->c_str();
56 custom_op += ")";
57 return custom_op;
58 }
59
60 ::circle::BuiltinOperator code = opcode->builtin_code();
61 return ::circle::EnumNameBuiltinOperator(code);
62}
bool is_valid(const ::circle::OperatorCode *opcode)
Definition Helper.cpp:26

References is_custom(), and is_valid().

Referenced by circledump::dump_model(), mio::circle::Reader::opcode_name(), and luci::CircleReader::opcode_name().

◆ tensor_name()

const char * mio::circle::tensor_name ( const ::circle::Tensor *  tensor)

Definition at line 69 of file Helper.cpp.

70{
71 static const char *kEmptyTensorName = "(noname)";
72
73 auto name = tensor->name();
74 if (name)
75 return name->c_str();
76
77 return kEmptyTensorName;
78}

Referenced by circledump::dump_sub_graph(), circlechef::generate_recipe(), circlechef::set_inputs(), circlechef::set_outputs(), and mio::circle::Reader::tensor_name().

◆ tensor_type()

const char * mio::circle::tensor_type ( const ::circle::Tensor *  tensor)

Definition at line 64 of file Helper.cpp.

65{
66 return ::circle::EnumNameTensorType(tensor->type());
67}

Referenced by circledump::dump_sub_graph(), and mio::circle::Reader::tensor_dtype().