James Conroy | 2dc0572 | 2019-09-19 17:00:31 +0100 | [diff] [blame] | 1 | // |
Teresa Charlin | 588cbdf | 2022-01-19 15:55:37 +0000 | [diff] [blame] | 2 | // Copyright © 2019 Arm Ltd and Contributors. All rights reserved. |
James Conroy | 2dc0572 | 2019-09-19 17:00:31 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "ClArgMinMaxWorkload.hpp" |
| 7 | #include "ClWorkloadUtils.hpp" |
| 8 | |
| 9 | #include <aclCommon/ArmComputeTensorUtils.hpp> |
| 10 | |
Colm Donelan | 0c47974 | 2021-12-10 12:43:54 +0000 | [diff] [blame] | 11 | #include <armnn/backends/TensorHandle.hpp> |
James Conroy | 2dc0572 | 2019-09-19 17:00:31 +0100 | [diff] [blame] | 12 | |
Matteo Martincigh | e011d20 | 2019-11-28 11:35:47 +0000 | [diff] [blame] | 13 | #include <armnnUtils/TensorUtils.hpp> |
Matthew Sloyan | 171214c | 2020-09-09 09:07:37 +0100 | [diff] [blame] | 14 | #include <armnn/utility/NumericCast.hpp> |
James Conroy | 2dc0572 | 2019-09-19 17:00:31 +0100 | [diff] [blame] | 15 | |
| 16 | #include <cl/ClTensorHandle.hpp> |
| 17 | #include <cl/ClLayerSupport.hpp> |
| 18 | |
| 19 | namespace |
| 20 | { |
| 21 | unsigned int CalcAclAxis(unsigned int numDimensions, unsigned int axisIndex) |
| 22 | { |
| 23 | return (numDimensions - axisIndex) - 1; |
| 24 | } |
| 25 | |
| 26 | } //namespace |
| 27 | |
| 28 | namespace armnn |
| 29 | { |
| 30 | |
| 31 | arm_compute::Status ClArgMinMaxWorkloadValidate(const TensorInfo& input, |
| 32 | const TensorInfo& output, |
| 33 | const ArgMinMaxDescriptor& descriptor) |
| 34 | { |
| 35 | const arm_compute::TensorInfo aclInput = armcomputetensorutils::BuildArmComputeTensorInfo(input); |
| 36 | const arm_compute::TensorInfo aclOutput = armcomputetensorutils::BuildArmComputeTensorInfo(output); |
| 37 | |
| 38 | auto numDims = input.GetNumDimensions(); |
| 39 | auto unsignedAxis = armnnUtils::GetUnsignedAxis(numDims, descriptor.m_Axis); |
Matthew Sloyan | 171214c | 2020-09-09 09:07:37 +0100 | [diff] [blame] | 40 | int aclAxis = armnn::numeric_cast<int>(CalcAclAxis(numDims, unsignedAxis)); |
James Conroy | 2dc0572 | 2019-09-19 17:00:31 +0100 | [diff] [blame] | 41 | |
| 42 | if (descriptor.m_Function == ArgMinMaxFunction::Max) |
| 43 | { |
| 44 | return arm_compute::CLArgMinMaxLayer::validate(&aclInput, aclAxis, &aclOutput, |
| 45 | arm_compute::ReductionOperation::ARG_IDX_MAX); |
| 46 | } |
| 47 | else |
| 48 | { |
| 49 | return arm_compute::CLArgMinMaxLayer::validate(&aclInput, aclAxis, &aclOutput, |
| 50 | arm_compute::ReductionOperation::ARG_IDX_MIN); |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | |
| 55 | ClArgMinMaxWorkload::ClArgMinMaxWorkload(const ArgMinMaxQueueDescriptor& descriptor, |
Sadik Armagan | e944475 | 2020-12-02 11:28:58 +0000 | [diff] [blame] | 56 | const WorkloadInfo& info, |
| 57 | const arm_compute::CLCompileContext& clCompileContext) |
Teresa Charlin | 588cbdf | 2022-01-19 15:55:37 +0000 | [diff] [blame] | 58 | : ClBaseWorkload<ArgMinMaxQueueDescriptor>(descriptor, info) |
James Conroy | 2dc0572 | 2019-09-19 17:00:31 +0100 | [diff] [blame] | 59 | { |
Keith Davis | bcd860a | 2021-08-05 14:20:33 +0100 | [diff] [blame] | 60 | // Report Profiling Details |
| 61 | ARMNN_REPORT_PROFILING_WORKLOAD_DESC("ClArgMinMaxWorkload_Construct", |
| 62 | descriptor.m_Parameters, |
| 63 | info, |
| 64 | this->GetGuid()); |
| 65 | |
James Conroy | 2dc0572 | 2019-09-19 17:00:31 +0100 | [diff] [blame] | 66 | arm_compute::ICLTensor& input = static_cast<IClTensorHandle*>(this->m_Data.m_Inputs[0])->GetTensor(); |
| 67 | arm_compute::ICLTensor& output = static_cast<IClTensorHandle*>(this->m_Data.m_Outputs[0])->GetTensor(); |
| 68 | |
| 69 | auto numDims = info.m_InputTensorInfos[0].GetNumDimensions(); |
| 70 | auto unsignedAxis = armnnUtils::GetUnsignedAxis(numDims, m_Data.m_Parameters.m_Axis); |
Matthew Sloyan | 171214c | 2020-09-09 09:07:37 +0100 | [diff] [blame] | 71 | int aclAxis = armnn::numeric_cast<int>(CalcAclAxis(numDims, unsignedAxis)); |
James Conroy | 2dc0572 | 2019-09-19 17:00:31 +0100 | [diff] [blame] | 72 | |
James Conroy | 2dc0572 | 2019-09-19 17:00:31 +0100 | [diff] [blame] | 73 | { |
Kevin May | 9f6862d | 2021-10-22 15:42:28 +0100 | [diff] [blame] | 74 | ARMNN_SCOPED_PROFILING_EVENT(Compute::Undefined, "ClArgMinMaxWorkload_configure"); |
| 75 | if (m_Data.m_Parameters.m_Function == ArgMinMaxFunction::Max) |
| 76 | { |
Cathal Corbett | ea660e1 | 2022-06-08 17:36:13 +0100 | [diff] [blame] | 77 | m_ArgMinMaxLayer.configure(clCompileContext, |
| 78 | &input, |
| 79 | aclAxis, |
| 80 | &output, |
| 81 | arm_compute::ReductionOperation::ARG_IDX_MAX); |
Kevin May | 9f6862d | 2021-10-22 15:42:28 +0100 | [diff] [blame] | 82 | } |
| 83 | else |
| 84 | { |
| 85 | m_ArgMinMaxLayer.configure(clCompileContext, |
| 86 | &input, |
| 87 | aclAxis, |
| 88 | &output, |
| 89 | arm_compute::ReductionOperation::ARG_IDX_MIN); |
| 90 | } |
James Conroy | 2dc0572 | 2019-09-19 17:00:31 +0100 | [diff] [blame] | 91 | } |
| 92 | } |
| 93 | |
| 94 | void ClArgMinMaxWorkload::Execute() const |
| 95 | { |
Keith Davis | bcd860a | 2021-08-05 14:20:33 +0100 | [diff] [blame] | 96 | ARMNN_SCOPED_PROFILING_EVENT_CL_GUID("ClArgMinMaxWorkload_Execute", this->GetGuid()); |
James Conroy | 2dc0572 | 2019-09-19 17:00:31 +0100 | [diff] [blame] | 97 | RunClFunction(m_ArgMinMaxLayer, CHECK_LOCATION()); |
| 98 | } |
| 99 | |
| 100 | } //namespace armnn |
| 101 | |