ONE - On-device Neural Engine
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
onert::compiler::pass::ConstantOutputPass Class Reference

Pass to specially handle constant model outputs. More...

#include <ConstantOutputPass.h>

Collaboration diagram for onert::compiler::pass::ConstantOutputPass:

Public Member Functions

std::string id () final
 
void callback (const ir::OperandIndex &i, ir::Operand &o) final
 
- Public Member Functions inherited from onert::compiler::pass::OperandPass
virtual ~OperandPass ()=default
 
void run () override final
 
 Pass (ir::Graph &graph)
 
- Public Member Functions inherited from onert::compiler::pass::Pass
 Pass (ir::Graph &graph)
 
virtual ~Pass ()=default
 
- Public Member Functions inherited from onert::compiler::pass::IPass
virtual ~IPass ()=default
 

Additional Inherited Members

- Protected Attributes inherited from onert::compiler::pass::Pass
ir::Graph_graph
 

Detailed Description

Pass to specially handle constant model outputs.

As an output buffer is given right before an execution but constant initialization is done at prepare phase, the current runtime structure cannot handle when an output is constant. To resolve this problem, this pass inserts a Permute layer with a const input and make the model output tensor to be its output.

e.g.)

((Const Output))

becomes

(Const) -> [Permute] -> ((Output))

Note that this is a mandatory pass for Graph.

Definition at line 43 of file ConstantOutputPass.h.

Member Function Documentation

◆ callback()

void onert::compiler::pass::ConstantOutputPass::callback ( const ir::OperandIndex i,
ir::Operand o 
)
finalvirtual

Implements onert::compiler::pass::OperandPass.

Definition at line 26 of file ConstantOutputPass.cc.

27{
28 if (!_graph.getOutputs().contains(ind) || !obj.isConstant())
29 return;
30
31 auto permute_input_ind = _graph.addOperand(obj.shape(), obj.typeInfo());
32 auto &permute_input_obj = _graph.operands().at(permute_input_ind);
33
34 // Move the const data
35 permute_input_obj.data(obj.shareData());
36 obj.releaseData();
37 obj.info().setAsNonConst();
38
39 using ir::operation::Permute;
40 auto permute_obj = std::make_unique<Permute>(permute_input_ind, ind);
41 auto permute_ind = _graph.operations().push(std::move(permute_obj));
42
43 permute_input_obj.insertUse(permute_ind);
44 obj.setDef(permute_ind);
45
46 // Make the operations that uses this operand to use the generated operand
47 auto orig_uses = obj.getUses();
48 for (auto &&use : orig_uses)
49 {
50 permute_input_obj.insertUse(use);
51 obj.removeUse(use);
52 _graph.operations().at(use).replaceInputs(ind, permute_input_ind);
53 }
54
55 VERBOSE(ConstantOutputPass) << "Permute Op inserted for a constant ouput, node index : "
56 << permute_ind << std::endl;
57 VERBOSE(ConstantOutputPass) << " - Input (inserted) Operand : " << permute_input_ind
58 << std::endl;
59 VERBOSE(ConstantOutputPass) << " - Output(original) Operand : " << ind << std::endl;
60}
OperandIndex addOperand(const Shape &shape, const TypeInfo &type)
Definition Graph.cc:33
const Operands & operands() const override
Definition Graph.h:110
const Operations & operations() const override
Definition Graph.h:112
const OperandIndexSequence & getOutputs() const override
Definition Graph.h:106
bool contains(const OperandIndex &index) const
Index push(std::unique_ptr< Object > &&object, Index index)
Put the object in the container with given index.
const Object & at(const Index &index) const
Get the object that is associated with the given index.
#define VERBOSE(name, lv)
Definition Log.h:71

References onert::compiler::pass::Pass::_graph, onert::ir::Graph::addOperand(), onert::util::ObjectManager< Index, Object >::at(), onert::ir::OperandIndexSequence::contains(), onert::ir::Graph::getOutputs(), onert::ir::Graph::operands(), onert::ir::Graph::operations(), onert::util::ObjectManager< Index, Object >::push(), and VERBOSE.

◆ id()

std::string onert::compiler::pass::ConstantOutputPass::id ( )
inlinefinalvirtual

Implements onert::compiler::pass::OperandPass.

Definition at line 49 of file ConstantOutputPass.h.

49{ return "ConstantOutputPass"; }

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