ONE - On-device Neural Engine
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
onert::backend::cl_common Namespace Reference

Data Structures

class  BackendContext
 
struct  ParentInfo
 Struct to represent parent operand in child operand. More...
 

Typedefs

using LifetimeMap = std::map< size_t, std::pair< UsesType, ir::OperandIndex > >
 
using LifetimeSeq = std::vector< std::pair< UsesType, ir::OperandIndex > >
 

Enumerations

enum class  UsesType { FIRST , LAST }
 

Functions

LifetimeMap createLifetimeMap (LifetimeSeq &seq, ir::OperandIndexMap< ParentInfo > &parent_map)
 

Typedef Documentation

◆ LifetimeMap

using onert::backend::cl_common::LifetimeMap = typedef std::map<size_t, std::pair<UsesType, ir::OperandIndex> >

Definition at line 38 of file LifetimeMap.h.

◆ LifetimeSeq

using onert::backend::cl_common::LifetimeSeq = typedef std::vector<std::pair<UsesType, ir::OperandIndex> >

Definition at line 39 of file LifetimeMap.h.

Enumeration Type Documentation

◆ UsesType

Enumerator
FIRST 
LAST 

Definition at line 31 of file LifetimeMap.h.

Function Documentation

◆ createLifetimeMap()

LifetimeMap onert::backend::cl_common::createLifetimeMap ( LifetimeSeq seq,
ir::OperandIndexMap< ParentInfo > &  parent_map 
)

Definition at line 24 of file LifetimeMap.cc.

26{
27 // Update lifetime sequence to apply subtensor optimization
28 std::unordered_map<ir::OperandIndex, ir::OperandIndex> root_map;
29 std::function<ir::OperandIndex &(ir::OperandIndex)> find_root =
31 ir::OperandIndex &ret = root_map[ind];
32
33 // We know the root parent value already
34 if (ret.valid())
35 return ret;
36
37 auto itr = parent_map.find(ind);
38 if (itr == parent_map.end())
39 {
40 // If there is no parent, let's store the value of itself
41 return ret = ind;
42 }
43 else
44 {
45 return ret = find_root(itr->second.parent);
46 }
47 };
48
49 ir::OperandIndexMap<bool> first_use_check;
50 ir::OperandIndexMap<bool> last_use_check;
51 LifetimeMap lifetime_map;
52 for (size_t i = 0; i < lifetime_seq.size(); i++)
53 {
54 const auto &[entry_uses_type, entry_idx] = lifetime_seq[i];
55 if (entry_uses_type != UsesType::FIRST)
56 continue;
57 auto root_ind = find_root(entry_idx);
58 if (first_use_check[root_ind])
59 continue;
60 first_use_check[root_ind] = true;
61 lifetime_map[i] = {UsesType::FIRST, root_ind};
62 }
63
64 for (int i = lifetime_seq.size() - 1; i >= 0; i--)
65 {
66 const auto &[entry_uses_type, entry_idx] = lifetime_seq[i];
67 if (entry_uses_type != UsesType::LAST)
68 continue;
69 auto root_ind = find_root(entry_idx);
70 if (last_use_check[root_ind])
71 continue;
72 last_use_check[root_ind] = true;
73 lifetime_map[i] = {UsesType::LAST, root_ind};
74 }
75
76 return lifetime_map;
77}
bool valid() const
Check whether the value is valid or not.
Definition Index.h:125

References FIRST, LAST, and onert::util::Index< T, DummyTag >::valid().

Referenced by onert::backend::acl_common::AclTensorBuilder< T_ITensor, T_Tensor, T_SubTensor >::allocate().