Sadik Armagan | f446432 | 2018-12-20 16:19:12 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "ClSpaceToBatchNdWorkload.hpp" |
| 7 | |
| 8 | #include "ClWorkloadUtils.hpp" |
| 9 | |
| 10 | #include <aclCommon/ArmComputeUtils.hpp> |
| 11 | #include <aclCommon/ArmComputeTensorUtils.hpp> |
Jan Eilers | 3c9e045 | 2020-04-10 13:00:44 +0100 | [diff] [blame] | 12 | #include <armnn/utility/PolymorphicDowncast.hpp> |
Sadik Armagan | f446432 | 2018-12-20 16:19:12 +0000 | [diff] [blame] | 13 | #include <backendsCommon/CpuTensorHandle.hpp> |
| 14 | #include <cl/ClLayerSupport.hpp> |
| 15 | #include <cl/ClTensorHandle.hpp> |
| 16 | #include <cl/ClLayerSupport.hpp> |
| 17 | |
Sadik Armagan | f446432 | 2018-12-20 16:19:12 +0000 | [diff] [blame] | 18 | namespace armnn |
| 19 | { |
| 20 | using namespace armcomputetensorutils; |
| 21 | |
| 22 | arm_compute::Status ClSpaceToBatchNdWorkloadValidate(const TensorInfo& input, |
| 23 | const TensorInfo& output, |
| 24 | const SpaceToBatchNdDescriptor& descriptor) |
| 25 | { |
| 26 | const arm_compute::TensorInfo aclInputInfo = BuildArmComputeTensorInfo(input, descriptor.m_DataLayout); |
| 27 | const arm_compute::TensorInfo aclOutputInfo = BuildArmComputeTensorInfo(output, descriptor.m_DataLayout); |
| 28 | |
| 29 | // ArmNN blockShape is [H, W] Cl asks for W, H |
| 30 | int32_t blockHeight = boost::numeric_cast<int32_t>(descriptor.m_BlockShape[0]); |
| 31 | int32_t blockWidth = boost::numeric_cast<int32_t>(descriptor.m_BlockShape[1]); |
| 32 | |
Nattapat Chaimanowong | 17fa2b4 | 2019-02-26 12:26:08 +0000 | [diff] [blame] | 33 | arm_compute::Size2D paddingLeftTop = BuildArmComputeSize2D( |
| 34 | descriptor.m_PadList[1].first, descriptor.m_PadList[0].first); |
| 35 | arm_compute::Size2D paddingRightBottom = BuildArmComputeSize2D( |
| 36 | descriptor.m_PadList[1].second, descriptor.m_PadList[0].second); |
Sadik Armagan | f446432 | 2018-12-20 16:19:12 +0000 | [diff] [blame] | 37 | |
| 38 | return arm_compute::CLSpaceToBatchLayer::validate(&aclInputInfo, |
| 39 | blockWidth, |
| 40 | blockHeight, |
Nattapat Chaimanowong | 17fa2b4 | 2019-02-26 12:26:08 +0000 | [diff] [blame] | 41 | paddingLeftTop, |
| 42 | paddingRightBottom, |
Sadik Armagan | f446432 | 2018-12-20 16:19:12 +0000 | [diff] [blame] | 43 | &aclOutputInfo); |
| 44 | } |
| 45 | |
| 46 | ClSpaceToBatchNdWorkload::ClSpaceToBatchNdWorkload( |
| 47 | const SpaceToBatchNdQueueDescriptor& descriptor, const WorkloadInfo& info) |
| 48 | : BaseWorkload<SpaceToBatchNdQueueDescriptor>(descriptor, info) |
| 49 | { |
| 50 | m_Data.ValidateInputsOutputs("ClSpaceToBatchNdWorkload", 1, 1); |
| 51 | |
| 52 | arm_compute::ICLTensor& input = |
Jan Eilers | 3c9e045 | 2020-04-10 13:00:44 +0100 | [diff] [blame] | 53 | armnn::PolymorphicPointerDowncast<IClTensorHandle>(m_Data.m_Inputs[0])->GetTensor(); |
Sadik Armagan | f446432 | 2018-12-20 16:19:12 +0000 | [diff] [blame] | 54 | arm_compute::ICLTensor& output = |
Jan Eilers | 3c9e045 | 2020-04-10 13:00:44 +0100 | [diff] [blame] | 55 | armnn::PolymorphicPointerDowncast<IClTensorHandle>(m_Data.m_Outputs[0])->GetTensor(); |
Sadik Armagan | f446432 | 2018-12-20 16:19:12 +0000 | [diff] [blame] | 56 | |
| 57 | // ArmNN blockShape is [H, W] Cl asks for W, H |
| 58 | int32_t blockHeight = boost::numeric_cast<int32_t>(m_Data.m_Parameters.m_BlockShape[0]); |
| 59 | int32_t blockWidth = boost::numeric_cast<int32_t>(m_Data.m_Parameters.m_BlockShape[1]); |
| 60 | |
Nattapat Chaimanowong | 17fa2b4 | 2019-02-26 12:26:08 +0000 | [diff] [blame] | 61 | arm_compute::Size2D paddingLeftTop = BuildArmComputeSize2D( |
| 62 | m_Data.m_Parameters.m_PadList[1].first, m_Data.m_Parameters.m_PadList[0].first); |
| 63 | arm_compute::Size2D paddingRightBottom = BuildArmComputeSize2D( |
| 64 | m_Data.m_Parameters.m_PadList[1].second, m_Data.m_Parameters.m_PadList[0].second); |
Sadik Armagan | f446432 | 2018-12-20 16:19:12 +0000 | [diff] [blame] | 65 | |
| 66 | arm_compute::DataLayout aclDataLayout = ConvertDataLayout(m_Data.m_Parameters.m_DataLayout); |
| 67 | input.info()->set_data_layout(aclDataLayout); |
| 68 | output.info()->set_data_layout(aclDataLayout); |
| 69 | |
| 70 | m_SpaceToBatchLayer.configure(&input, |
| 71 | blockWidth, |
| 72 | blockHeight, |
Nattapat Chaimanowong | 17fa2b4 | 2019-02-26 12:26:08 +0000 | [diff] [blame] | 73 | paddingLeftTop, |
| 74 | paddingRightBottom, |
Sadik Armagan | f446432 | 2018-12-20 16:19:12 +0000 | [diff] [blame] | 75 | &output); |
| 76 | } |
| 77 | |
| 78 | void ClSpaceToBatchNdWorkload::Execute() const |
| 79 | { |
| 80 | ARMNN_SCOPED_PROFILING_EVENT_CL("ClSpaceToBatchNdWorkload_Execute"); |
| 81 | RunClFunction(m_SpaceToBatchLayer, CHECK_LOCATION()); |
| 82 | } |
| 83 | |
| 84 | } //namespace armnn |