Mike Kelly | 5685802 | 2020-01-27 12:14:47 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2020 Arm Ltd. All rights reserved. |
| 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, |
| 22 | const BatchToSpaceNdDescriptor& desc) |
| 23 | { |
| 24 | const arm_compute::TensorInfo aclInputInfo = BuildArmComputeTensorInfo(input, desc.m_DataLayout); |
| 25 | const arm_compute::TensorInfo aclOutputInfo = BuildArmComputeTensorInfo(output, desc.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>(desc.m_BlockShape[0]); |
| 29 | int32_t blockWidth = armnn::numeric_cast<int32_t>(desc.m_BlockShape[1]); |
Mike Kelly | 5685802 | 2020-01-27 12:14:47 +0000 | [diff] [blame] | 30 | |
| 31 | const arm_compute::Status aclStatus = arm_compute::NEBatchToSpaceLayer::validate(&aclInputInfo, |
| 32 | blockWidth, |
| 33 | blockHeight, |
| 34 | &aclOutputInfo); |
| 35 | return aclStatus; |
| 36 | } |
| 37 | |
| 38 | NeonBatchToSpaceNdWorkload::NeonBatchToSpaceNdWorkload(const BatchToSpaceNdQueueDescriptor& desc, |
| 39 | const WorkloadInfo& info) |
| 40 | : BaseWorkload<BatchToSpaceNdQueueDescriptor>(desc, info) |
| 41 | { |
| 42 | m_Data.ValidateInputsOutputs("NeonBatchToSpaceNdWorkload", 1, 1); |
| 43 | |
| 44 | arm_compute::ITensor& input = |
Jan Eilers | 3c9e045 | 2020-04-10 13:00:44 +0100 | [diff] [blame] | 45 | armnn::PolymorphicPointerDowncast<IAclTensorHandle>(m_Data.m_Inputs[0])->GetTensor(); |
Mike Kelly | 5685802 | 2020-01-27 12:14:47 +0000 | [diff] [blame] | 46 | arm_compute::ITensor& output = |
Jan Eilers | 3c9e045 | 2020-04-10 13:00:44 +0100 | [diff] [blame] | 47 | armnn::PolymorphicPointerDowncast<IAclTensorHandle>(m_Data.m_Outputs[0])->GetTensor(); |
Mike Kelly | 5685802 | 2020-01-27 12:14:47 +0000 | [diff] [blame] | 48 | |
| 49 | arm_compute::DataLayout aclDataLayout = ConvertDataLayout(m_Data.m_Parameters.m_DataLayout); |
| 50 | input.info()->set_data_layout(aclDataLayout); |
| 51 | output.info()->set_data_layout(aclDataLayout); |
| 52 | |
| 53 | // ArmNN blockShape is [H, W] Cl asks for W, H |
Matthew Sloyan | 171214c | 2020-09-09 09:07:37 +0100 | [diff] [blame] | 54 | int32_t blockHeight = armnn::numeric_cast<int32_t>(desc.m_Parameters.m_BlockShape[0]); |
| 55 | int32_t blockWidth = armnn::numeric_cast<int32_t>(desc.m_Parameters.m_BlockShape[1]); |
Mike Kelly | 5685802 | 2020-01-27 12:14:47 +0000 | [diff] [blame] | 56 | |
| 57 | m_Layer.reset(new arm_compute::NEBatchToSpaceLayer()); |
| 58 | m_Layer->configure(&input, blockWidth, blockHeight, &output); |
| 59 | m_Layer->prepare(); |
| 60 | } |
| 61 | |
| 62 | void NeonBatchToSpaceNdWorkload::Execute() const |
| 63 | { |
| 64 | if (m_Layer) |
| 65 | { |
| 66 | ARMNN_SCOPED_PROFILING_EVENT_NEON("NeonSpaceToBatchNdWorkload_Execute"); |
| 67 | m_Layer->run(); |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | } //namespace armnn |