From ae050524109f1ce827962665436ef7430f2ac479 Mon Sep 17 00:00:00 2001 From: David Monahan Date: Wed, 22 Mar 2023 16:48:58 +0000 Subject: IVGCVSW-7255 Update Doxygen Documentation and publish on GitHub. * Updating Doxygen documentation for 23.02 release. Signed-off-by: David Monahan Change-Id: I545574ff7664b4595d2fe6a91a3c35d2ad55df82 --- 23.02/classarmnn_1_1_cl_gather_nd_workload.xhtml | 184 ++++++++++++++++++----- 1 file changed, 147 insertions(+), 37 deletions(-) (limited to '23.02/classarmnn_1_1_cl_gather_nd_workload.xhtml') diff --git a/23.02/classarmnn_1_1_cl_gather_nd_workload.xhtml b/23.02/classarmnn_1_1_cl_gather_nd_workload.xhtml index 028cb9e242..e0c87c9da3 100644 --- a/23.02/classarmnn_1_1_cl_gather_nd_workload.xhtml +++ b/23.02/classarmnn_1_1_cl_gather_nd_workload.xhtml @@ -8,7 +8,7 @@ - + ArmNN: ClGatherNdWorkload Class Reference @@ -19,9 +19,6 @@ - @@ -30,7 +27,8 @@ extensions: ["tex2jax.js"], jax: ["input/TeX","output/HTML-CSS"], }); - + + @@ -51,18 +49,21 @@ - + +/* @license-end */
@@ -76,7 +77,9 @@ $(function() {
@@ -111,13 +114,13 @@ Inheritance diagram for ClGatherNdWorkload:
ClBaseWorkload< GatherNdQueueDescriptor > BaseWorkload< GatherNdQueueDescriptor > -IWorkload - - +IWorkload + + - + @@ -144,6 +147,10 @@ Public Member Functions + + + + @@ -196,26 +203,107 @@ Additional Inherited Members

Public Member Functions

 ClGatherNdWorkload (const GatherNdQueueDescriptor &descriptor, const WorkloadInfo &info, const arm_compute::CLCompileContext &clCompileContext)
 ClGatherNdWorkload (const GatherNdQueueDescriptor &descriptor, const WorkloadInfo &info, const arm_compute::CLCompileContext &clCompileContext)
 
virtual void Execute () const override
 
- Public Member Functions inherited from IWorkload
virtual ~IWorkload ()
 
virtual arm::pipe::ProfilingGuid GetGuid () const =0
 
virtual bool SupportsTensorHandleReplacement () const =0
 
virtual void RegisterDebugCallback (const DebugCallbackFunction &)
 
virtual armnn::Optional< armnn::MemoryRequirementsGetMemoryRequirements ()

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

+

Call Gather with adequate shapes

Definition at line 99 of file ClGatherNdWorkload.cpp.

- -

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

-
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  ARMNN_ASSERT_MSG(indicesInfo.GetDataType() == DataType::Signed32,
146  "flattenedCoeff must be same data type as m_FlattenedCoeff");
147  CopyArmComputeClTensorData<int32_t>(m_FlattenedCoeff, flattenedCoeff.data());
148 
149  // Prepare the tensor to store the output of the multiplication
150  armnn::TensorInfo outputMul_Info = indicesInfo;
151  outputMul_Info.SetShape({ keyIndices["W"], keyIndices["ND"] });
152  BuildArmComputeTensor(m_OutputMul, outputMul_Info);
153  armcomputetensorutils::InitialiseArmComputeTensorEmpty(m_OutputMul);
154 
155  // Multiply
156  m_MulLayer.configure(clCompileContext,
157  &indices,
158  &m_FlattenedCoeff,
159  &m_OutputMul,
160  1.0f,
161  arm_compute::ConvertPolicy::WRAP,
162  arm_compute::RoundingPolicy::TO_ZERO,
163  arm_compute::ActivationLayerInfo());
164 
165  // Reduce Sum
166  const std::vector<unsigned int> armnnReduceAxes(1, 1);
167  arm_compute::Coordinates coords = BuildArmComputeReductionCoordinates(m_OutputMul.info()->num_dimensions(),
168  outputMul_Info.GetNumDimensions(),
169  armnnReduceAxes);
170  m_ReduceSumLayer.configure(clCompileContext,
171  &m_OutputMul,
172  &m_FlattenedIndices,
173  static_cast<unsigned int>(coords[0]),
174  arm_compute::ReductionOperation::SUM,
175  false);
176 
177  /// Call Gather with adequate shapes
178  // Reshape params into { K, C }
179  paramsInfo.SetShape({ keyIndices["K"], keyIndices["C"] });
180  input.info()->set_tensor_shape(BuildArmComputeTensorShape(paramsInfo.GetShape()));
181 
182  // Reshape output to have the shape given by gather { W, C }
183  // (the original outputInfo has the shape given by gatherNd)
184  armnn::TensorInfo outputGather_Info = outputInfo;
185  outputGather_Info.SetShape({ keyIndices["W"], keyIndices["C"] });
186  BuildArmComputeTensor(m_OutputGather, outputGather_Info);
187  armcomputetensorutils::InitialiseArmComputeTensorEmpty(m_OutputGather);
188  {
189  ARMNN_SCOPED_PROFILING_EVENT(Compute::Undefined, "ClGatherNdWorkload_configure");
190  auto aclAxis = ComputeAclAxis(0, paramsInfo);
191  m_GatherLayer.configure(clCompileContext, &input, &m_FlattenedIndices, &m_OutputGather, aclAxis);
192  }
193 
194  // Reshape output to the original output shape
195  m_ReshapeLayer.configure(clCompileContext, &m_OutputGather, &output);
196 };
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...
-
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) ...
- - -
std::array< unsigned int, MaxNumOfTensorDimensions > Coordinates
-
void ValidateInputsOutputs(const std::string &descName, unsigned int numExpectedIn, unsigned int numExpectedOut) const
-
#define ARMNN_SCOPED_PROFILING_EVENT(backendId, name)
Definition: Profiling.hpp:220
-
void SetShape(const TensorShape &newShape)
Definition: Tensor.hpp:193
-
#define ARMNN_ASSERT_MSG(COND, MSG)
Definition: Assert.hpp:15
- - -
std::vector< ITensorHandle * > m_Outputs
- -
std::vector< ITensorHandle * > m_Inputs
+
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  ARMNN_ASSERT_MSG(indicesInfo.GetDataType() == DataType::Signed32,
+
146  "flattenedCoeff must be same data type as m_FlattenedCoeff");
+
147  CopyArmComputeClTensorData<int32_t>(m_FlattenedCoeff, flattenedCoeff.data());
+
148 
+
149  // Prepare the tensor to store the output of the multiplication
+
150  armnn::TensorInfo outputMul_Info = indicesInfo;
+
151  outputMul_Info.SetShape({ keyIndices["W"], keyIndices["ND"] });
+
152  BuildArmComputeTensor(m_OutputMul, outputMul_Info);
+
153  armcomputetensorutils::InitialiseArmComputeTensorEmpty(m_OutputMul);
+
154 
+
155  // Multiply
+
156  m_MulLayer.configure(clCompileContext,
+
157  &indices,
+
158  &m_FlattenedCoeff,
+
159  &m_OutputMul,
+
160  1.0f,
+
161  arm_compute::ConvertPolicy::WRAP,
+
162  arm_compute::RoundingPolicy::TO_ZERO,
+
163  arm_compute::ActivationLayerInfo());
+
164 
+
165  // Reduce Sum
+
166  const std::vector<unsigned int> armnnReduceAxes(1, 1);
+
167  arm_compute::Coordinates coords = BuildArmComputeReductionCoordinates(m_OutputMul.info()->num_dimensions(),
+
168  outputMul_Info.GetNumDimensions(),
+
169  armnnReduceAxes);
+
170  m_ReduceSumLayer.configure(clCompileContext,
+
171  &m_OutputMul,
+
172  &m_FlattenedIndices,
+
173  static_cast<unsigned int>(coords[0]),
+
174  arm_compute::ReductionOperation::SUM,
+
175  false);
+
176 
+
177  /// Call Gather with adequate shapes
+
178  // Reshape params into { K, C }
+
179  paramsInfo.SetShape({ keyIndices["K"], keyIndices["C"] });
+
180  input.info()->set_tensor_shape(BuildArmComputeTensorShape(paramsInfo.GetShape()));
+
181 
+
182  // Reshape output to have the shape given by gather { W, C }
+
183  // (the original outputInfo has the shape given by gatherNd)
+
184  armnn::TensorInfo outputGather_Info = outputInfo;
+
185  outputGather_Info.SetShape({ keyIndices["W"], keyIndices["C"] });
+
186  BuildArmComputeTensor(m_OutputGather, outputGather_Info);
+
187  armcomputetensorutils::InitialiseArmComputeTensorEmpty(m_OutputGather);
+
188  {
+
189  ARMNN_SCOPED_PROFILING_EVENT(Compute::Undefined, "ClGatherNdWorkload_configure");
+
190  auto aclAxis = ComputeAclAxis(0, paramsInfo);
+
191  m_GatherLayer.configure(clCompileContext, &input, &m_FlattenedIndices, &m_OutputGather, aclAxis);
+
192  }
+
193 
+
194  // Reshape output to the original output shape
+
195  m_ReshapeLayer.configure(clCompileContext, &m_OutputGather, &output);
+
196 };
+

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

+

Member Function Documentation

@@ -245,13 +333,16 @@ Additional Inherited Members

Implements IWorkload.

Definition at line 198 of file ClGatherNdWorkload.cpp.

- -

References ARMNN_SCOPED_PROFILING_EVENT_CL_GUID, CHECK_LOCATION, BaseWorkload< GatherNdQueueDescriptor >::GetGuid(), and armnn::RunClFunction().

-
199 {
200  ARMNN_SCOPED_PROFILING_EVENT_CL_GUID("ClGatherNdWorkload_Execute", this->GetGuid());
201  RunClFunction(m_MulLayer, CHECK_LOCATION());
202  RunClFunction(m_ReduceSumLayer, CHECK_LOCATION());
203  RunClFunction(m_GatherLayer, CHECK_LOCATION());
204  RunClFunction(m_ReshapeLayer, CHECK_LOCATION());
205 }
#define ARMNN_SCOPED_PROFILING_EVENT_CL_GUID(name, guid)
-
void RunClFunction(arm_compute::IFunction &function, const CheckLocation &location)
-
arm::pipe::ProfilingGuid GetGuid() const final
Definition: Workload.hpp:61
-
#define CHECK_LOCATION()
Definition: Exceptions.hpp:203
+
199 {
+
200  ARMNN_SCOPED_PROFILING_EVENT_CL_GUID("ClGatherNdWorkload_Execute", this->GetGuid());
+
201  RunClFunction(m_MulLayer, CHECK_LOCATION());
+
202  RunClFunction(m_ReduceSumLayer, CHECK_LOCATION());
+
203  RunClFunction(m_GatherLayer, CHECK_LOCATION());
+
204  RunClFunction(m_ReshapeLayer, CHECK_LOCATION());
+
205 }
+

References ARMNN_SCOPED_PROFILING_EVENT_CL_GUID, CHECK_LOCATION, BaseWorkload< GatherNdQueueDescriptor >::GetGuid(), and armnn::RunClFunction().

+

The documentation for this class was generated from the following files: +
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)
+
arm::pipe::ProfilingGuid GetGuid() const final
Definition: Workload.hpp:61
+
void ValidateInputsOutputs(const std::string &descName, unsigned int numExpectedIn, unsigned int numExpectedOut) const
+
#define CHECK_LOCATION()
Definition: Exceptions.hpp:203
+
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,...
+ + +
unsigned int GetNumDimensions() const
Definition: Tensor.hpp:195
+
#define ARMNN_SCOPED_PROFILING_EVENT(backendId, name)
Definition: Profiling.hpp:220
+ +
void RunClFunction(arm_compute::IFunction &function, const CheckLocation &location)
+ +
#define ARMNN_ASSERT_MSG(COND, MSG)
Definition: Assert.hpp:15
+
std::vector< ITensorHandle * > m_Outputs
+
void SetShape(const TensorShape &newShape)
Definition: Tensor.hpp:193
+
#define ARMNN_SCOPED_PROFILING_EVENT_CL_GUID(name, guid)
+
std::array< unsigned int, MaxNumOfTensorDimensions > Coordinates
+
std::vector< ITensorHandle * > m_Inputs
+ -- cgit v1.2.1