ArmNN
 21.11
ClStackWorkload.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017 Arm Ltd. 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)
50 : BaseWorkload<StackQueueDescriptor>(descriptor, info)
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(Compute::Undefined, "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_GUID("ClStackWorkload_Execute", this->GetGuid());
80  m_Layer->run();
81  }
82 }
83 
84 } //namespace armnn
#define ARMNN_SCOPED_PROFILING_EVENT_CL_GUID(name, guid)
uint32_t m_Axis
0-based axis along which to stack the input tensors.
TensorShape m_InputShape
Required shape of all input tensors.
ClStackWorkload(const StackQueueDescriptor &descriptor, const WorkloadInfo &info, const arm_compute::CLCompileContext &clCompileContext)
Copyright (c) 2021 ARM Limited and Contributors.
void Execute() const override
#define ARMNN_SCOPED_PROFILING_EVENT(backendId, name)
Definition: Profiling.hpp:220
A StackDescriptor for the StackLayer.
arm_compute::Status ClStackWorkloadValidate(const std::vector< const TensorInfo *> &inputs, const TensorInfo &output, const StackDescriptor &descriptor)
Status
enumeration
Definition: Types.hpp:29
profiling::ProfilingGuid GetGuid() const final
Definition: Workload.hpp:55
std::vector< ITensorHandle * > m_Outputs
unsigned int GetNumDimensions() const
Function that returns the tensor rank.
Definition: Tensor.cpp:174
#define ARMNN_REPORT_PROFILING_WORKLOAD_DESC(name, desc, infos, guid)
Definition: Profiling.hpp:227
std::enable_if_t< std::is_unsigned< Source >::value &&std::is_unsigned< Dest >::value, Dest > numeric_cast(Source source)
Definition: NumericCast.hpp:35
Contains information about TensorInfos of a layer.
std::vector< ITensorHandle * > m_Inputs