ONE - On-device Neural Engine
Loading...
Searching...
No Matches
moco::onnx::Constant_V1 Class Reference

GraphBuilder for Constant(since version 1) node. More...

#include <Constant.h>

Public Member Functions

bool validate (const ::onnx::NodeProto &) const
 
void build (const ::onnx::NodeProto &, GraphBuilderContext *) const
 

Detailed Description

GraphBuilder for Constant(since version 1) node.

Definition at line 29 of file Constant.h.

Member Function Documentation

◆ build()

void moco::onnx::Constant_V1::build ( const ::onnx::NodeProto &  node,
GraphBuilderContext context 
) const

Definition at line 39 of file Constant_V1.cpp.

40{
41 assert(context != nullptr);
42
43 loco::Graph *graph = context->graph();
44 SymbolTable *nodes = context->nodes();
45
46 // Create a "ConstGen" node for Constant
47 auto const_node = graph->nodes()->create<loco::ConstGen>();
48 auto tensor_attribute = node.attribute().Get(0).t();
49 const_node->dtype(as_loco_datatype(tensor_attribute.data_type()));
50 const_node->rank(tensor_attribute.dims_size());
51 // TODO Support other data types
52 assert(const_node->dtype() == loco::DataType::FLOAT32);
53 const_node->size<loco::DataType::FLOAT32>(tensor_attribute.float_data_size());
54
55 for (uint32_t i = 0; i < const_node->rank(); ++i)
56 {
57 const_node->dim(i) = tensor_attribute.dims(i);
58 }
59
60 // TODO Support other data types
61 for (int i = 0; i < tensor_attribute.float_data_size(); ++i)
62 {
63 const_node->at<loco::DataType::FLOAT32>(i) = tensor_attribute.float_data(i);
64 }
65
66 nodes->enroll(node.name(), const_node);
67 nodes->enroll(node.output(0), const_node);
68}
Create a value from constant byte array.
Definition Nodes.h:218
const DataTypeImpl< DT >::Type & at(uint32_t n) const
Get the element at a given position @require at(n) is valid only when n < size()
Definition Nodes.cpp:198
A neural network graph.
Definition Graph.h:161
loco::DataType as_loco_datatype(const int32_t tensor_dtype)
Definition Convert.cpp:28

References moco::onnx::as_loco_datatype(), loco::ConstGen::at(), moco::onnx::SymbolTable::enroll(), moco::onnx::GraphBuilderContext::graph(), and moco::onnx::GraphBuilderContext::nodes().

Referenced by moco::onnx::ConstantGraphBuilder::build().

◆ validate()

bool moco::onnx::Constant_V1::validate ( const ::onnx::NodeProto &  node) const

Definition at line 27 of file Constant_V1.cpp.

28{
29 if (node.attribute_size() == 0 || !node.attribute(0).has_t())
30 return false;
31
32 auto type = moco::onnx::tensor_dtype_as_string(node.attribute(0).t().data_type());
33 if (type.compare("FLOAT16") != 0 && type.compare("FLOAT") != 0 && type.compare("DOUBLE") != 0)
34 return false;
35
36 return true;
37}
type
Definition infer.py:18
std::string tensor_dtype_as_string(const int32_t tensor_dtype)
Definition Convert.cpp:68

References moco::onnx::tensor_dtype_as_string().

Referenced by moco::onnx::ConstantGraphBuilder::validate().


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