ArmNN
 20.05
NeonTensorHandleFactory.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
7 #include "NeonTensorHandle.hpp"
8 
11 
12 namespace armnn
13 {
14 
16 
17 std::unique_ptr<ITensorHandle> NeonTensorHandleFactory::CreateSubTensorHandle(ITensorHandle& parent,
18  const TensorShape& subTensorShape,
19  const unsigned int* subTensorOrigin)
20  const
21 {
22  const arm_compute::TensorShape shape = armcomputetensorutils::BuildArmComputeTensorShape(subTensorShape);
23 
25  coords.set_num_dimensions(subTensorShape.GetNumDimensions());
26  for (unsigned int i = 0; i < subTensorShape.GetNumDimensions(); ++i)
27  {
28  // Arm compute indexes tensor coords in reverse order.
29  unsigned int revertedIndex = subTensorShape.GetNumDimensions() - i - 1;
30  coords.set(i, boost::numeric_cast<int>(subTensorOrigin[revertedIndex]));
31  }
32 
33  const arm_compute::TensorShape parentShape = armcomputetensorutils::BuildArmComputeTensorShape(parent.GetShape());
34  if (!::arm_compute::error_on_invalid_subtensor(__func__, __FILE__, __LINE__, parentShape, coords, shape))
35  {
36  return nullptr;
37  }
38 
39  return std::make_unique<NeonSubTensorHandle>(
40  PolymorphicDowncast<IAclTensorHandle*>(&parent), shape, coords);
41 }
42 
43 std::unique_ptr<ITensorHandle> NeonTensorHandleFactory::CreateTensorHandle(const TensorInfo& tensorInfo) const
44 {
45  return NeonTensorHandleFactory::CreateTensorHandle(tensorInfo, true);
46 }
47 
48 std::unique_ptr<ITensorHandle> NeonTensorHandleFactory::CreateTensorHandle(const TensorInfo& tensorInfo,
49  DataLayout dataLayout) const
50 {
51  return NeonTensorHandleFactory::CreateTensorHandle(tensorInfo, dataLayout, true);
52 }
53 
54 std::unique_ptr<ITensorHandle> NeonTensorHandleFactory::CreateTensorHandle(const TensorInfo& tensorInfo,
55  const bool IsMemoryManaged) const
56 {
57  auto tensorHandle = std::make_unique<NeonTensorHandle>(tensorInfo);
58  if (IsMemoryManaged)
59  {
60  tensorHandle->SetMemoryGroup(m_MemoryManager->GetInterLayerMemoryGroup());
61  }
62  // If we are not Managing the Memory then we must be importing
63  tensorHandle->SetImportEnabledFlag(!IsMemoryManaged);
64  tensorHandle->SetImportFlags(GetImportFlags());
65 
66  return tensorHandle;
67 }
68 
69 std::unique_ptr<ITensorHandle> NeonTensorHandleFactory::CreateTensorHandle(const TensorInfo& tensorInfo,
70  DataLayout dataLayout,
71  const bool IsMemoryManaged) const
72 {
73  auto tensorHandle = std::make_unique<NeonTensorHandle>(tensorInfo, dataLayout);
74  if (IsMemoryManaged)
75  {
76  tensorHandle->SetMemoryGroup(m_MemoryManager->GetInterLayerMemoryGroup());
77  }
78  // If we are not Managing the Memory then we must be importing
79  tensorHandle->SetImportEnabledFlag(!IsMemoryManaged);
80  tensorHandle->SetImportFlags(GetImportFlags());
81 
82  return tensorHandle;
83 }
84 
86 {
87  static const FactoryId s_Id(NeonTensorHandleFactoryId());
88  return s_Id;
89 }
90 
92 {
93  return GetIdStatic();
94 }
95 
97 {
98  return true;
99 }
100 
102 {
103  return 0;
104 }
105 
107 {
108  return 0;
109 }
110 
111 } // namespace armnn
DataLayout
Definition: Types.hpp:49
MemorySourceFlags GetImportFlags() const override
std::unique_ptr< ITensorHandle > CreateTensorHandle(const TensorInfo &tensorInfo) const override
std::array< unsigned int, MaxNumOfTensorDimensions > Coordinates
unsigned int MemorySourceFlags
Copyright (c) 2020 ARM Limited.
const FactoryId & GetId() const override
MemorySourceFlags GetExportFlags() const override
ITensorHandleFactory::FactoryId FactoryId
constexpr const char * NeonTensorHandleFactoryId()
virtual TensorShape GetShape() const =0
Get the number of elements for each dimension ordered from slowest iterating dimension to fastest ite...
unsigned int GetNumDimensions() const
Definition: Tensor.hpp:43
static const FactoryId & GetIdStatic()
std::unique_ptr< ITensorHandle > CreateSubTensorHandle(ITensorHandle &parent, const TensorShape &subTensorShape, const unsigned int *subTensorOrigin) const override