xref: /aosp_15_r20/external/armnn/src/backends/cl/workloads/ClGatherWorkload.cpp (revision 89c4ff92f2867872bb9e2354d150bf0c8c502810)
1 //
2 // Copyright © 2020 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #include "ClGatherWorkload.hpp"
7 #include "ClWorkloadUtils.hpp"
8 #include <aclCommon/ArmComputeUtils.hpp>
9 #include <cl/ClTensorHandle.hpp>
10 
11 using namespace armnn::armcomputetensorutils;
12 
13 namespace armnn
14 {
ClGatherWorkloadValidate(const TensorInfo & input,const TensorInfo & indices,const TensorInfo & output,const GatherDescriptor & descriptor)15 arm_compute::Status ClGatherWorkloadValidate(const TensorInfo& input,
16                                              const TensorInfo& indices,
17                                              const TensorInfo& output,
18                                              const GatherDescriptor& descriptor)
19 {
20     const arm_compute::TensorInfo aclInput   = BuildArmComputeTensorInfo(input);
21     const arm_compute::TensorInfo aclIndices = BuildArmComputeTensorInfo(indices);
22     const arm_compute::TensorInfo aclOutput  = BuildArmComputeTensorInfo(output);
23 
24     int aclAxis = ComputeAclAxis(descriptor.m_Axis, input);
25 
26     return arm_compute::CLGather::validate(&aclInput, &aclIndices, &aclOutput, aclAxis);
27 }
28 
ClGatherWorkload(const GatherQueueDescriptor & descriptor,const WorkloadInfo & info,const arm_compute::CLCompileContext & clCompileContext)29 ClGatherWorkload::ClGatherWorkload(const GatherQueueDescriptor& descriptor,
30                                    const WorkloadInfo& info,
31                                    const arm_compute::CLCompileContext& clCompileContext)
32         : ClBaseWorkload<GatherQueueDescriptor>(descriptor, info)
33 {
34     // Report Profiling Details
35     ARMNN_REPORT_PROFILING_WORKLOAD_DESC("ClGatherWorkload_Construct",
36                                          descriptor.m_Parameters,
37                                          info,
38                                          this->GetGuid());
39 
40     m_Data.ValidateInputsOutputs("ClGatherWorkload", 2, 1);
41 
42     arm_compute::ICLTensor& input    = static_cast<IClTensorHandle*>(m_Data.m_Inputs[0])->GetTensor();
43     arm_compute::ICLTensor& indices  = static_cast<IClTensorHandle*>(m_Data.m_Inputs[1])->GetTensor();
44     arm_compute::ICLTensor& output   = static_cast<IClTensorHandle*>(m_Data.m_Outputs[0])->GetTensor();
45 
46     int aclAxis = ComputeAclAxis(descriptor.m_Parameters.m_Axis, info.m_InputTensorInfos[0]);
47 
48     {
49         ARMNN_SCOPED_PROFILING_EVENT(Compute::Undefined, "ClGatherWorkload_configure");
50         m_Layer.configure(clCompileContext, &input, &indices, &output, aclAxis);
51     }
52 };
53 
Execute() const54 void ClGatherWorkload::Execute() const
55 {
56     ARMNN_SCOPED_PROFILING_EVENT_CL_GUID("ClGatherWorkload_Execute", this->GetGuid());
57     RunClFunction(m_Layer, CHECK_LOCATION());
58 }
59 } // namespace armnn
60