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