blob: ff4e238cd840b7fdcdb1ce71e9689d9d20a246ca [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
42std::unique_ptr<ITensorHandle> NeonTensorHandleFactory::CreateTensorHandle(const TensorInfo& tensorInfo) const
43{
44 auto tensorHandle = std::make_unique<NeonTensorHandle>(tensorInfo);
45 tensorHandle->SetMemoryGroup(m_MemoryManager->GetInterLayerMemoryGroup());
46
47 return tensorHandle;
48}
49
50std::unique_ptr<ITensorHandle> NeonTensorHandleFactory::CreateTensorHandle(const TensorInfo& tensorInfo,
51 DataLayout dataLayout) const
52{
53 auto tensorHandle = std::make_unique<NeonTensorHandle>(tensorInfo, dataLayout);
54 tensorHandle->SetMemoryGroup(m_MemoryManager->GetInterLayerMemoryGroup());
55
56 return tensorHandle;
57}
58
Jan Eilerse9f0f0f2019-08-16 10:28:37 +010059const FactoryId& NeonTensorHandleFactory::GetIdStatic()
60{
61 static const FactoryId s_Id(NeonTensorHandleFactoryId());
62 return s_Id;
63}
64
Ferran Balaguerbfeb2712019-08-07 15:14:56 +010065const FactoryId& NeonTensorHandleFactory::GetId() const
Narumol Prangnawarat4e3e8182019-08-14 12:25:50 +010066{
Jan Eilerse9f0f0f2019-08-16 10:28:37 +010067 return GetIdStatic();
Narumol Prangnawarat4e3e8182019-08-14 12:25:50 +010068}
69
70bool NeonTensorHandleFactory::SupportsSubTensors() const
71{
72 return true;
73}
74
75MemorySourceFlags NeonTensorHandleFactory::GetExportFlags() const
76{
77 return m_ExportFlags;
78}
79
80MemorySourceFlags NeonTensorHandleFactory::GetImportFlags() const
81{
82 return m_ImportFlags;
83}
84
Ferran Balaguerbfeb2712019-08-07 15:14:56 +010085} // namespace armnn