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 | |
| 11 | #include <backendsCommon/CpuTensorHandle.hpp> |
| 12 | |
Matteo Martincigh | e011d20 | 2019-11-28 11:35:47 +0000 | [diff] [blame] | 13 | #include <armnnUtils/TensorUtils.hpp> |
James Conroy | 2dc0572 | 2019-09-19 17:00:31 +0100 | [diff] [blame] | 14 | |
| 15 | #include <cl/ClTensorHandle.hpp> |
| 16 | #include <cl/ClLayerSupport.hpp> |
| 17 | |
| 18 | namespace |
| 19 | { |
| 20 | unsigned int CalcAclAxis(unsigned int numDimensions, unsigned int axisIndex) |
| 21 | { |
| 22 | return (numDimensions - axisIndex) - 1; |
| 23 | } |
| 24 | |
| 25 | } //namespace |
| 26 | |
| 27 | namespace armnn |
| 28 | { |
| 29 | |
| 30 | arm_compute::Status ClArgMinMaxWorkloadValidate(const TensorInfo& input, |
| 31 | const TensorInfo& output, |
| 32 | const ArgMinMaxDescriptor& descriptor) |
| 33 | { |
| 34 | const arm_compute::TensorInfo aclInput = armcomputetensorutils::BuildArmComputeTensorInfo(input); |
| 35 | const arm_compute::TensorInfo aclOutput = armcomputetensorutils::BuildArmComputeTensorInfo(output); |
| 36 | |
| 37 | auto numDims = input.GetNumDimensions(); |
| 38 | auto unsignedAxis = armnnUtils::GetUnsignedAxis(numDims, descriptor.m_Axis); |
| 39 | int aclAxis = boost::numeric_cast<int>(CalcAclAxis(numDims, unsignedAxis)); |
| 40 | |
| 41 | if (descriptor.m_Function == ArgMinMaxFunction::Max) |
| 42 | { |
| 43 | return arm_compute::CLArgMinMaxLayer::validate(&aclInput, aclAxis, &aclOutput, |
| 44 | arm_compute::ReductionOperation::ARG_IDX_MAX); |
| 45 | } |
| 46 | else |
| 47 | { |
| 48 | return arm_compute::CLArgMinMaxLayer::validate(&aclInput, aclAxis, &aclOutput, |
| 49 | arm_compute::ReductionOperation::ARG_IDX_MIN); |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | |
| 54 | ClArgMinMaxWorkload::ClArgMinMaxWorkload(const ArgMinMaxQueueDescriptor& descriptor, |
| 55 | const WorkloadInfo& info) |
| 56 | : BaseWorkload<ArgMinMaxQueueDescriptor>(descriptor, info) |
| 57 | { |
| 58 | arm_compute::ICLTensor& input = static_cast<IClTensorHandle*>(this->m_Data.m_Inputs[0])->GetTensor(); |
| 59 | arm_compute::ICLTensor& output = static_cast<IClTensorHandle*>(this->m_Data.m_Outputs[0])->GetTensor(); |
| 60 | |
| 61 | auto numDims = info.m_InputTensorInfos[0].GetNumDimensions(); |
| 62 | auto unsignedAxis = armnnUtils::GetUnsignedAxis(numDims, m_Data.m_Parameters.m_Axis); |
| 63 | int aclAxis = boost::numeric_cast<int>(CalcAclAxis(numDims, unsignedAxis)); |
| 64 | |
| 65 | if (m_Data.m_Parameters.m_Function == ArgMinMaxFunction::Max) |
| 66 | { |
| 67 | m_ArgMinMaxLayer.configure(&input, aclAxis, &output, arm_compute::ReductionOperation::ARG_IDX_MAX); |
| 68 | } |
| 69 | else |
| 70 | { |
| 71 | m_ArgMinMaxLayer.configure(&input, aclAxis, &output, arm_compute::ReductionOperation::ARG_IDX_MIN); |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | void ClArgMinMaxWorkload::Execute() const |
| 76 | { |
| 77 | ARMNN_SCOPED_PROFILING_EVENT_CL("ClArgMinMaxWorkload_Execute"); |
| 78 | RunClFunction(m_ArgMinMaxLayer, CHECK_LOCATION()); |
| 79 | } |
| 80 | |
| 81 | } //namespace armnn |
| 82 | |