ArmNN
 20.05
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 
6 
8 #include "ClTensorHandle.hpp"
9 
11 
12 #include <arm_compute/runtime/CL/CLTensor.h>
13 #include <arm_compute/core/Coordinates.h>
14 #include <arm_compute/runtime/CL/CLSubTensor.h>
15 
16 
17 namespace armnn
18 {
19 
21 
22 std::unique_ptr<ITensorHandle> ClTensorHandleFactory::CreateSubTensorHandle(ITensorHandle& parent,
23  const TensorShape& subTensorShape,
24  const unsigned int* subTensorOrigin) const
25 {
27  arm_compute::TensorShape shape = armcomputetensorutils::BuildArmComputeTensorShape(subTensorShape);
28 
29  coords.set_num_dimensions(subTensorShape.GetNumDimensions());
30  for (unsigned int i = 0; i < subTensorShape.GetNumDimensions(); ++i)
31  {
32  // Arm compute indexes tensor coords in reverse order.
33  unsigned int revertedIndex = subTensorShape.GetNumDimensions() - i - 1;
34  coords.set(i, boost::numeric_cast<int>(subTensorOrigin[revertedIndex]));
35  }
36 
37  const arm_compute::TensorShape parentShape = armcomputetensorutils::BuildArmComputeTensorShape(
38  parent.GetShape());
39  if (!::arm_compute::error_on_invalid_subtensor(__func__, __FILE__, __LINE__, parentShape, coords, shape))
40  {
41  return nullptr;
42  }
43 
44  return std::make_unique<ClSubTensorHandle>(
45  PolymorphicDowncast<IClTensorHandle *>(&parent), shape, coords);
46 }
47 
48 std::unique_ptr<ITensorHandle> ClTensorHandleFactory::CreateTensorHandle(const TensorInfo& tensorInfo) const
49 {
50  return ClTensorHandleFactory::CreateTensorHandle(tensorInfo, true);
51 }
52 
53 std::unique_ptr<ITensorHandle> ClTensorHandleFactory::CreateTensorHandle(const TensorInfo& tensorInfo,
54  DataLayout dataLayout) const
55 {
56  return ClTensorHandleFactory::CreateTensorHandle(tensorInfo, dataLayout, true);
57 }
58 
59 std::unique_ptr<ITensorHandle> ClTensorHandleFactory::CreateTensorHandle(const TensorInfo& tensorInfo,
60  const bool IsMemoryManaged) const
61 {
62  std::unique_ptr<ClTensorHandle> tensorHandle = std::make_unique<ClTensorHandle>(tensorInfo);
63  if (IsMemoryManaged)
64  {
65  tensorHandle->SetMemoryGroup(m_MemoryManager->GetInterLayerMemoryGroup());
66  }
67  return tensorHandle;
68 }
69 
70 std::unique_ptr<ITensorHandle> ClTensorHandleFactory::CreateTensorHandle(const TensorInfo& tensorInfo,
71  DataLayout dataLayout,
72  const bool IsMemoryManaged) const
73 {
74  std::unique_ptr<ClTensorHandle> tensorHandle = std::make_unique<ClTensorHandle>(tensorInfo, dataLayout);
75  if (IsMemoryManaged)
76  {
77  tensorHandle->SetMemoryGroup(m_MemoryManager->GetInterLayerMemoryGroup());
78  }
79  return tensorHandle;
80 }
81 
83 {
84  static const FactoryId s_Id(ClTensorHandleFactoryId());
85  return s_Id;
86 }
87 
89 {
90  return GetIdStatic();
91 }
92 
94 {
95  return true;
96 }
97 
99 {
100  return m_ExportFlags;
101 }
102 
104 {
105  return m_ImportFlags;
106 }
107 
108 } // namespace armnn
static const FactoryId & GetIdStatic()
bool SupportsSubTensors() const override
DataLayout
Definition: Types.hpp:49
MemorySourceFlags GetImportFlags() const override
std::array< unsigned int, MaxNumOfTensorDimensions > Coordinates
unsigned int MemorySourceFlags
Copyright (c) 2020 ARM Limited.
std::unique_ptr< ITensorHandle > CreateSubTensorHandle(ITensorHandle &parent, const TensorShape &subTensorShape, const unsigned int *subTensorOrigin) const override
MemorySourceFlags GetExportFlags() const override
constexpr const char * ClTensorHandleFactoryId()
ITensorHandleFactory::FactoryId FactoryId
std::unique_ptr< ITensorHandle > CreateTensorHandle(const TensorInfo &tensorInfo) const override
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
const FactoryId & GetId() const override