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> |
James Conroy | 1f58f03 | 2021-04-27 17:13:27 +0100 | [diff] [blame] | 9 | #include <backendsCommon/TensorHandle.hpp> |
Mike Kelly | 831faed | 2018-11-28 11:52:08 +0000 | [diff] [blame] | 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 | |
Keith Davis | bcd860a | 2021-08-05 14:20:33 +0100 | [diff] [blame] | 20 | ClBatchToSpaceNdWorkload::ClBatchToSpaceNdWorkload(const BatchToSpaceNdQueueDescriptor& descriptor, |
Sadik Armagan | e944475 | 2020-12-02 11:28:58 +0000 | [diff] [blame] | 21 | const WorkloadInfo& info, |
| 22 | const arm_compute::CLCompileContext& clCompileContext) |
Keith Davis | bcd860a | 2021-08-05 14:20:33 +0100 | [diff] [blame] | 23 | : BaseWorkload<BatchToSpaceNdQueueDescriptor>(descriptor, info) |
Mike Kelly | 831faed | 2018-11-28 11:52:08 +0000 | [diff] [blame] | 24 | { |
Keith Davis | bcd860a | 2021-08-05 14:20:33 +0100 | [diff] [blame] | 25 | // Report Profiling Details |
| 26 | ARMNN_REPORT_PROFILING_WORKLOAD_DESC("ClBatchToSpaceWorkload_Construct", |
| 27 | descriptor.m_Parameters, |
| 28 | info, |
| 29 | this->GetGuid()); |
| 30 | |
Mike Kelly | 831faed | 2018-11-28 11:52:08 +0000 | [diff] [blame] | 31 | m_Data.ValidateInputsOutputs("ClBatchToSpaceNdWorkload", 1, 1); |
| 32 | |
| 33 | arm_compute::DataLayout aclDataLayout = ConvertDataLayout(m_Data.m_Parameters.m_DataLayout); |
| 34 | |
| 35 | arm_compute::ICLTensor& input = static_cast<IClTensorHandle*>(m_Data.m_Inputs[0])->GetTensor(); |
| 36 | input.info()->set_data_layout(aclDataLayout); |
| 37 | |
| 38 | // ArmNN blockShape is [H, W] Cl asks for W, H |
Keith Davis | bcd860a | 2021-08-05 14:20:33 +0100 | [diff] [blame] | 39 | int32_t blockHeight = armnn::numeric_cast<int32_t>(descriptor.m_Parameters.m_BlockShape[0]); |
| 40 | int32_t blockWidth = armnn::numeric_cast<int32_t>(descriptor.m_Parameters.m_BlockShape[1]); |
Mike Kelly | 831faed | 2018-11-28 11:52:08 +0000 | [diff] [blame] | 41 | |
| 42 | arm_compute::ICLTensor& output = static_cast<IClTensorHandle*>(m_Data.m_Outputs[0])->GetTensor(); |
| 43 | output.info()->set_data_layout(aclDataLayout); |
| 44 | |
Kevin May | 9f6862d | 2021-10-22 15:42:28 +0100 | [diff] [blame] | 45 | { |
| 46 | ARMNN_SCOPED_PROFILING_EVENT(Compute::Undefined, "ClBatchToSpaceNdWorkload_configure"); |
| 47 | m_Layer.configure(clCompileContext, &input, blockWidth, blockHeight, &output); |
| 48 | } |
Mike Kelly | 831faed | 2018-11-28 11:52:08 +0000 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | void ClBatchToSpaceNdWorkload::Execute() const |
| 52 | { |
Keith Davis | bcd860a | 2021-08-05 14:20:33 +0100 | [diff] [blame] | 53 | ARMNN_SCOPED_PROFILING_EVENT_CL_GUID("ClBatchToSpaceNdWorkload_Execute", this->GetGuid()); |
Mike Kelly | 831faed | 2018-11-28 11:52:08 +0000 | [diff] [blame] | 54 | RunClFunction(m_Layer, CHECK_LOCATION()); |
| 55 | } |
| 56 | |
| 57 | arm_compute::Status ClBatchToSpaceNdWorkloadValidate(const TensorInfo& input, |
| 58 | const TensorInfo& output, |
Keith Davis | bcd860a | 2021-08-05 14:20:33 +0100 | [diff] [blame] | 59 | const BatchToSpaceNdDescriptor& descriptor) |
| 60 | { |
| 61 | DataLayout dataLayout = descriptor.m_DataLayout; |
Mike Kelly | 831faed | 2018-11-28 11:52:08 +0000 | [diff] [blame] | 62 | const arm_compute::TensorInfo aclInputInfo = BuildArmComputeTensorInfo(input, dataLayout); |
| 63 | |
| 64 | // ArmNN blockShape is [H, W] Cl asks for W, H |
Keith Davis | bcd860a | 2021-08-05 14:20:33 +0100 | [diff] [blame] | 65 | int32_t blockHeight = armnn::numeric_cast<int32_t>(descriptor.m_BlockShape[0]); |
| 66 | int32_t blockWidth = armnn::numeric_cast<int32_t>(descriptor.m_BlockShape[1]); |
Mike Kelly | 831faed | 2018-11-28 11:52:08 +0000 | [diff] [blame] | 67 | |
| 68 | const arm_compute::TensorInfo aclOutputInfo = BuildArmComputeTensorInfo(output, dataLayout); |
| 69 | |
| 70 | const arm_compute::Status aclStatus = arm_compute::CLBatchToSpaceLayer::validate(&aclInputInfo, |
| 71 | blockWidth, |
| 72 | blockHeight, |
| 73 | &aclOutputInfo); |
| 74 | return aclStatus; |
| 75 | } |
| 76 | |
| 77 | } //namespace armnn |