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

Pass to specially handle odd outputs in a subgraph. More...

#include <OddOutputPass.h>

Collaboration diagram for onert::compiler::pass::OddOutputPass:

Public Member Functions

std::string id () final
 
void run () override
 
 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 odd outputs in a subgraph.

Runtime Graph IR requires every input or output must have distinct tensor index, this is onert's restriction. However we allow duplication of indices in the models(or API). So we should transform the graph after model-loading.

This is necessary since our API lets users to set different buffers for each input and output so it is unavoidable that we must copy the value at runtime.

Note that this is a mandatory pass for Graph.

Case 1 : An operand which is a model output and a model input

Create an operand and insert a Permute(copy) op between them. And change the output to be the newly generated operand.

e.g.)

((#0 Input0 and also Output0))
becomes
((#0 Input0)) -> [#0 Permute] -> ((#1 Output0))

Case 2 : Two or more duplicated outputs

Do the same with Case 1, but between two outputs of the same tensor index.

e.g.)

((#0 Input0)) -> [#0 Some Operation] -> ((#1 Output0 and also Output1))
becomes
((#0 Input0)) -> [#0 Some Operation] -> ((#1 Output0)) [#1 Permute] -> ((#2 Output1))

Definition at line 66 of file OddOutputPass.h.

Member Function Documentation

◆ id()

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

Implements onert::compiler::pass::Pass.

Definition at line 72 of file OddOutputPass.h.

72{ return "OddOutputPass"; }

◆ Pass()

onert::compiler::pass::Pass::Pass ( ir::Graph graph)
inline

Definition at line 35 of file Pass.h.

◆ run()

void onert::compiler::pass::OddOutputPass::run ( )
overridevirtual

Implements onert::compiler::pass::Pass.

Definition at line 26 of file OddOutputPass.cc.

27{
28 auto &outputs = _graph.getOutputs();
29
30 VERBOSE(OddOutputPass) << "Case 1 : An operand which is a model output and a model input"
31 << std::endl;
32 for (const auto &ind : outputs)
33 {
34 if (_graph.getInputs().contains(ind))
35 {
36 auto permute_output_ind = insertPermute(ind);
37 // Update the output to be newly added operand
38 _graph.getOutputs().replace(ind, permute_output_ind);
39 }
40 }
41
42 VERBOSE(OddOutputPass) << "Case 2 : Two or more duplicated outputs" << std::endl;
43 std::unordered_set<ir::OperandIndex> occurence;
44 for (auto &&ind : outputs)
45 {
46 if (occurence.count(ind) == 0)
47 {
48 occurence.insert(ind);
49 continue;
50 }
51
52 // Panic when it is const, it must have been handled earlier in another pass
53 [[maybe_unused]] auto &obj = _graph.operands().at(ind);
54 assert(!obj.isConstant());
55
56 auto permute_output_ind = insertPermute(ind);
57 ind = permute_output_ind; // Replace output index to fix output duplication
58 }
59}
const Operands & operands() const override
Definition Graph.h:110
const OperandIndexSequence & getInputs() const override
Definition Graph.h:104
const OperandIndexSequence & getOutputs() const override
Definition Graph.h:106
bool contains(const OperandIndex &index) const
void replace(const OperandIndex &from, const OperandIndex &to)
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::util::ObjectManager< Index, Object >::at(), onert::ir::OperandIndexSequence::contains(), onert::ir::Graph::getInputs(), onert::ir::Graph::getOutputs(), onert::ir::Graph::operands(), onert::ir::OperandIndexSequence::replace(), and VERBOSE.


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