ONE - On-device Neural Engine
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 27 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 33 of file PermutationInsertionPass.cc.

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

33{ return "PermutationInsertionPass"; }

◆ LoweredOperandPass()

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

Definition at line 29 of file LoweredOperandPass.h.

30 : OperandPass{lowered_graph.graph()}, _lowered_graph{lowered_graph}
31 {
32 // DO NOTHING
33 }

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