ONE - On-device Neural Engine
Loading...
Searching...
No Matches
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 42 of file LifetimeMap.h.

◆ LifetimeSeq

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

Definition at line 43 of file LifetimeMap.h.

Enumeration Type Documentation

◆ UsesType

Enumerator
FIRST 
LAST 

Definition at line 35 of file LifetimeMap.h.

Function Documentation

◆ createLifetimeMap()

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

Definition at line 28 of file LifetimeMap.cc.

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

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

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