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