Narumol Prangnawarat | 15eb583 | 2019-05-20 15:31:05 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "NeonSplitterWorkload.hpp" |
| 7 | |
Matthew Bentham | 5e98b01 | 2020-01-24 23:11:43 +0000 | [diff] [blame^] | 8 | #include <arm_compute/runtime/NEON/functions/NESplit.h> |
Narumol Prangnawarat | 15eb583 | 2019-05-20 15:31:05 +0100 | [diff] [blame] | 9 | |
| 10 | #include <aclCommon/ArmComputeTensorUtils.hpp> |
| 11 | #include <aclCommon/ArmComputeUtils.hpp> |
| 12 | #include <backendsCommon/CpuTensorHandle.hpp> |
| 13 | #include <neon/NeonTensorHandle.hpp> |
| 14 | |
Matthew Bentham | 5e98b01 | 2020-01-24 23:11:43 +0000 | [diff] [blame^] | 15 | #include "NeonWorkloadUtils.hpp" |
Narumol Prangnawarat | 15eb583 | 2019-05-20 15:31:05 +0100 | [diff] [blame] | 16 | |
| 17 | namespace armnn |
| 18 | { |
| 19 | |
| 20 | using namespace armcomputetensorutils; |
| 21 | |
| 22 | namespace |
| 23 | { |
| 24 | unsigned int CalcAclAxis(unsigned int numDimensions, unsigned int splitAxis) |
| 25 | { |
| 26 | return (numDimensions - splitAxis) - 1; |
| 27 | } |
| 28 | |
| 29 | } //namespace |
| 30 | |
| 31 | arm_compute::Status NeonSplitterWorkloadValidate(const TensorInfo& input, |
| 32 | const std::vector<std::reference_wrapper<TensorInfo>>& outputs, |
| 33 | unsigned int splitAxis) |
| 34 | { |
| 35 | const arm_compute::TensorInfo aclInputInfo = BuildArmComputeTensorInfo(input); |
| 36 | |
| 37 | size_t numOutputs = outputs.size(); |
| 38 | |
| 39 | std::vector<arm_compute::TensorInfo> aclOutputs; |
| 40 | aclOutputs.reserve(numOutputs); |
| 41 | |
| 42 | std::vector<arm_compute::ITensorInfo*> aclOutputPtr; |
| 43 | aclOutputPtr.reserve(numOutputs); |
| 44 | |
| 45 | for (size_t i = 0u; i < outputs.size(); ++i) |
| 46 | { |
| 47 | aclOutputs.emplace_back(BuildArmComputeTensorInfo(outputs[i])); |
| 48 | aclOutputPtr.emplace_back(&aclOutputs.back()); |
| 49 | } |
| 50 | |
| 51 | unsigned int aclAxis = CalcAclAxis(input.GetNumDimensions(), splitAxis); |
| 52 | return arm_compute::NESplit::validate(&aclInputInfo, aclOutputPtr, aclAxis); |
| 53 | } |
| 54 | |
| 55 | NeonSplitterWorkload::NeonSplitterWorkload(const SplitterQueueDescriptor& descriptor, const WorkloadInfo& info) |
| 56 | : BaseWorkload<SplitterQueueDescriptor>(descriptor, info) |
| 57 | { |
| 58 | bool allOutputsAreSubtensors = true; |
| 59 | |
| 60 | // Check that all outputs are sub-tensors |
| 61 | for (auto output : m_Data.m_Outputs) |
| 62 | { |
| 63 | if (output && !output->GetParent()) |
| 64 | { |
| 65 | // Non sub-tensor input found so we need to execute the split function |
| 66 | allOutputsAreSubtensors = false; |
| 67 | break; |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | if (allOutputsAreSubtensors) |
| 72 | { |
| 73 | // Can skip configuring the split function since it's not executed |
| 74 | return; |
| 75 | } |
| 76 | |
Derek Lamberti | c81855f | 2019-06-13 17:34:19 +0100 | [diff] [blame] | 77 | arm_compute::ITensor& input = boost::polymorphic_downcast<IAclTensorHandle*>(m_Data.m_Inputs[0])->GetTensor(); |
Narumol Prangnawarat | 15eb583 | 2019-05-20 15:31:05 +0100 | [diff] [blame] | 78 | |
| 79 | std::vector<arm_compute::ITensor *> aclOutputs; |
| 80 | for (auto output : m_Data.m_Outputs) |
| 81 | { |
Derek Lamberti | c81855f | 2019-06-13 17:34:19 +0100 | [diff] [blame] | 82 | arm_compute::ITensor& aclOutput = boost::polymorphic_pointer_downcast<IAclTensorHandle>(output)->GetTensor(); |
Narumol Prangnawarat | 15eb583 | 2019-05-20 15:31:05 +0100 | [diff] [blame] | 83 | aclOutputs.emplace_back(&aclOutput); |
| 84 | } |
| 85 | |
| 86 | // Create the layer function |
Matthew Bentham | 5e98b01 | 2020-01-24 23:11:43 +0000 | [diff] [blame^] | 87 | std::unique_ptr<arm_compute::NESplit> layer(new arm_compute::NESplit()); |
Narumol Prangnawarat | 15eb583 | 2019-05-20 15:31:05 +0100 | [diff] [blame] | 88 | |
| 89 | // Configure input and output tensors |
| 90 | std::set<unsigned int> splitAxis = ComputeSplitAxis(descriptor.m_Parameters, m_Data.m_Inputs[0]->GetShape()); |
| 91 | if (splitAxis.size() != 1) |
| 92 | { |
| 93 | throw InvalidArgumentException("Cannot derive split axis from SplitterDescriptor"); |
| 94 | } |
| 95 | |
| 96 | unsigned int aclAxis = CalcAclAxis(descriptor.m_Parameters.GetNumDimensions(), *splitAxis.begin()); |
Matthew Bentham | 5e98b01 | 2020-01-24 23:11:43 +0000 | [diff] [blame^] | 97 | layer->configure(&input, aclOutputs, aclAxis); |
Narumol Prangnawarat | 15eb583 | 2019-05-20 15:31:05 +0100 | [diff] [blame] | 98 | |
| 99 | // Prepare |
Matthew Bentham | 5e98b01 | 2020-01-24 23:11:43 +0000 | [diff] [blame^] | 100 | layer->prepare(); |
| 101 | m_Layer.reset(layer.release()); |
Narumol Prangnawarat | 15eb583 | 2019-05-20 15:31:05 +0100 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | void NeonSplitterWorkload::Execute() const |
| 105 | { |
| 106 | if (m_Layer) |
| 107 | { |
| 108 | ARMNN_SCOPED_PROFILING_EVENT_NEON("NeonSplitterWorkload_Execute"); |
| 109 | m_Layer->run(); |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | } //namespace armnn |
| 114 | |