Mike Kelly | 831faed | 2018-11-28 11:52:08 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "ClBatchToSpaceNdWorkload.hpp" |
| 7 | |
| 8 | #include <cl/ClTensorHandle.hpp> |
| 9 | #include <backendsCommon/CpuTensorHandle.hpp> |
| 10 | #include <aclCommon/ArmComputeTensorUtils.hpp> |
| 11 | |
Matthew Sloyan | 171214c | 2020-09-09 09:07:37 +0100 | [diff] [blame] | 12 | #include <armnn/utility/NumericCast.hpp> |
| 13 | |
Mike Kelly | 831faed | 2018-11-28 11:52:08 +0000 | [diff] [blame] | 14 | #include "ClWorkloadUtils.hpp" |
| 15 | |
| 16 | namespace armnn |
| 17 | { |
| 18 | using namespace armcomputetensorutils; |
| 19 | |
| 20 | ClBatchToSpaceNdWorkload::ClBatchToSpaceNdWorkload(const BatchToSpaceNdQueueDescriptor& desc, |
| 21 | const WorkloadInfo& info) |
| 22 | : BaseWorkload<BatchToSpaceNdQueueDescriptor>(desc, info) |
| 23 | { |
| 24 | m_Data.ValidateInputsOutputs("ClBatchToSpaceNdWorkload", 1, 1); |
| 25 | |
| 26 | arm_compute::DataLayout aclDataLayout = ConvertDataLayout(m_Data.m_Parameters.m_DataLayout); |
| 27 | |
| 28 | arm_compute::ICLTensor& input = static_cast<IClTensorHandle*>(m_Data.m_Inputs[0])->GetTensor(); |
| 29 | input.info()->set_data_layout(aclDataLayout); |
| 30 | |
| 31 | // ArmNN blockShape is [H, W] Cl asks for W, H |
Matthew Sloyan | 171214c | 2020-09-09 09:07:37 +0100 | [diff] [blame] | 32 | int32_t blockHeight = armnn::numeric_cast<int32_t>(desc.m_Parameters.m_BlockShape[0]); |
| 33 | int32_t blockWidth = armnn::numeric_cast<int32_t>(desc.m_Parameters.m_BlockShape[1]); |
Mike Kelly | 831faed | 2018-11-28 11:52:08 +0000 | [diff] [blame] | 34 | |
| 35 | arm_compute::ICLTensor& output = static_cast<IClTensorHandle*>(m_Data.m_Outputs[0])->GetTensor(); |
| 36 | output.info()->set_data_layout(aclDataLayout); |
| 37 | |
| 38 | m_Layer.configure(&input, blockWidth, blockHeight, &output); |
| 39 | } |
| 40 | |
| 41 | void ClBatchToSpaceNdWorkload::Execute() const |
| 42 | { |
| 43 | ARMNN_SCOPED_PROFILING_EVENT_CL("ClBatchToSpaceNdWorkload_Execute"); |
| 44 | RunClFunction(m_Layer, CHECK_LOCATION()); |
| 45 | } |
| 46 | |
| 47 | arm_compute::Status ClBatchToSpaceNdWorkloadValidate(const TensorInfo& input, |
| 48 | const TensorInfo& output, |
| 49 | const BatchToSpaceNdDescriptor& desc) { |
| 50 | DataLayout dataLayout = desc.m_DataLayout; |
| 51 | const arm_compute::TensorInfo aclInputInfo = BuildArmComputeTensorInfo(input, dataLayout); |
| 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_BlockShape[0]); |
| 55 | int32_t blockWidth = armnn::numeric_cast<int32_t>(desc.m_BlockShape[1]); |
Mike Kelly | 831faed | 2018-11-28 11:52:08 +0000 | [diff] [blame] | 56 | |
| 57 | const arm_compute::TensorInfo aclOutputInfo = BuildArmComputeTensorInfo(output, dataLayout); |
| 58 | |
| 59 | const arm_compute::Status aclStatus = arm_compute::CLBatchToSpaceLayer::validate(&aclInputInfo, |
| 60 | blockWidth, |
| 61 | blockHeight, |
| 62 | &aclOutputInfo); |
| 63 | return aclStatus; |
| 64 | } |
| 65 | |
| 66 | } //namespace armnn |