James Conroy | 2dc0572 | 2019-09-19 17:00:31 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2019 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "ClArgMinMaxWorkload.hpp" |
| 7 | #include "ClWorkloadUtils.hpp" |
| 8 | |
| 9 | #include <aclCommon/ArmComputeTensorUtils.hpp> |
| 10 | |
James Conroy | 1f58f03 | 2021-04-27 17:13:27 +0100 | [diff] [blame] | 11 | #include <backendsCommon/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) |
James Conroy | 2dc0572 | 2019-09-19 17:00:31 +0100 | [diff] [blame] | 58 | : BaseWorkload<ArgMinMaxQueueDescriptor>(descriptor, info) |
| 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 | { |
| 77 | m_ArgMinMaxLayer.configure(&input, aclAxis, &output, arm_compute::ReductionOperation::ARG_IDX_MAX); |
| 78 | } |
| 79 | else |
| 80 | { |
| 81 | m_ArgMinMaxLayer.configure(clCompileContext, |
| 82 | &input, |
| 83 | aclAxis, |
| 84 | &output, |
| 85 | arm_compute::ReductionOperation::ARG_IDX_MIN); |
| 86 | } |
James Conroy | 2dc0572 | 2019-09-19 17:00:31 +0100 | [diff] [blame] | 87 | } |
| 88 | } |
| 89 | |
| 90 | void ClArgMinMaxWorkload::Execute() const |
| 91 | { |
Keith Davis | bcd860a | 2021-08-05 14:20:33 +0100 | [diff] [blame] | 92 | ARMNN_SCOPED_PROFILING_EVENT_CL_GUID("ClArgMinMaxWorkload_Execute", this->GetGuid()); |
James Conroy | 2dc0572 | 2019-09-19 17:00:31 +0100 | [diff] [blame] | 93 | RunClFunction(m_ArgMinMaxLayer, CHECK_LOCATION()); |
| 94 | } |
| 95 | |
| 96 | } //namespace armnn |
| 97 | |