ArmNN
 24.08
NeonConcatWorkload.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017-2023 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #include "NeonConcatWorkload.hpp"
7 
8 #include "NeonWorkloadUtils.hpp"
9 
14 
15 namespace armnn
16 {
17 using namespace armcomputetensorutils;
18 
19 namespace
20 {
21 size_t CalcAxis(const armnn::OriginsDescriptor& descriptor)
22 {
23  return (descriptor.GetNumDimensions() - descriptor.GetConcatAxis()) - 1;
24 }
25 } //namespace
26 
27 arm_compute::Status NeonConcatWorkloadValidate(const std::vector<const TensorInfo*>& inputs,
28  const TensorInfo& output,
29  const OriginsDescriptor& descriptor)
30 
31 {
32  std::vector<arm_compute::TensorInfo> aclInputs;
33  for (const TensorInfo* input : inputs)
34  {
35  arm_compute::TensorInfo aclInputInfo = BuildArmComputeTensorInfo(*input, armnn::DataLayout::NCHW);
36  aclInputs.emplace_back(aclInputInfo);
37  }
38  const arm_compute::TensorInfo aclOutputInfo = BuildArmComputeTensorInfo(output);
39  std::vector<const arm_compute::ITensorInfo*> aclInputPtrs;
40  for (arm_compute::ITensorInfo& input : aclInputs)
41  {
42  aclInputPtrs.emplace_back(&input);
43  }
44 
45  size_t aclAxis = CalcAxis(descriptor);
46  return arm_compute::NEConcatenateLayer::validate(aclInputPtrs, &aclOutputInfo, aclAxis);
47 }
48 
50 const ConcatQueueDescriptor& descriptor, const WorkloadInfo& info)
52 {
53  // Report Profiling Details
54  ARMNN_REPORT_PROFILING_WORKLOAD_DESC("NeonConcatWorkload_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::ITensor *> aclInputs;
79  for (auto input : m_Data.m_Inputs)
80  {
81  arm_compute::ITensor& aclInput = armnn::PolymorphicPointerDowncast<IAclTensorHandle>(input)->GetTensor();
82  aclInputs.emplace_back(&aclInput);
83  }
84  arm_compute::ITensor& output = armnn::PolymorphicPointerDowncast<IAclTensorHandle>(
85  m_Data.m_Outputs[0])->GetTensor();
86 
87  // Create the layer function
88  m_Layer.reset(new arm_compute::NEConcatenateLayer());
89 
90  // Configure input and output tensors
91  size_t aclAxis = CalcAxis(descriptor.m_Parameters);
92  m_Layer->configure(aclInputs, &output, aclAxis);
93 
94  // Prepare
95  m_Layer->prepare();
96 }
97 
99 {
100  if (m_Layer)
101  {
102  ARMNN_SCOPED_PROFILING_EVENT_NEON_NAME_GUID("NeonConcatWorkload_Execute");
103  m_Layer->run();
104  }
105 }
106 
107 } //namespace armnn
108 
NeonConcatWorkload.hpp
armnn::OriginsDescriptor::GetConcatAxis
unsigned int GetConcatAxis() const
Get the concatenation axis value.
Definition: Descriptors.cpp:162
armnn::ConcatQueueDescriptor
Definition: WorkloadData.hpp:130
armnn::TensorInfo
Definition: Tensor.hpp:152
armnn::OriginsDescriptor::GetNumDimensions
uint32_t GetNumDimensions() const
Get the number of dimensions.
Definition: Descriptors.cpp:192
NeonTensorHandle.hpp
armnn::NeonConcatWorkloadValidate
arm_compute::Status NeonConcatWorkloadValidate(const std::vector< const TensorInfo * > &inputs, const TensorInfo &output, const OriginsDescriptor &descriptor)
Definition: NeonConcatWorkload.cpp:27
armnn::QueueDescriptorWithParameters::m_Parameters
LayerDescriptor m_Parameters
Definition: WorkloadData.hpp:66
armnn::WorkloadInfo
Contains information about TensorInfos of a layer.
Definition: WorkloadInfo.hpp:16
PolymorphicDowncast.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
armnn::NeonConcatWorkload::NeonConcatWorkload
NeonConcatWorkload(const ConcatQueueDescriptor &descriptor, const WorkloadInfo &info)
Definition: NeonConcatWorkload.cpp:49
TensorHandle.hpp
armnn::Status
Status
Definition: Types.hpp:42
armnn::BaseWorkload< ConcatQueueDescriptor >::m_Data
ConcatQueueDescriptor m_Data
Definition: Workload.hpp:89
NeonWorkloadUtils.hpp
armnn::NeonConcatWorkload::Execute
void Execute() const override
Definition: NeonConcatWorkload.cpp:98
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_SCOPED_PROFILING_EVENT_NEON_NAME_GUID
#define ARMNN_SCOPED_PROFILING_EVENT_NEON_NAME_GUID(label)
Creates a profiling event that uses GetGuid() and GetName() from the calling class.
Definition: NeonWorkloadUtils.hpp:33
armnn::NeonBaseWorkload
Definition: NeonBaseWorkload.hpp:13
armnn::QueueDescriptor::m_Inputs
std::vector< ITensorHandle * > m_Inputs
Definition: WorkloadData.hpp:26
armnn::DataLayout::NCHW
@ NCHW