ONE - On-device Neural Engine
Loading...
Searching...
No Matches
onert::compiler::pass::PermutationInsertionPass Class Reference

#include <PermutationInsertionPass.h>

Collaboration diagram for onert::compiler::pass::PermutationInsertionPass:

Public Member Functions

std::string id () override
 
void callback (const ir::OperandIndex &index, ir::Operand &object) override
 
 LoweredOperandPass (compiler::ILoweredGraph &lowered_graph)
 
- Public Member Functions inherited from onert::compiler::pass::LoweredOperandPass
 LoweredOperandPass (compiler::ILoweredGraph &lowered_graph)
 
virtual ~LoweredOperandPass ()=default
 
- 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::LoweredOperandPass
compiler::ILoweredGraph_lowered_graph
 
- Protected Attributes inherited from onert::compiler::pass::Pass
ir::Graph_graph
 

Detailed Description

Definition at line 31 of file PermutationInsertionPass.h.

Member Function Documentation

◆ callback()

void onert::compiler::pass::PermutationInsertionPass::callback ( const ir::OperandIndex index,
ir::Operand object 
)
overridevirtual

Implements onert::compiler::pass::LoweredOperandPass.

Definition at line 37 of file PermutationInsertionPass.cc.

38{
39 auto &operand_li_map = _lowered_graph.lower_info().operand;
40 auto &&operand_li = operand_li_map.getRawPtr(index);
41 assert(operand_li);
42
43 // NOTE Later, constants also will have Def
44 // Ignore constants
45 if (operand_li->def_backends().size() == 0)
46 {
47 return;
48 }
49
50 std::list<ir::OperationIndex> permute_indexes;
51
52 // Build a map for all necessary type of operands
53 std::unordered_map<const backend::Backend *, ir::OperandIndex> backend_to_index;
54 {
55 assert(operand_li->def_backends().size() == 1);
56 for (auto &&backend : operand_li->def_backends())
57 {
58 backend_to_index.emplace(backend, index);
59 }
60
61 auto insert_set = operand_li->use_backends() - operand_li->def_backends();
62 for (auto &&backend : insert_set)
63 {
64 const auto permute_operation_index = insertPermute(index, backend);
65 permute_indexes.push_back(permute_operation_index);
66 const auto &permute_operation = _graph.operations().at(permute_operation_index);
67 const auto permuted_operand_index = permute_operation.getOutputs().at(0);
68 backend_to_index.emplace(backend, permuted_operand_index);
69 }
70 }
71
72 // Update operations' input that uses this operand
73 {
74 std::list<ir::OperationIndex> remove_list;
75
76 auto uses = object.getUses();
77 for (auto &&use : uses)
78 {
79 // If permute operation, ignore it
80 if (std::find(permute_indexes.begin(), permute_indexes.end(), use) != permute_indexes.end())
81 continue;
82
83 auto &operation = _graph.operations().at(use);
84 const auto backend = _lowered_graph.lower_info().operation.at(use);
85 assert(backend);
86 assert(operation.getInputs().contains(index));
87
88 auto new_index = backend_to_index.at(backend);
89 if (index != new_index)
90 {
91 // Update from operation
92 // Replace the same inputs of an operation at once for the following reasons:
93 // No. 2 and 3 above
94 operation.replaceInputs(index, new_index);
95
96 // Update from operand
97 remove_list.push_back(
98 use); // Removal should be done in another loop since we are in the loop
99 _graph.operands().at(new_index).insertUse(use);
100 }
101 }
102
103 for (const auto &operation_index : remove_list)
104 {
105 object.removeUse(operation_index);
106 }
107 }
108}
const Operands & operands() const override
Definition Graph.h:112
const Operations & operations() const override
Definition Graph.h:114
const Object & at(const Index &index) const
Get the object that is associated with the given index.
std::unordered_map< ir::OperationIndex, const backend::Backend * > operation
util::ObjectManager< ir::OperandIndex, OperandLowerInfo > operand
virtual const compiler::GraphLowerInfo & lower_info() const =0

References onert::compiler::pass::Pass::_graph, onert::compiler::pass::LoweredOperandPass::_lowered_graph, onert::util::ObjectManager< Index, Object >::at(), onert::compiler::ILoweredGraph::lower_info(), onert::compiler::GraphLowerInfo::operand, onert::ir::Graph::operands(), onert::compiler::GraphLowerInfo::operation, and onert::ir::Graph::operations().

◆ id()

std::string onert::compiler::pass::PermutationInsertionPass::id ( )
inlineoverridevirtual

Implements onert::compiler::pass::LoweredOperandPass.

Definition at line 37 of file PermutationInsertionPass.h.

37{ return "PermutationInsertionPass"; }

◆ LoweredOperandPass()

onert::compiler::pass::LoweredOperandPass::LoweredOperandPass ( compiler::ILoweredGraph lowered_graph)
inline

Definition at line 33 of file LoweredOperandPass.h.

34 : OperandPass{lowered_graph.graph()}, _lowered_graph{lowered_graph}
35 {
36 // DO NOTHING
37 }

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