ArmNN
 24.02
ClTensorHandleFactory.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 "ClTensorHandle.hpp"
8 
11 
12 #include <arm_compute/core/Coordinates.h>
13 #include <arm_compute/runtime/CL/CLSubTensor.h>
14 #include <arm_compute/runtime/CL/CLTensor.h>
15 
16 namespace armnn
17 {
18 
20 
21 std::unique_ptr<ITensorHandle> ClTensorHandleFactory::CreateSubTensorHandle(ITensorHandle& parent,
22  const TensorShape& subTensorShape,
23  const unsigned int* subTensorOrigin) const
24 {
26  arm_compute::TensorShape shape = armcomputetensorutils::BuildArmComputeTensorShape(subTensorShape);
27 
28  coords.set_num_dimensions(subTensorShape.GetNumDimensions());
29  for (unsigned int i = 0; i < subTensorShape.GetNumDimensions(); ++i)
30  {
31  // Arm compute indexes tensor coords in reverse order.
32  unsigned int revertedIndex = subTensorShape.GetNumDimensions() - i - 1;
33  coords.set(i, armnn::numeric_cast<int>(subTensorOrigin[revertedIndex]));
34  }
35 
36  const arm_compute::TensorShape parentShape = armcomputetensorutils::BuildArmComputeTensorShape(parent.GetShape());
37 
38  // In order for ACL to support subtensors the concat axis cannot be on x or y and the values of x and y
39  // must match the parent shapes
40  if (coords.x() != 0 || coords.y() != 0)
41  {
42  return nullptr;
43  }
44  if ((parentShape.x() != shape.x()) || (parentShape.y() != shape.y()))
45  {
46  return nullptr;
47  }
48 
49  if (!::arm_compute::error_on_invalid_subtensor(__func__, __FILE__, __LINE__, parentShape, coords, shape))
50  {
51  return nullptr;
52  }
53 
54  return std::make_unique<ClSubTensorHandle>(PolymorphicDowncast<IClTensorHandle*>(&parent), shape, coords);
55 }
56 
57 std::unique_ptr<ITensorHandle> ClTensorHandleFactory::CreateTensorHandle(const TensorInfo& tensorInfo) const
58 {
59  return ClTensorHandleFactory::CreateTensorHandle(tensorInfo, true);
60 }
61 
62 std::unique_ptr<ITensorHandle> ClTensorHandleFactory::CreateTensorHandle(const TensorInfo& tensorInfo,
63  DataLayout dataLayout) const
64 {
65  return ClTensorHandleFactory::CreateTensorHandle(tensorInfo, dataLayout, true);
66 }
67 
68 std::unique_ptr<ITensorHandle> ClTensorHandleFactory::CreateTensorHandle(const TensorInfo& tensorInfo,
69  const bool IsMemoryManaged) const
70 {
71  std::unique_ptr<ClTensorHandle> tensorHandle = std::make_unique<ClTensorHandle>(tensorInfo);
72  if (!IsMemoryManaged)
73  {
74  ARMNN_LOG(warning) << "ClTensorHandleFactory only has support for memory managed.";
75  }
76  tensorHandle->SetMemoryGroup(m_MemoryManager->GetInterLayerMemoryGroup());
77  return tensorHandle;
78 }
79 
80 std::unique_ptr<ITensorHandle> ClTensorHandleFactory::CreateTensorHandle(const TensorInfo& tensorInfo,
81  DataLayout dataLayout,
82  const bool IsMemoryManaged) const
83 {
84  std::unique_ptr<ClTensorHandle> tensorHandle = std::make_unique<ClTensorHandle>(tensorInfo, dataLayout);
85  if (!IsMemoryManaged)
86  {
87  ARMNN_LOG(warning) << "ClTensorHandleFactory only has support for memory managed.";
88  }
89  tensorHandle->SetMemoryGroup(m_MemoryManager->GetInterLayerMemoryGroup());
90  return tensorHandle;
91 }
92 
94 {
95  static const FactoryId s_Id(ClTensorHandleFactoryId());
96  return s_Id;
97 }
98 
100 {
101  return GetIdStatic();
102 }
103 
105 {
106  return false;
107 }
108 
110 {
112 }
113 
115 {
117 }
118 
119 } // namespace armnn
armnn::ClTensorHandleFactoryId
constexpr const char * ClTensorHandleFactoryId()
Definition: ClTensorHandleFactory.hpp:15
armnn::ClTensorHandleFactory::SupportsSubTensors
bool SupportsSubTensors() const override
Definition: ClTensorHandleFactory.cpp:104
armnn::ClTensorHandleFactory::GetImportFlags
MemorySourceFlags GetImportFlags() const override
Definition: ClTensorHandleFactory.cpp:114
armnn::DataLayout
DataLayout
Definition: Types.hpp:62
armnn::ClTensorHandleFactory::GetIdStatic
static const FactoryId & GetIdStatic()
Definition: ClTensorHandleFactory.cpp:93
armnn::TensorInfo
Definition: Tensor.hpp:152
armnn::ClTensorHandleFactory::GetExportFlags
MemorySourceFlags GetExportFlags() const override
Definition: ClTensorHandleFactory.cpp:109
armnn::MemorySourceFlags
unsigned int MemorySourceFlags
Definition: MemorySources.hpp:15
ClTensorHandleFactory.hpp
armnn::ITensorHandle
Definition: ITensorHandle.hpp:16
armnn::ClTensorHandleFactory::CreateTensorHandle
std::unique_ptr< ITensorHandle > CreateTensorHandle(const TensorInfo &tensorInfo) const override
Definition: ClTensorHandleFactory.cpp:57
armnn::ITensorHandle::GetShape
virtual TensorShape GetShape() const =0
Get the number of elements for each dimension ordered from slowest iterating dimension to fastest ite...
armnn::Coordinates
std::array< unsigned int, MaxNumOfTensorDimensions > Coordinates
Definition: InternalTypes.hpp:15
armnn::ClTensorHandleFactory::CreateSubTensorHandle
std::unique_ptr< ITensorHandle > CreateSubTensorHandle(ITensorHandle &parent, const TensorShape &subTensorShape, const unsigned int *subTensorOrigin) const override
Definition: ClTensorHandleFactory.cpp:21
NumericCast.hpp
ARMNN_LOG
#define ARMNN_LOG(severity)
Definition: Logging.hpp:212
armnn::ClTensorHandleFactory::GetId
const FactoryId & GetId() const override
Definition: ClTensorHandleFactory.cpp:99
armnn::TensorShape
Definition: Tensor.hpp:20
armnn::TensorShape::GetNumDimensions
unsigned int GetNumDimensions() const
Function that returns the tensor rank.
Definition: Tensor.cpp:174
armnn::FactoryId
ITensorHandleFactory::FactoryId FactoryId
Definition: MockTensorHandleFactory.cpp:12
armnn::MemorySource::Undefined
@ Undefined
PolymorphicDowncast.hpp
ClTensorHandle.hpp
armnn
Copyright (c) 2021 ARM Limited and Contributors.
Definition: 01_00_quick_start.dox:6
armnn::ITensorHandleFactory::FactoryId
std::string FactoryId
Definition: ITensorHandleFactory.hpp:49
armnn::BoostLogSeverityMapping::warning
@ warning