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 | |
Sadik Armagan | e944475 | 2020-12-02 11:28:58 +0000 | [diff] [blame] | 45 | m_Layer.configure(clCompileContext, &input, blockWidth, blockHeight, &output); |
Mike Kelly | 831faed | 2018-11-28 11:52:08 +0000 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | void ClBatchToSpaceNdWorkload::Execute() const |
| 49 | { |
Keith Davis | bcd860a | 2021-08-05 14:20:33 +0100 | [diff] [blame] | 50 | ARMNN_SCOPED_PROFILING_EVENT_CL_GUID("ClBatchToSpaceNdWorkload_Execute", this->GetGuid()); |
Mike Kelly | 831faed | 2018-11-28 11:52:08 +0000 | [diff] [blame] | 51 | RunClFunction(m_Layer, CHECK_LOCATION()); |
| 52 | } |
| 53 | |
| 54 | arm_compute::Status ClBatchToSpaceNdWorkloadValidate(const TensorInfo& input, |
| 55 | const TensorInfo& output, |
Keith Davis | bcd860a | 2021-08-05 14:20:33 +0100 | [diff] [blame] | 56 | const BatchToSpaceNdDescriptor& descriptor) |
| 57 | { |
| 58 | DataLayout dataLayout = descriptor.m_DataLayout; |
Mike Kelly | 831faed | 2018-11-28 11:52:08 +0000 | [diff] [blame] | 59 | const arm_compute::TensorInfo aclInputInfo = BuildArmComputeTensorInfo(input, dataLayout); |
| 60 | |
| 61 | // ArmNN blockShape is [H, W] Cl asks for W, H |
Keith Davis | bcd860a | 2021-08-05 14:20:33 +0100 | [diff] [blame] | 62 | int32_t blockHeight = armnn::numeric_cast<int32_t>(descriptor.m_BlockShape[0]); |
| 63 | int32_t blockWidth = armnn::numeric_cast<int32_t>(descriptor.m_BlockShape[1]); |
Mike Kelly | 831faed | 2018-11-28 11:52:08 +0000 | [diff] [blame] | 64 | |
| 65 | const arm_compute::TensorInfo aclOutputInfo = BuildArmComputeTensorInfo(output, dataLayout); |
| 66 | |
| 67 | const arm_compute::Status aclStatus = arm_compute::CLBatchToSpaceLayer::validate(&aclInputInfo, |
| 68 | blockWidth, |
| 69 | blockHeight, |
| 70 | &aclOutputInfo); |
| 71 | return aclStatus; |
| 72 | } |
| 73 | |
| 74 | } //namespace armnn |