Narumol Prangnawarat | 4e3e818 | 2019-08-14 12:25:50 +0100 | [diff] [blame] | 1 | // |
| 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 | |
| 11 | namespace armnn |
| 12 | { |
| 13 | |
Jan Eilers | e9f0f0f | 2019-08-16 10:28:37 +0100 | [diff] [blame] | 14 | using FactoryId = ITensorHandleFactory::FactoryId; |
Narumol Prangnawarat | 4e3e818 | 2019-08-14 12:25:50 +0100 | [diff] [blame] | 15 | |
| 16 | std::unique_ptr<ITensorHandle> NeonTensorHandleFactory::CreateSubTensorHandle(ITensorHandle& parent, |
Jan Eilers | e9f0f0f | 2019-08-16 10:28:37 +0100 | [diff] [blame] | 17 | const TensorShape& subTensorShape, |
| 18 | const unsigned int* subTensorOrigin) |
Narumol Prangnawarat | 4e3e818 | 2019-08-14 12:25:50 +0100 | [diff] [blame] | 19 | 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 Eilers | e9f0f0f | 2019-08-16 10:28:37 +0100 | [diff] [blame] | 25 | for (unsigned int i = 0; i < subTensorShape.GetNumDimensions(); ++i) |
Narumol Prangnawarat | 4e3e818 | 2019-08-14 12:25:50 +0100 | [diff] [blame] | 26 | { |
| 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 | |
| 42 | std::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 | |
| 50 | std::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 Eilers | e9f0f0f | 2019-08-16 10:28:37 +0100 | [diff] [blame] | 59 | const FactoryId& NeonTensorHandleFactory::GetIdStatic() |
| 60 | { |
| 61 | static const FactoryId s_Id(NeonTensorHandleFactoryId()); |
| 62 | return s_Id; |
| 63 | } |
| 64 | |
Ferran Balaguer | bfeb271 | 2019-08-07 15:14:56 +0100 | [diff] [blame] | 65 | const FactoryId& NeonTensorHandleFactory::GetId() const |
Narumol Prangnawarat | 4e3e818 | 2019-08-14 12:25:50 +0100 | [diff] [blame] | 66 | { |
Jan Eilers | e9f0f0f | 2019-08-16 10:28:37 +0100 | [diff] [blame] | 67 | return GetIdStatic(); |
Narumol Prangnawarat | 4e3e818 | 2019-08-14 12:25:50 +0100 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | bool NeonTensorHandleFactory::SupportsSubTensors() const |
| 71 | { |
| 72 | return true; |
| 73 | } |
| 74 | |
| 75 | MemorySourceFlags NeonTensorHandleFactory::GetExportFlags() const |
| 76 | { |
| 77 | return m_ExportFlags; |
| 78 | } |
| 79 | |
| 80 | MemorySourceFlags NeonTensorHandleFactory::GetImportFlags() const |
| 81 | { |
| 82 | return m_ImportFlags; |
| 83 | } |
| 84 | |
Ferran Balaguer | bfeb271 | 2019-08-07 15:14:56 +0100 | [diff] [blame] | 85 | } // namespace armnn |