blob: 80f46d2237437b17bbbac2e22625949f920f74b3 [file] [log] [blame]
Narumol Prangnawarat4e3e8182019-08-14 12:25:50 +01001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#include "NeonTensorHandleFactory.hpp"
7#include "NeonTensorHandle.hpp"
8
9#include <boost/core/ignore_unused.hpp>
10
11namespace armnn
12{
13
Jan Eilerse9f0f0f2019-08-16 10:28:37 +010014using FactoryId = ITensorHandleFactory::FactoryId;
Narumol Prangnawarat4e3e8182019-08-14 12:25:50 +010015
16std::unique_ptr<ITensorHandle> NeonTensorHandleFactory::CreateSubTensorHandle(ITensorHandle& parent,
Jan Eilerse9f0f0f2019-08-16 10:28:37 +010017 const TensorShape& subTensorShape,
18 const unsigned int* subTensorOrigin)
Narumol Prangnawarat4e3e8182019-08-14 12:25:50 +010019 const
20{
21 const arm_compute::TensorShape shape = armcomputetensorutils::BuildArmComputeTensorShape(subTensorShape);
22
23 arm_compute::Coordinates coords;
24 coords.set_num_dimensions(subTensorShape.GetNumDimensions());
Jan Eilerse9f0f0f2019-08-16 10:28:37 +010025 for (unsigned int i = 0; i < subTensorShape.GetNumDimensions(); ++i)
Narumol Prangnawarat4e3e8182019-08-14 12:25:50 +010026 {
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
David Monahanc6e5a6e2019-10-02 09:33:57 +010042std::unique_ptr<ITensorHandle> NeonTensorHandleFactory::CreateTensorHandle(const TensorInfo& tensorInfo) const
43{
44 return NeonTensorHandleFactory::CreateTensorHandle(tensorInfo, true);
45}
46
47std::unique_ptr<ITensorHandle> NeonTensorHandleFactory::CreateTensorHandle(const TensorInfo& tensorInfo,
48 DataLayout dataLayout) const
49{
50 return NeonTensorHandleFactory::CreateTensorHandle(tensorInfo, dataLayout, true);
51}
52
David Monahan3fb7e102019-08-20 11:25:29 +010053std::unique_ptr<ITensorHandle> NeonTensorHandleFactory::CreateTensorHandle(const TensorInfo& tensorInfo,
54 const bool IsMemoryManaged) const
Narumol Prangnawarat4e3e8182019-08-14 12:25:50 +010055{
56 auto tensorHandle = std::make_unique<NeonTensorHandle>(tensorInfo);
David Monahan3fb7e102019-08-20 11:25:29 +010057 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);
James Conroy57d10b72019-10-25 09:44:14 +010063 tensorHandle->SetImportFlags(GetImportFlags());
Narumol Prangnawarat4e3e8182019-08-14 12:25:50 +010064
65 return tensorHandle;
66}
67
68std::unique_ptr<ITensorHandle> NeonTensorHandleFactory::CreateTensorHandle(const TensorInfo& tensorInfo,
David Monahan3fb7e102019-08-20 11:25:29 +010069 DataLayout dataLayout,
70 const bool IsMemoryManaged) const
Narumol Prangnawarat4e3e8182019-08-14 12:25:50 +010071{
72 auto tensorHandle = std::make_unique<NeonTensorHandle>(tensorInfo, dataLayout);
David Monahan3fb7e102019-08-20 11:25:29 +010073 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);
James Conroy57d10b72019-10-25 09:44:14 +010079 tensorHandle->SetImportFlags(GetImportFlags());
Narumol Prangnawarat4e3e8182019-08-14 12:25:50 +010080
81 return tensorHandle;
82}
83
Jan Eilerse9f0f0f2019-08-16 10:28:37 +010084const FactoryId& NeonTensorHandleFactory::GetIdStatic()
85{
86 static const FactoryId s_Id(NeonTensorHandleFactoryId());
87 return s_Id;
88}
89
Ferran Balaguerbfeb2712019-08-07 15:14:56 +010090const FactoryId& NeonTensorHandleFactory::GetId() const
Narumol Prangnawarat4e3e8182019-08-14 12:25:50 +010091{
Jan Eilerse9f0f0f2019-08-16 10:28:37 +010092 return GetIdStatic();
Narumol Prangnawarat4e3e8182019-08-14 12:25:50 +010093}
94
95bool NeonTensorHandleFactory::SupportsSubTensors() const
96{
97 return true;
98}
99
100MemorySourceFlags NeonTensorHandleFactory::GetExportFlags() const
101{
James Conroy57d10b72019-10-25 09:44:14 +0100102 return 0;
Narumol Prangnawarat4e3e8182019-08-14 12:25:50 +0100103}
104
105MemorySourceFlags NeonTensorHandleFactory::GetImportFlags() const
106{
James Conroy57d10b72019-10-25 09:44:14 +0100107 return static_cast<MemorySourceFlags>(MemorySource::Malloc);
Narumol Prangnawarat4e3e8182019-08-14 12:25:50 +0100108}
109
Ferran Balaguerbfeb2712019-08-07 15:14:56 +0100110} // namespace armnn