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

GraphBuilder for Constant(since version 9) 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 9) node.

Note
Until version 1, only FLOAT16, FLOAT, DOUBLE was supported Since version 9, all types are supported

Definition at line 41 of file Constant.h.

Member Function Documentation

◆ build()

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

Definition at line 35 of file Constant_V9.cpp.

36{
37 assert(context != nullptr);
38
39 loco::Graph *graph = context->graph();
40 SymbolTable *nodes = context->nodes();
41
42 // Create a "ConstGen" node for Constant
43 auto const_node = graph->nodes()->create<loco::ConstGen>();
44 auto tensor_attribute = node.attribute().Get(0).t();
45 const_node->dtype(as_loco_datatype(tensor_attribute.data_type()));
46 const_node->rank(tensor_attribute.dims_size());
47 // TODO Support other data types
48 assert(const_node->dtype() == loco::DataType::FLOAT32);
49 const_node->size<loco::DataType::FLOAT32>(tensor_attribute.float_data_size());
50
51 for (uint32_t i = 0; i < const_node->rank(); ++i)
52 {
53 const_node->dim(i) = tensor_attribute.dims(i);
54 }
55
56 // TODO Support other data types
57 for (int i = 0; i < tensor_attribute.float_data_size(); ++i)
58 {
59 const_node->at<loco::DataType::FLOAT32>(i) = tensor_attribute.float_data(i);
60 }
61
62 nodes->enroll(node.name(), const_node);
63 nodes->enroll(node.output(0), const_node);
64}
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_V9::validate ( const ::onnx::NodeProto &  node) const

Definition at line 27 of file Constant_V9.cpp.

28{
29 if (node.attribute_size() == 0 || !node.attribute(0).has_t())
30 return false;
31
32 return true;
33}

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


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