ArmNN
 24.08
ClGatherNdWorkload Class Reference

#include <ClGatherNdWorkload.hpp>

Inheritance diagram for ClGatherNdWorkload:
[legend]
Collaboration diagram for ClGatherNdWorkload:
[legend]

Public Member Functions

 ClGatherNdWorkload (const GatherNdQueueDescriptor &descriptor, const WorkloadInfo &info, const arm_compute::CLCompileContext &clCompileContext)
 
virtual void Execute () const override
 
- Public Member Functions inherited from ClBaseWorkload< GatherNdQueueDescriptor >
 ClBaseWorkload (const GatherNdQueueDescriptor &descriptor, const WorkloadInfo &info)
 
void ReplaceInputTensorHandle (ITensorHandle *tensorHandle, unsigned int slot) override
 
void ReplaceOutputTensorHandle (ITensorHandle *tensorHandle, unsigned int slot) override
 
- Public Member Functions inherited from BaseWorkload< GatherNdQueueDescriptor >
 BaseWorkload (const GatherNdQueueDescriptor &descriptor, const WorkloadInfo &info)
 
virtual const std::string & GetName () const override
 
void ExecuteAsync (ExecutionData &executionData) override
 
void PostAllocationConfigure () override
 
const GatherNdQueueDescriptorGetData () const
 
arm::pipe::ProfilingGuid GetGuid () const final
 
virtual bool SupportsTensorHandleReplacement () const override
 
- Public Member Functions inherited from IWorkload
virtual ~IWorkload ()
 
virtual arm::pipe::ProfilingGuid GetGuid () const =0
 
virtual bool SupportsTensorHandleReplacement () const =0
 
virtual const std::string & GetName () const =0
 
virtual void RegisterDebugCallback (const DebugCallbackFunction &)
 
virtual armnn::Optional< armnn::MemoryRequirementsGetMemoryRequirements ()
 

Additional Inherited Members

- Protected Member Functions inherited from ClBaseWorkload< GatherNdQueueDescriptor >
virtual void Reconfigure ()
 
- Protected Attributes inherited from BaseWorkload< GatherNdQueueDescriptor >
GatherNdQueueDescriptor m_Data
 
const arm::pipe::ProfilingGuid m_Guid
 
const std::string m_Name
 

Detailed Description

Definition at line 22 of file ClGatherNdWorkload.hpp.

Constructor & Destructor Documentation

◆ ClGatherNdWorkload()

ClGatherNdWorkload ( const GatherNdQueueDescriptor descriptor,
const WorkloadInfo info,
const arm_compute::CLCompileContext &  clCompileContext 
)

Calculate flattened indices: m_FlattenedIndices = indices * m_FlattenedCoeff. This could be done using MatMul instead of multiplication followed by reduce sum operation, but GeMM does not support s32 at the moment.

Call Gather with adequate shapes

Definition at line 99 of file ClGatherNdWorkload.cpp.

102  : ClBaseWorkload<GatherNdQueueDescriptor>(descriptor, info)
103 {
104  m_Data.ValidateInputsOutputs("ClGatherNdWorkload", 2, 1);
105 
106  TensorInfo paramsInfo = info.m_InputTensorInfos[0];
107  TensorInfo indicesInfo = info.m_InputTensorInfos[1];
108  TensorInfo outputInfo = info.m_OutputTensorInfos[0];
109 
110  arm_compute::ICLTensor& input = static_cast<IClTensorHandle*>(m_Data.m_Inputs[0])->GetTensor();
111  arm_compute::ICLTensor& indices = static_cast<IClTensorHandle*>(m_Data.m_Inputs[1])->GetTensor();
112  arm_compute::ICLTensor& output = static_cast<IClTensorHandle*>(m_Data.m_Outputs[0])->GetTensor();
113 
114  // Calculate ND, K, W, C.
115  std::map<std::string, unsigned int> keyIndices = CalculateGatherNdKeyIndices(paramsInfo, indicesInfo);
116 
117  /// Calculate flattened indices: m_FlattenedIndices = indices * m_FlattenedCoeff.
118  /// This could be done using MatMul instead of multiplication followed by reduce sum operation,
119  /// but GeMM does not support s32 at the moment.
120 
121  // Prepare the tensor to store the output of the reduce_sum operation
122  armnn::TensorInfo flattenedIndices_Info = indicesInfo;
123  flattenedIndices_Info.SetShape({ keyIndices["W"] });
124  BuildArmComputeTensor(m_FlattenedIndices, flattenedIndices_Info);
125  armcomputetensorutils::InitialiseArmComputeTensorEmpty(m_FlattenedIndices);
126 
127  // Reshape indices into { W, ND }
128  indices.info()->set_tensor_shape(BuildArmComputeTensorShape({ keyIndices["W"], keyIndices["ND"] }));
129 
130  // Calculate the m_FlattenedCoeff
131  TensorShape paramsShape = paramsInfo.GetShape();
132  std::vector<int32_t> flattenedCoeff(keyIndices["ND"], 1);
133  for (unsigned int i = 1; i < keyIndices["ND"]; ++i)
134  {
135  flattenedCoeff[i - 1] = static_cast<int32_t>(paramsShape[i]);
136  }
137  for (unsigned int i = keyIndices["ND"] - 1; i > 0; --i)
138  {
139  flattenedCoeff[i - 1] *= flattenedCoeff[i];
140  }
141  armnn::TensorInfo flattenedCoeff_Info = indicesInfo;
142  flattenedCoeff_Info.SetShape({ keyIndices["ND"] });
143  BuildArmComputeTensor(m_FlattenedCoeff, flattenedCoeff_Info);
144  armcomputetensorutils::InitialiseArmComputeTensorEmpty(m_FlattenedCoeff);
145  CopyArmComputeClTensorData<int32_t>(m_FlattenedCoeff, flattenedCoeff.data());
146 
147  // Prepare the tensor to store the output of the multiplication
148  armnn::TensorInfo outputMul_Info = indicesInfo;
149  outputMul_Info.SetShape({ keyIndices["W"], keyIndices["ND"] });
150  BuildArmComputeTensor(m_OutputMul, outputMul_Info);
151  armcomputetensorutils::InitialiseArmComputeTensorEmpty(m_OutputMul);
152 
153  // Multiply
154  m_MulLayer.configure(clCompileContext,
155  &indices,
156  &m_FlattenedCoeff,
157  &m_OutputMul,
158  1.0f,
159  arm_compute::ConvertPolicy::WRAP,
160  arm_compute::RoundingPolicy::TO_ZERO,
161  arm_compute::ActivationLayerInfo());
162 
163  // Reduce Sum
164  const std::vector<unsigned int> armnnReduceAxes(1, 1);
165  arm_compute::Coordinates coords = BuildArmComputeReductionCoordinates(m_OutputMul.info()->num_dimensions(),
166  outputMul_Info.GetNumDimensions(),
167  armnnReduceAxes);
168  m_ReduceSumLayer.configure(clCompileContext,
169  &m_OutputMul,
170  &m_FlattenedIndices,
171  static_cast<unsigned int>(coords[0]),
172  arm_compute::ReductionOperation::SUM,
173  false);
174 
175  /// Call Gather with adequate shapes
176  // Reshape params into { K, C }
177  paramsInfo.SetShape({ keyIndices["K"], keyIndices["C"] });
178  input.info()->set_tensor_shape(BuildArmComputeTensorShape(paramsInfo.GetShape()));
179 
180  // Reshape output to have the shape given by gather { W, C }
181  // (the original outputInfo has the shape given by gatherNd)
182  armnn::TensorInfo outputGather_Info = outputInfo;
183  outputGather_Info.SetShape({ keyIndices["W"], keyIndices["C"] });
184  BuildArmComputeTensor(m_OutputGather, outputGather_Info);
185  armcomputetensorutils::InitialiseArmComputeTensorEmpty(m_OutputGather);
186  {
187  ARMNN_SCOPED_PROFILING_EVENT_CL_NAME_GUID("ClGatherNdWorkload_configure");
188  auto aclAxis = ComputeAclAxis(0, paramsInfo);
189  m_GatherLayer.configure(clCompileContext, &input, &m_FlattenedIndices, &m_OutputGather, aclAxis);
190  }
191 
192  // Reshape output to the original output shape
193  m_ReshapeLayer.configure(clCompileContext, &m_OutputGather, &output);
194 };

References armnn::CalculateGatherNdKeyIndices(), armnn::info, BaseWorkload< GatherNdQueueDescriptor >::m_Data, QueueDescriptor::m_Inputs, QueueDescriptor::m_Outputs, TensorInfo::SetShape(), and QueueDescriptor::ValidateInputsOutputs().

Member Function Documentation

◆ Execute()

void Execute ( ) const
overridevirtual

Implements IWorkload.

Definition at line 196 of file ClGatherNdWorkload.cpp.

197 {
198  ARMNN_SCOPED_PROFILING_EVENT_CL_NAME_GUID("ClGatherNdWorkload_Execute");
199  RunClFunction(m_MulLayer, CHECK_LOCATION());
200  RunClFunction(m_ReduceSumLayer, CHECK_LOCATION());
201  RunClFunction(m_GatherLayer, CHECK_LOCATION());
202  RunClFunction(m_ReshapeLayer, CHECK_LOCATION());
203 }

References ARMNN_SCOPED_PROFILING_EVENT_CL_NAME_GUID, CHECK_LOCATION, and armnn::RunClFunction().


The documentation for this class was generated from the following files:
armnn::QueueDescriptor::ValidateInputsOutputs
void ValidateInputsOutputs(const std::string &descName, unsigned int numExpectedIn, unsigned int numExpectedOut) const
Definition: WorkloadData.cpp:447
armnn::TensorInfo
Definition: Tensor.hpp:152
armnn::TensorInfo::GetNumDimensions
unsigned int GetNumDimensions() const
Definition: Tensor.hpp:197
CHECK_LOCATION
#define CHECK_LOCATION()
Definition: Exceptions.hpp:203
armnn::Coordinates
std::array< unsigned int, MaxNumOfTensorDimensions > Coordinates
Definition: InternalTypes.hpp:15
ARMNN_SCOPED_PROFILING_EVENT_CL_NAME_GUID
#define ARMNN_SCOPED_PROFILING_EVENT_CL_NAME_GUID(label)
Creates a profiling event that uses GetGuid() and GetName() from the calling class.
Definition: ClWorkloadUtils.hpp:36
armnn::CalculateGatherNdKeyIndices
std::map< std::string, unsigned int > CalculateGatherNdKeyIndices(TensorInfo inputInfo0, TensorInfo inputInfo1)
Calculates the key index values needed for GatherNd: N, ND, K, W, C (N is always 1)
Definition: WorkloadUtils.cpp:313
armnn::BoostLogSeverityMapping::info
@ info
armnn::QueueDescriptor::m_Outputs
std::vector< ITensorHandle * > m_Outputs
Definition: WorkloadData.hpp:27
armnn::BaseWorkload< GatherNdQueueDescriptor >::m_Data
GatherNdQueueDescriptor m_Data
Definition: Workload.hpp:89
armnn::RunClFunction
void RunClFunction(arm_compute::IFunction &function, const CheckLocation &location)
Definition: ClWorkloadUtils.hpp:167
armnn::TensorInfo::SetShape
void SetShape(const TensorShape &newShape)
Definition: Tensor.hpp:195
armnn::ComputeAclAxis
int ComputeAclAxis(const int &armnnAxis, const armnn::TensorInfo &tensor)
Function to convert ArmNN axis (left to right) to ACL axis (right to left) ranging from [-rank,...
Definition: ArmComputeUtils.hpp:246
armnn::QueueDescriptor::m_Inputs
std::vector< ITensorHandle * > m_Inputs
Definition: WorkloadData.hpp:26