blob: a8b5b814122290d3b0467996828d6c5325815830 [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
Jan Eilers8eb25602020-03-09 12:13:48 +00009#include <armnn/utility/IgnoreUnused.hpp>
Jan Eilersbb446e52020-04-02 13:56:54 +010010#include <armnn/utility/PolymorphicDowncast.hpp>
Narumol Prangnawarat4e3e8182019-08-14 12:25:50 +010011
12namespace armnn
13{
14
Jan Eilerse9f0f0f2019-08-16 10:28:37 +010015using FactoryId = ITensorHandleFactory::FactoryId;
Narumol Prangnawarat4e3e8182019-08-14 12:25:50 +010016
17std::unique_ptr<ITensorHandle> NeonTensorHandleFactory::CreateSubTensorHandle(ITensorHandle& parent,
Jan Eilerse9f0f0f2019-08-16 10:28:37 +010018 const TensorShape& subTensorShape,
19 const unsigned int* subTensorOrigin)
Narumol Prangnawarat4e3e8182019-08-14 12:25:50 +010020 const
21{
22 const arm_compute::TensorShape shape = armcomputetensorutils::BuildArmComputeTensorShape(subTensorShape);
23
24 arm_compute::Coordinates coords;
25 coords.set_num_dimensions(subTensorShape.GetNumDimensions());
Jan Eilerse9f0f0f2019-08-16 10:28:37 +010026 for (unsigned int i = 0; i < subTensorShape.GetNumDimensions(); ++i)
Narumol Prangnawarat4e3e8182019-08-14 12:25:50 +010027 {
28 // Arm compute indexes tensor coords in reverse order.
29 unsigned int revertedIndex = subTensorShape.GetNumDimensions() - i - 1;
30 coords.set(i, boost::numeric_cast<int>(subTensorOrigin[revertedIndex]));
31 }
32
33 const arm_compute::TensorShape parentShape = armcomputetensorutils::BuildArmComputeTensorShape(parent.GetShape());
34 if (!::arm_compute::error_on_invalid_subtensor(__func__, __FILE__, __LINE__, parentShape, coords, shape))
35 {
36 return nullptr;
37 }
38
39 return std::make_unique<NeonSubTensorHandle>(
Jan Eilersbb446e52020-04-02 13:56:54 +010040 PolymorphicDowncast<IAclTensorHandle*>(&parent), shape, coords);
Narumol Prangnawarat4e3e8182019-08-14 12:25:50 +010041}
42
David Monahanc6e5a6e2019-10-02 09:33:57 +010043std::unique_ptr<ITensorHandle> NeonTensorHandleFactory::CreateTensorHandle(const TensorInfo& tensorInfo) const
44{
45 return NeonTensorHandleFactory::CreateTensorHandle(tensorInfo, true);
46}
47
48std::unique_ptr<ITensorHandle> NeonTensorHandleFactory::CreateTensorHandle(const TensorInfo& tensorInfo,
49 DataLayout dataLayout) const
50{
51 return NeonTensorHandleFactory::CreateTensorHandle(tensorInfo, dataLayout, true);
52}
53
David Monahan3fb7e102019-08-20 11:25:29 +010054std::unique_ptr<ITensorHandle> NeonTensorHandleFactory::CreateTensorHandle(const TensorInfo& tensorInfo,
55 const bool IsMemoryManaged) const
Narumol Prangnawarat4e3e8182019-08-14 12:25:50 +010056{
57 auto tensorHandle = std::make_unique<NeonTensorHandle>(tensorInfo);
David Monahan3fb7e102019-08-20 11:25:29 +010058 if (IsMemoryManaged)
59 {
60 tensorHandle->SetMemoryGroup(m_MemoryManager->GetInterLayerMemoryGroup());
61 }
62 // If we are not Managing the Memory then we must be importing
63 tensorHandle->SetImportEnabledFlag(!IsMemoryManaged);
James Conroy57d10b72019-10-25 09:44:14 +010064 tensorHandle->SetImportFlags(GetImportFlags());
Narumol Prangnawarat4e3e8182019-08-14 12:25:50 +010065
66 return tensorHandle;
67}
68
69std::unique_ptr<ITensorHandle> NeonTensorHandleFactory::CreateTensorHandle(const TensorInfo& tensorInfo,
David Monahan3fb7e102019-08-20 11:25:29 +010070 DataLayout dataLayout,
71 const bool IsMemoryManaged) const
Narumol Prangnawarat4e3e8182019-08-14 12:25:50 +010072{
73 auto tensorHandle = std::make_unique<NeonTensorHandle>(tensorInfo, dataLayout);
David Monahan3fb7e102019-08-20 11:25:29 +010074 if (IsMemoryManaged)
75 {
76 tensorHandle->SetMemoryGroup(m_MemoryManager->GetInterLayerMemoryGroup());
77 }
78 // If we are not Managing the Memory then we must be importing
79 tensorHandle->SetImportEnabledFlag(!IsMemoryManaged);
James Conroy57d10b72019-10-25 09:44:14 +010080 tensorHandle->SetImportFlags(GetImportFlags());
Narumol Prangnawarat4e3e8182019-08-14 12:25:50 +010081
82 return tensorHandle;
83}
84
Jan Eilerse9f0f0f2019-08-16 10:28:37 +010085const FactoryId& NeonTensorHandleFactory::GetIdStatic()
86{
87 static const FactoryId s_Id(NeonTensorHandleFactoryId());
88 return s_Id;
89}
90
Ferran Balaguerbfeb2712019-08-07 15:14:56 +010091const FactoryId& NeonTensorHandleFactory::GetId() const
Narumol Prangnawarat4e3e8182019-08-14 12:25:50 +010092{
Jan Eilerse9f0f0f2019-08-16 10:28:37 +010093 return GetIdStatic();
Narumol Prangnawarat4e3e8182019-08-14 12:25:50 +010094}
95
96bool NeonTensorHandleFactory::SupportsSubTensors() const
97{
98 return true;
99}
100
101MemorySourceFlags NeonTensorHandleFactory::GetExportFlags() const
102{
James Conroy57d10b72019-10-25 09:44:14 +0100103 return 0;
Narumol Prangnawarat4e3e8182019-08-14 12:25:50 +0100104}
105
106MemorySourceFlags NeonTensorHandleFactory::GetImportFlags() const
107{
James Conroyffab16f2019-11-07 14:37:09 +0000108 return 0;
Narumol Prangnawarat4e3e8182019-08-14 12:25:50 +0100109}
110
Ferran Balaguerbfeb2712019-08-07 15:14:56 +0100111} // namespace armnn