Mike Kelly | 5685802 | 2020-01-27 12:14:47 +0000 | [diff] [blame] | 1 | // |
Teresa Charlin | ca5c82a | 2023-03-28 11:00:36 +0100 | [diff] [blame] | 2 | // Copyright © 2020, 2023 Arm Ltd and Contributors. All rights reserved. |
Mike Kelly | 5685802 | 2020-01-27 12:14:47 +0000 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "NeonBatchToSpaceNdWorkload.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 | 5685802 | 2020-01-27 12:14:47 +0000 | [diff] [blame] | 13 | #include <ResolveType.hpp> |
| 14 | |
| 15 | namespace armnn |
| 16 | { |
| 17 | |
| 18 | using namespace armcomputetensorutils; |
| 19 | |
| 20 | arm_compute::Status NeonBatchToSpaceNdWorkloadValidate(const TensorInfo& input, |
| 21 | const TensorInfo& output, |
Keith Davis | 2d0679f | 2021-08-05 11:35:00 +0100 | [diff] [blame] | 22 | const BatchToSpaceNdDescriptor& descriptor) |
Mike Kelly | 5685802 | 2020-01-27 12:14:47 +0000 | [diff] [blame] | 23 | { |
Keith Davis | 2d0679f | 2021-08-05 11:35:00 +0100 | [diff] [blame] | 24 | const arm_compute::TensorInfo aclInputInfo = BuildArmComputeTensorInfo(input, descriptor.m_DataLayout); |
| 25 | const arm_compute::TensorInfo aclOutputInfo = BuildArmComputeTensorInfo(output, descriptor.m_DataLayout); |
Mike Kelly | 5685802 | 2020-01-27 12:14:47 +0000 | [diff] [blame] | 26 | |
| 27 | // ArmNN blockShape is [H, W] Cl asks for W, H |
Keith Davis | 2d0679f | 2021-08-05 11:35:00 +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 | 5685802 | 2020-01-27 12:14:47 +0000 | [diff] [blame] | 30 | |
Teresa Charlin | ca5c82a | 2023-03-28 11:00:36 +0100 | [diff] [blame] | 31 | const arm_compute::CropInfo cropInfo = BuildArmComputeCropInfo(descriptor); |
| 32 | |
Mike Kelly | 5685802 | 2020-01-27 12:14:47 +0000 | [diff] [blame] | 33 | const arm_compute::Status aclStatus = arm_compute::NEBatchToSpaceLayer::validate(&aclInputInfo, |
| 34 | blockWidth, |
| 35 | blockHeight, |
Teresa Charlin | ca5c82a | 2023-03-28 11:00:36 +0100 | [diff] [blame] | 36 | &aclOutputInfo, |
| 37 | cropInfo); |
Mike Kelly | 5685802 | 2020-01-27 12:14:47 +0000 | [diff] [blame] | 38 | return aclStatus; |
| 39 | } |
| 40 | |
Keith Davis | 2d0679f | 2021-08-05 11:35:00 +0100 | [diff] [blame] | 41 | NeonBatchToSpaceNdWorkload::NeonBatchToSpaceNdWorkload(const BatchToSpaceNdQueueDescriptor& descriptor, |
Mike Kelly | 5685802 | 2020-01-27 12:14:47 +0000 | [diff] [blame] | 42 | const WorkloadInfo& info) |
Teresa Charlin | 588cbdf | 2022-01-19 15:55:37 +0000 | [diff] [blame] | 43 | : NeonBaseWorkload<BatchToSpaceNdQueueDescriptor>(descriptor, info) |
Mike Kelly | 5685802 | 2020-01-27 12:14:47 +0000 | [diff] [blame] | 44 | { |
Keith Davis | 2d0679f | 2021-08-05 11:35:00 +0100 | [diff] [blame] | 45 | // Report Profiling Details |
| 46 | ARMNN_REPORT_PROFILING_WORKLOAD_DESC("NeonBatchToSpaceWorkload_Construct", |
| 47 | descriptor.m_Parameters, |
| 48 | info, |
| 49 | this->GetGuid()); |
| 50 | |
Mike Kelly | 5685802 | 2020-01-27 12:14:47 +0000 | [diff] [blame] | 51 | m_Data.ValidateInputsOutputs("NeonBatchToSpaceNdWorkload", 1, 1); |
| 52 | |
| 53 | arm_compute::ITensor& input = |
Jan Eilers | 3c9e045 | 2020-04-10 13:00:44 +0100 | [diff] [blame] | 54 | armnn::PolymorphicPointerDowncast<IAclTensorHandle>(m_Data.m_Inputs[0])->GetTensor(); |
Mike Kelly | 5685802 | 2020-01-27 12:14:47 +0000 | [diff] [blame] | 55 | arm_compute::ITensor& output = |
Jan Eilers | 3c9e045 | 2020-04-10 13:00:44 +0100 | [diff] [blame] | 56 | armnn::PolymorphicPointerDowncast<IAclTensorHandle>(m_Data.m_Outputs[0])->GetTensor(); |
Mike Kelly | 5685802 | 2020-01-27 12:14:47 +0000 | [diff] [blame] | 57 | |
| 58 | arm_compute::DataLayout aclDataLayout = ConvertDataLayout(m_Data.m_Parameters.m_DataLayout); |
| 59 | input.info()->set_data_layout(aclDataLayout); |
| 60 | output.info()->set_data_layout(aclDataLayout); |
| 61 | |
| 62 | // ArmNN blockShape is [H, W] Cl asks for W, H |
Keith Davis | 2d0679f | 2021-08-05 11:35:00 +0100 | [diff] [blame] | 63 | int32_t blockHeight = armnn::numeric_cast<int32_t>(descriptor.m_Parameters.m_BlockShape[0]); |
| 64 | int32_t blockWidth = armnn::numeric_cast<int32_t>(descriptor.m_Parameters.m_BlockShape[1]); |
Mike Kelly | 5685802 | 2020-01-27 12:14:47 +0000 | [diff] [blame] | 65 | |
Teresa Charlin | ca5c82a | 2023-03-28 11:00:36 +0100 | [diff] [blame] | 66 | const arm_compute::CropInfo cropInfo = BuildArmComputeCropInfo(descriptor.m_Parameters); |
| 67 | |
Mike Kelly | 5685802 | 2020-01-27 12:14:47 +0000 | [diff] [blame] | 68 | m_Layer.reset(new arm_compute::NEBatchToSpaceLayer()); |
Teresa Charlin | ca5c82a | 2023-03-28 11:00:36 +0100 | [diff] [blame] | 69 | m_Layer->configure(&input, blockWidth, blockHeight, &output, cropInfo); |
Mike Kelly | 5685802 | 2020-01-27 12:14:47 +0000 | [diff] [blame] | 70 | m_Layer->prepare(); |
| 71 | } |
| 72 | |
| 73 | void NeonBatchToSpaceNdWorkload::Execute() const |
| 74 | { |
| 75 | if (m_Layer) |
| 76 | { |
Keith Davis | 2d0679f | 2021-08-05 11:35:00 +0100 | [diff] [blame] | 77 | ARMNN_SCOPED_PROFILING_EVENT_NEON_GUID("NeonSpaceToBatchNdWorkload_Execute", this->GetGuid()); |
Mike Kelly | 5685802 | 2020-01-27 12:14:47 +0000 | [diff] [blame] | 78 | m_Layer->run(); |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | } //namespace armnn |