ONE - On-device Neural Engine
Loading...
Searching...
No Matches
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 47 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 30 of file ConstantOutputPass.cc.

31{
32 if (!_graph.getOutputs().contains(ind) || !obj.isConstant())
33 return;
34
35 auto permute_input_ind = _graph.addOperand(obj.shape(), obj.typeInfo());
36 auto &permute_input_obj = _graph.operands().at(permute_input_ind);
37
38 // Move the const data
39 permute_input_obj.data(obj.shareData());
40 obj.releaseData();
41 obj.info().setAsNonConst();
42
43 using ir::operation::Permute;
44 auto permute_obj = std::make_unique<Permute>(permute_input_ind, ind);
45 auto permute_ind = _graph.operations().push(std::move(permute_obj));
46
47 permute_input_obj.insertUse(permute_ind);
48 obj.setDef(permute_ind);
49
50 // Make the operations that uses this operand to use the generated operand
51 auto orig_uses = obj.getUses();
52 for (auto &&use : orig_uses)
53 {
54 permute_input_obj.insertUse(use);
55 obj.removeUse(use);
56 _graph.operations().at(use).replaceInputs(ind, permute_input_ind);
57 }
58
59 VERBOSE(ConstantOutputPass) << "Permute Op inserted for a constant ouput, node index : "
60 << permute_ind << std::endl;
61 VERBOSE(ConstantOutputPass) << " - Input (inserted) Operand : " << permute_input_ind
62 << std::endl;
63 VERBOSE(ConstantOutputPass) << " - Output(original) Operand : " << ind << std::endl;
64}
OperandIndex addOperand(const Shape &shape, const TypeInfo &type)
Definition Graph.cc:35
const Operands & operands() const override
Definition Graph.h:112
const Operations & operations() const override
Definition Graph.h:114
const OperandIndexSequence & getOutputs() const override
Definition Graph.h:108
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 53 of file ConstantOutputPass.h.

53{ return "ConstantOutputPass"; }

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