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 | |
Matthew Sloyan | 171214c | 2020-09-09 09:07:37 +0100 | [diff] [blame] | 10 | #include <armnn/utility/NumericCast.hpp> |
Jan Eilers | 3c9e045 | 2020-04-10 13:00:44 +0100 | [diff] [blame] | 11 | #include <armnn/utility/PolymorphicDowncast.hpp> |
Matthew Sloyan | 171214c | 2020-09-09 09:07:37 +0100 | [diff] [blame] | 12 | |
Mike Kelly | 0be3a88 | 2020-01-24 11:27:50 +0000 | [diff] [blame] | 13 | #include <ResolveType.hpp> |
| 14 | |
| 15 | namespace armnn |
| 16 | { |
| 17 | |
| 18 | using namespace armcomputetensorutils; |
| 19 | |
| 20 | arm_compute::Status NeonSpaceToBatchNdWorkloadValidate(const TensorInfo& input, |
| 21 | const TensorInfo& output, |
| 22 | const SpaceToBatchNdDescriptor& descriptor) |
| 23 | { |
| 24 | const arm_compute::TensorInfo aclInputInfo = BuildArmComputeTensorInfo(input, descriptor.m_DataLayout); |
| 25 | const arm_compute::TensorInfo aclOutputInfo = BuildArmComputeTensorInfo(output, descriptor.m_DataLayout); |
| 26 | |
| 27 | // ArmNN blockShape is [H, W] Cl asks for W, H |
Matthew Sloyan | 171214c | 2020-09-09 09:07:37 +0100 | [diff] [blame] | 28 | int32_t blockHeight = armnn::numeric_cast<int32_t>(descriptor.m_BlockShape[0]); |
| 29 | int32_t blockWidth = armnn::numeric_cast<int32_t>(descriptor.m_BlockShape[1]); |
Mike Kelly | 0be3a88 | 2020-01-24 11:27:50 +0000 | [diff] [blame] | 30 | |
| 31 | arm_compute::Size2D paddingLeftTop = BuildArmComputeSize2D( |
| 32 | descriptor.m_PadList[1].first, descriptor.m_PadList[0].first); |
| 33 | arm_compute::Size2D paddingRightBottom = BuildArmComputeSize2D( |
| 34 | descriptor.m_PadList[1].second, descriptor.m_PadList[0].second); |
| 35 | |
| 36 | return arm_compute::NESpaceToBatchLayer::validate(&aclInputInfo, |
| 37 | blockWidth, |
| 38 | blockHeight, |
| 39 | paddingLeftTop, |
| 40 | paddingRightBottom, |
| 41 | &aclOutputInfo); |
| 42 | } |
| 43 | |
Keith Davis | 2d0679f | 2021-08-05 11:35:00 +0100 | [diff] [blame] | 44 | NeonSpaceToBatchNdWorkload::NeonSpaceToBatchNdWorkload(const SpaceToBatchNdQueueDescriptor& descriptor, |
Mike Kelly | 0be3a88 | 2020-01-24 11:27:50 +0000 | [diff] [blame] | 45 | const WorkloadInfo& info) |
Keith Davis | 2d0679f | 2021-08-05 11:35:00 +0100 | [diff] [blame] | 46 | : BaseWorkload<SpaceToBatchNdQueueDescriptor>(descriptor, info) |
Mike Kelly | 0be3a88 | 2020-01-24 11:27:50 +0000 | [diff] [blame] | 47 | { |
Keith Davis | 2d0679f | 2021-08-05 11:35:00 +0100 | [diff] [blame] | 48 | // Report Profiling Details |
| 49 | ARMNN_REPORT_PROFILING_WORKLOAD_DESC("NeonSpaceToBatchNdWorkload_Construct", |
| 50 | descriptor.m_Parameters, |
| 51 | info, |
| 52 | this->GetGuid()); |
| 53 | |
Mike Kelly | 0be3a88 | 2020-01-24 11:27:50 +0000 | [diff] [blame] | 54 | m_Data.ValidateInputsOutputs("NESpaceToBatchNdWorkload", 1, 1); |
| 55 | |
| 56 | arm_compute::ITensor& input = |
Jan Eilers | 3c9e045 | 2020-04-10 13:00:44 +0100 | [diff] [blame] | 57 | PolymorphicPointerDowncast<IAclTensorHandle>(m_Data.m_Inputs[0])->GetTensor(); |
Mike Kelly | 0be3a88 | 2020-01-24 11:27:50 +0000 | [diff] [blame] | 58 | arm_compute::ITensor& output = |
Jan Eilers | 3c9e045 | 2020-04-10 13:00:44 +0100 | [diff] [blame] | 59 | PolymorphicPointerDowncast<IAclTensorHandle>(m_Data.m_Outputs[0])->GetTensor(); |
Mike Kelly | 0be3a88 | 2020-01-24 11:27:50 +0000 | [diff] [blame] | 60 | |
| 61 | // ArmNN blockShape is [H, W] Cl asks for W, H |
Matthew Sloyan | 171214c | 2020-09-09 09:07:37 +0100 | [diff] [blame] | 62 | int32_t blockHeight = armnn::numeric_cast<int32_t>(m_Data.m_Parameters.m_BlockShape[0]); |
| 63 | int32_t blockWidth = armnn::numeric_cast<int32_t>(m_Data.m_Parameters.m_BlockShape[1]); |
Mike Kelly | 0be3a88 | 2020-01-24 11:27:50 +0000 | [diff] [blame] | 64 | |
| 65 | arm_compute::Size2D paddingLeftTop = BuildArmComputeSize2D( |
| 66 | m_Data.m_Parameters.m_PadList[1].first, m_Data.m_Parameters.m_PadList[0].first); |
| 67 | arm_compute::Size2D paddingRightBottom = BuildArmComputeSize2D( |
| 68 | m_Data.m_Parameters.m_PadList[1].second, m_Data.m_Parameters.m_PadList[0].second); |
| 69 | |
| 70 | arm_compute::DataLayout aclDataLayout = ConvertDataLayout(m_Data.m_Parameters.m_DataLayout); |
| 71 | input.info()->set_data_layout(aclDataLayout); |
| 72 | output.info()->set_data_layout(aclDataLayout); |
| 73 | |
| 74 | m_Layer.reset(new arm_compute::NESpaceToBatchLayer()); |
| 75 | m_Layer->configure(&input, |
| 76 | blockWidth, |
| 77 | blockHeight, |
| 78 | paddingLeftTop, |
| 79 | paddingRightBottom, |
| 80 | &output); |
| 81 | m_Layer->prepare(); |
| 82 | } |
| 83 | |
| 84 | void NeonSpaceToBatchNdWorkload::Execute() const |
| 85 | { |
| 86 | if (m_Layer) |
| 87 | { |
Keith Davis | 2d0679f | 2021-08-05 11:35:00 +0100 | [diff] [blame] | 88 | ARMNN_SCOPED_PROFILING_EVENT_NEON_GUID("NeonSpaceToBatchNdWorkload_Execute", this->GetGuid()); |
Mike Kelly | 0be3a88 | 2020-01-24 11:27:50 +0000 | [diff] [blame] | 89 | m_Layer->run(); |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | } //namespace armnn |