ArmNN
 24.08
ClConcatWorkload.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017,2019-2023 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 #include "ClConcatWorkload.hpp"
6 #include "ClWorkloadUtils.hpp"
10 #include <cl/ClTensorHandle.hpp>
11 #include <cl/ClLayerSupport.hpp>
12 
13 #include <arm_compute/core/Types.h>
14 
15 namespace armnn
16 {
17 using namespace armcomputetensorutils;
18 
19 namespace
20 {
21 size_t CalcAxis(const OriginsDescriptor& descriptor)
22 {
23  return (descriptor.GetNumDimensions() - descriptor.GetConcatAxis()) - 1;
24 }
25 } //namespace
26 
27 arm_compute::Status ClConcatWorkloadValidate(const std::vector<const TensorInfo*>& inputs,
28  const TensorInfo& output,
29  const OriginsDescriptor& descriptor)
30 {
31  std::vector<arm_compute::TensorInfo> aclInputs;
32  for (const TensorInfo* input : inputs)
33  {
34  arm_compute::TensorInfo aclInputInfo = BuildArmComputeTensorInfo(*input, armnn::DataLayout::NCHW);
35  aclInputs.emplace_back(aclInputInfo);
36  }
37  const arm_compute::TensorInfo aclOutputInfo = BuildArmComputeTensorInfo(output);
38  std::vector<const arm_compute::ITensorInfo*> aclInputPtrs;
39  for (arm_compute::ITensorInfo& input : aclInputs)
40  {
41  aclInputPtrs.emplace_back(&input);
42  }
43 
44  size_t aclAxis = CalcAxis(descriptor);
45  return arm_compute::CLConcatenateLayer::validate(aclInputPtrs, &aclOutputInfo, aclAxis);
46 }
47 
49  const WorkloadInfo& info,
50  const arm_compute::CLCompileContext& clCompileContext)
52 {
53  // Report Profiling Details
54  ARMNN_REPORT_PROFILING_WORKLOAD_DESC("ClConcatWorkload_Construct",
55  descriptor.m_Parameters,
56  info,
57  this->GetGuid());
58 
59  bool allInputsAreSubtensors = true;
60 
61  // Check that all inputs are sub-tensors
62  for (auto input : descriptor.m_Inputs)
63  {
64  if (!input->GetParent())
65  {
66  // Non sub-tensor input found so we need to execute the concat function
67  allInputsAreSubtensors = false;
68  break;
69  }
70  }
71 
72  if (allInputsAreSubtensors)
73  {
74  // Can skip configuring the concat function since it's not executed
75  return;
76  }
77 
78  std::vector<const arm_compute::ICLTensor *> aclInputs;
79  for (auto input : m_Data.m_Inputs)
80  {
81  arm_compute::ICLTensor& aclInput = armnn::PolymorphicPointerDowncast<IClTensorHandle>(input)->GetTensor();
82  aclInputs.emplace_back(&aclInput);
83  }
84 
85  arm_compute::ICLTensor& output =
86  armnn::PolymorphicPointerDowncast<IClTensorHandle>(m_Data.m_Outputs[0])->GetTensor();
87 
88  // Create the layer function
89  auto layer = std::make_unique<arm_compute::CLConcatenateLayer>();
90 
91  {
92  ARMNN_SCOPED_PROFILING_EVENT_CL_NAME_GUID("ClConcatWorkload_configure");
93  // Configure input and output tensors
94  size_t aclAxis = CalcAxis(descriptor.m_Parameters);
95  layer->configure(clCompileContext, aclInputs, &output, aclAxis);
96  }
97 
98  // Prepare
99  layer->prepare();
100  m_Layer = std::move(layer);
101 }
102 
104 {
105  if (m_Layer)
106  {
107  ARMNN_SCOPED_PROFILING_EVENT_CL_NAME_GUID("ClConcatWorkload_Execute");
108  m_Layer->run();
109  }
110 }
111 
112 } //namespace armnn
armnn::ConcatQueueDescriptor
Definition: WorkloadData.hpp:130
armnn::TensorInfo
Definition: Tensor.hpp:152
ClLayerSupport.hpp
armnn::ClBaseWorkload
Definition: ClBaseWorkload.hpp:13
armnn::ClConcatWorkload::Execute
void Execute() const override
Definition: ClConcatWorkload.cpp:103
armnn::QueueDescriptorWithParameters::m_Parameters
LayerDescriptor m_Parameters
Definition: WorkloadData.hpp:66
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::WorkloadInfo
Contains information about TensorInfos of a layer.
Definition: WorkloadInfo.hpp:16
PolymorphicDowncast.hpp
ClWorkloadUtils.hpp
armnn::ClConcatWorkload::ClConcatWorkload
ClConcatWorkload(const ConcatQueueDescriptor &descriptor, const WorkloadInfo &info, const arm_compute::CLCompileContext &clCompileContext)
Definition: ClConcatWorkload.cpp:48
ClConcatWorkload.hpp
armnn::BoostLogSeverityMapping::info
@ info
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< ConcatQueueDescriptor >::m_Data
ConcatQueueDescriptor m_Data
Definition: Workload.hpp:89
armnn::ClConcatWorkloadValidate
arm_compute::Status ClConcatWorkloadValidate(const std::vector< const TensorInfo * > &inputs, const TensorInfo &output, const OriginsDescriptor &descriptor)
Definition: ClConcatWorkload.cpp:27
armnn::OriginsDescriptor
An OriginsDescriptor for the ConcatLayer.
Definition: Descriptors.hpp:201
armnn
Copyright (c) 2021 ARM Limited and Contributors.
Definition: 01_00_quick_start.dox:6
ArmComputeTensorUtils.hpp
armnn::QueueDescriptor::m_Inputs
std::vector< ITensorHandle * > m_Inputs
Definition: WorkloadData.hpp:26
armnn::DataLayout::NCHW
@ NCHW