ArmNN
 24.08
ClStackWorkload.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2019-2023 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 #include "ClStackWorkload.hpp"
6 #include "ClWorkloadUtils.hpp"
11 #include <cl/ClTensorHandle.hpp>
12 #include <cl/ClLayerSupport.hpp>
13 
14 #include <arm_compute/core/Types.h>
15 
16 namespace armnn
17 {
18 using namespace armcomputetensorutils;
19 
20 namespace
21 {
22 int CalcAxis(const unsigned int axis, const unsigned int inputDimensions)
23 {
24  const int intAxis = armnn::numeric_cast<int>(axis);
25  return armnn::numeric_cast<int>(inputDimensions) - intAxis;
26 }
27 } //namespace
28 
29 arm_compute::Status ClStackWorkloadValidate(const std::vector<const TensorInfo*>& inputs,
30  const TensorInfo& output,
31  const StackDescriptor& descriptor)
32 {
33  std::vector<arm_compute::ITensorInfo*> aclInputPtrs;
34  arm_compute::TensorInfo aclInputInfo;
35  for (const TensorInfo* input : inputs)
36  {
37  aclInputInfo = BuildArmComputeTensorInfo(*input);
38  aclInputPtrs.emplace_back(&aclInputInfo);
39  }
40  const arm_compute::TensorInfo aclOutputInfo = BuildArmComputeTensorInfo(output);
41 
42  int aclAxis = CalcAxis(descriptor.m_Axis, descriptor.m_InputShape.GetNumDimensions());
43 
44  return arm_compute::CLStackLayer::validate(aclInputPtrs, aclAxis, &aclOutputInfo);
45 }
46 
48  const WorkloadInfo& info,
49  const arm_compute::CLCompileContext& clCompileContext)
51 {
52  // Report Profiling Details
53  ARMNN_REPORT_PROFILING_WORKLOAD_DESC("ClStackWorkload_Construct",
54  descriptor.m_Parameters,
55  info,
56  this->GetGuid());
57 
58  std::vector<arm_compute::ICLTensor*> aclInputs;
59  for (auto input : m_Data.m_Inputs)
60  {
61  arm_compute::ICLTensor& aclInput = armnn::PolymorphicPointerDowncast<IClTensorHandle>(input)->GetTensor();
62  aclInputs.emplace_back(&aclInput);
63  }
64  arm_compute::ICLTensor& output = armnn::PolymorphicPointerDowncast<IClTensorHandle>(
65  m_Data.m_Outputs[0])->GetTensor();
66 
67  m_Layer.reset(new arm_compute::CLStackLayer());
68  int aclAxis = CalcAxis(descriptor.m_Parameters.m_Axis, descriptor.m_Parameters.m_InputShape.GetNumDimensions());
69  {
70  ARMNN_SCOPED_PROFILING_EVENT_CL_NAME_GUID("ClStackWorkload_configure");
71  m_Layer->configure(clCompileContext, aclInputs, aclAxis, &output);
72  }
73 }
74 
76 {
77  if (m_Layer)
78  {
79  ARMNN_SCOPED_PROFILING_EVENT_CL_NAME_GUID("ClStackWorkload_Execute");
80  m_Layer->run();
81  }
82 }
83 
84 } //namespace armnn
armnn::StackQueueDescriptor
Definition: WorkloadData.hpp:152
armnn::TensorInfo
Definition: Tensor.hpp:152
ClLayerSupport.hpp
armnn::ClBaseWorkload
Definition: ClBaseWorkload.hpp:13
armnn::StackDescriptor
A StackDescriptor for the StackLayer.
Definition: Descriptors.hpp:1251
NumericCast.hpp
armnn::ClStackWorkload::ClStackWorkload
ClStackWorkload(const StackQueueDescriptor &descriptor, const WorkloadInfo &info, const arm_compute::CLCompileContext &clCompileContext)
Definition: ClStackWorkload.cpp:47
armnn::QueueDescriptorWithParameters::m_Parameters
LayerDescriptor m_Parameters
Definition: WorkloadData.hpp:66
armnn::TensorShape::GetNumDimensions
unsigned int GetNumDimensions() const
Function that returns the tensor rank.
Definition: Tensor.cpp:174
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::ClStackWorkloadValidate
arm_compute::Status ClStackWorkloadValidate(const std::vector< const TensorInfo * > &inputs, const TensorInfo &output, const StackDescriptor &descriptor)
Definition: ClStackWorkload.cpp:29
armnn::WorkloadInfo
Contains information about TensorInfos of a layer.
Definition: WorkloadInfo.hpp:16
PolymorphicDowncast.hpp
armnn::StackDescriptor::m_Axis
uint32_t m_Axis
0-based axis along which to stack the input tensors.
Definition: Descriptors.hpp:1273
ClWorkloadUtils.hpp
armnn::BoostLogSeverityMapping::info
@ info
armnn::StackDescriptor::m_InputShape
TensorShape m_InputShape
Required shape of all input tensors.
Definition: Descriptors.hpp:1277
armnn::QueueDescriptor::m_Outputs
std::vector< ITensorHandle * > m_Outputs
Definition: WorkloadData.hpp:27
ARMNN_REPORT_PROFILING_WORKLOAD_DESC
#define ARMNN_REPORT_PROFILING_WORKLOAD_DESC(name, desc, infos, guid)
Definition: Profiling.hpp:227
TensorHandle.hpp
armnn::Status
Status
Definition: Types.hpp:42
ClTensorHandle.hpp
armnn::BaseWorkload< StackQueueDescriptor >::m_Data
StackQueueDescriptor m_Data
Definition: Workload.hpp:89
ClStackWorkload.hpp
armnn
Copyright (c) 2021 ARM Limited and Contributors.
Definition: 01_00_quick_start.dox:6
ArmComputeTensorUtils.hpp
armnn::ClStackWorkload::Execute
void Execute() const override
Definition: ClStackWorkload.cpp:75
armnn::QueueDescriptor::m_Inputs
std::vector< ITensorHandle * > m_Inputs
Definition: WorkloadData.hpp:26