ArmNN
 20.02
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 
10 
11 namespace armnn
12 {
13 
15 
16 std::unique_ptr<ITensorHandle> NeonTensorHandleFactory::CreateSubTensorHandle(ITensorHandle& parent,
17  const TensorShape& subTensorShape,
18  const unsigned int* subTensorOrigin)
19  const
20 {
21  const arm_compute::TensorShape shape = armcomputetensorutils::BuildArmComputeTensorShape(subTensorShape);
22 
24  coords.set_num_dimensions(subTensorShape.GetNumDimensions());
25  for (unsigned int i = 0; i < subTensorShape.GetNumDimensions(); ++i)
26  {
27  // Arm compute indexes tensor coords in reverse order.
28  unsigned int revertedIndex = subTensorShape.GetNumDimensions() - i - 1;
29  coords.set(i, boost::numeric_cast<int>(subTensorOrigin[revertedIndex]));
30  }
31 
32  const arm_compute::TensorShape parentShape = armcomputetensorutils::BuildArmComputeTensorShape(parent.GetShape());
33  if (!::arm_compute::error_on_invalid_subtensor(__func__, __FILE__, __LINE__, parentShape, coords, shape))
34  {
35  return nullptr;
36  }
37 
38  return std::make_unique<NeonSubTensorHandle>(
39  boost::polymorphic_downcast<IAclTensorHandle*>(&parent), shape, coords);
40 }
41 
42 std::unique_ptr<ITensorHandle> NeonTensorHandleFactory::CreateTensorHandle(const TensorInfo& tensorInfo) const
43 {
44  return NeonTensorHandleFactory::CreateTensorHandle(tensorInfo, true);
45 }
46 
47 std::unique_ptr<ITensorHandle> NeonTensorHandleFactory::CreateTensorHandle(const TensorInfo& tensorInfo,
48  DataLayout dataLayout) const
49 {
50  return NeonTensorHandleFactory::CreateTensorHandle(tensorInfo, dataLayout, true);
51 }
52 
53 std::unique_ptr<ITensorHandle> NeonTensorHandleFactory::CreateTensorHandle(const TensorInfo& tensorInfo,
54  const bool IsMemoryManaged) const
55 {
56  auto tensorHandle = std::make_unique<NeonTensorHandle>(tensorInfo);
57  if (IsMemoryManaged)
58  {
59  tensorHandle->SetMemoryGroup(m_MemoryManager->GetInterLayerMemoryGroup());
60  }
61  // If we are not Managing the Memory then we must be importing
62  tensorHandle->SetImportEnabledFlag(!IsMemoryManaged);
63  tensorHandle->SetImportFlags(GetImportFlags());
64 
65  return tensorHandle;
66 }
67 
68 std::unique_ptr<ITensorHandle> NeonTensorHandleFactory::CreateTensorHandle(const TensorInfo& tensorInfo,
69  DataLayout dataLayout,
70  const bool IsMemoryManaged) const
71 {
72  auto tensorHandle = std::make_unique<NeonTensorHandle>(tensorInfo, dataLayout);
73  if (IsMemoryManaged)
74  {
75  tensorHandle->SetMemoryGroup(m_MemoryManager->GetInterLayerMemoryGroup());
76  }
77  // If we are not Managing the Memory then we must be importing
78  tensorHandle->SetImportEnabledFlag(!IsMemoryManaged);
79  tensorHandle->SetImportFlags(GetImportFlags());
80 
81  return tensorHandle;
82 }
83 
85 {
86  static const FactoryId s_Id(NeonTensorHandleFactoryId());
87  return s_Id;
88 }
89 
91 {
92  return GetIdStatic();
93 }
94 
96 {
97  return true;
98 }
99 
101 {
102  return 0;
103 }
104 
106 {
107  return 0;
108 }
109 
110 } // 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