Mike Kelly | 0be3a88 | 2020-01-24 11:27:50 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2020 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "NeonSpaceToBatchNdWorkload.hpp" |
| 7 | |
| 8 | #include "NeonWorkloadUtils.hpp" |
Jan Eilers | 3c9e045 | 2020-04-10 13:00:44 +0100 | [diff] [blame] | 9 | |
| 10 | #include <armnn/utility/PolymorphicDowncast.hpp> |
Mike Kelly | 0be3a88 | 2020-01-24 11:27:50 +0000 | [diff] [blame] | 11 | #include <ResolveType.hpp> |
| 12 | |
| 13 | namespace armnn |
| 14 | { |
| 15 | |
| 16 | using namespace armcomputetensorutils; |
| 17 | |
| 18 | arm_compute::Status NeonSpaceToBatchNdWorkloadValidate(const TensorInfo& input, |
| 19 | const TensorInfo& output, |
| 20 | const SpaceToBatchNdDescriptor& descriptor) |
| 21 | { |
| 22 | const arm_compute::TensorInfo aclInputInfo = BuildArmComputeTensorInfo(input, descriptor.m_DataLayout); |
| 23 | const arm_compute::TensorInfo aclOutputInfo = BuildArmComputeTensorInfo(output, descriptor.m_DataLayout); |
| 24 | |
| 25 | // ArmNN blockShape is [H, W] Cl asks for W, H |
| 26 | int32_t blockHeight = boost::numeric_cast<int32_t>(descriptor.m_BlockShape[0]); |
| 27 | int32_t blockWidth = boost::numeric_cast<int32_t>(descriptor.m_BlockShape[1]); |
| 28 | |
| 29 | arm_compute::Size2D paddingLeftTop = BuildArmComputeSize2D( |
| 30 | descriptor.m_PadList[1].first, descriptor.m_PadList[0].first); |
| 31 | arm_compute::Size2D paddingRightBottom = BuildArmComputeSize2D( |
| 32 | descriptor.m_PadList[1].second, descriptor.m_PadList[0].second); |
| 33 | |
| 34 | return arm_compute::NESpaceToBatchLayer::validate(&aclInputInfo, |
| 35 | blockWidth, |
| 36 | blockHeight, |
| 37 | paddingLeftTop, |
| 38 | paddingRightBottom, |
| 39 | &aclOutputInfo); |
| 40 | } |
| 41 | |
| 42 | NeonSpaceToBatchNdWorkload::NeonSpaceToBatchNdWorkload(const SpaceToBatchNdQueueDescriptor& desc, |
| 43 | const WorkloadInfo& info) |
| 44 | : BaseWorkload<SpaceToBatchNdQueueDescriptor>(desc, info) |
| 45 | { |
| 46 | m_Data.ValidateInputsOutputs("NESpaceToBatchNdWorkload", 1, 1); |
| 47 | |
| 48 | arm_compute::ITensor& input = |
Jan Eilers | 3c9e045 | 2020-04-10 13:00:44 +0100 | [diff] [blame] | 49 | PolymorphicPointerDowncast<IAclTensorHandle>(m_Data.m_Inputs[0])->GetTensor(); |
Mike Kelly | 0be3a88 | 2020-01-24 11:27:50 +0000 | [diff] [blame] | 50 | arm_compute::ITensor& output = |
Jan Eilers | 3c9e045 | 2020-04-10 13:00:44 +0100 | [diff] [blame] | 51 | PolymorphicPointerDowncast<IAclTensorHandle>(m_Data.m_Outputs[0])->GetTensor(); |
Mike Kelly | 0be3a88 | 2020-01-24 11:27:50 +0000 | [diff] [blame] | 52 | |
| 53 | // ArmNN blockShape is [H, W] Cl asks for W, H |
| 54 | int32_t blockHeight = boost::numeric_cast<int32_t>(m_Data.m_Parameters.m_BlockShape[0]); |
| 55 | int32_t blockWidth = boost::numeric_cast<int32_t>(m_Data.m_Parameters.m_BlockShape[1]); |
| 56 | |
| 57 | arm_compute::Size2D paddingLeftTop = BuildArmComputeSize2D( |
| 58 | m_Data.m_Parameters.m_PadList[1].first, m_Data.m_Parameters.m_PadList[0].first); |
| 59 | arm_compute::Size2D paddingRightBottom = BuildArmComputeSize2D( |
| 60 | m_Data.m_Parameters.m_PadList[1].second, m_Data.m_Parameters.m_PadList[0].second); |
| 61 | |
| 62 | arm_compute::DataLayout aclDataLayout = ConvertDataLayout(m_Data.m_Parameters.m_DataLayout); |
| 63 | input.info()->set_data_layout(aclDataLayout); |
| 64 | output.info()->set_data_layout(aclDataLayout); |
| 65 | |
| 66 | m_Layer.reset(new arm_compute::NESpaceToBatchLayer()); |
| 67 | m_Layer->configure(&input, |
| 68 | blockWidth, |
| 69 | blockHeight, |
| 70 | paddingLeftTop, |
| 71 | paddingRightBottom, |
| 72 | &output); |
| 73 | m_Layer->prepare(); |
| 74 | } |
| 75 | |
| 76 | void NeonSpaceToBatchNdWorkload::Execute() const |
| 77 | { |
| 78 | if (m_Layer) |
| 79 | { |
| 80 | ARMNN_SCOPED_PROFILING_EVENT_NEON("NeonSpaceToBatchNdWorkload_Execute"); |
| 81 | m_Layer->run(); |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | } //namespace armnn |