ArmNN
 20.02
NeonConcatWorkload.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #include "NeonConcatWorkload.hpp"
7 
8 #include "NeonWorkloadUtils.hpp"
9 
13 
14 
15 
16 namespace armnn
17 {
18 using namespace armcomputetensorutils;
19 
20 namespace
21 {
22 size_t CalcAxis(const armnn::OriginsDescriptor& desc)
23 {
24  return (desc.GetNumDimensions() - desc.GetConcatAxis()) - 1;
25 }
26 } //namespace
27 
28 arm_compute::Status NeonConcatWorkloadValidate(const std::vector<const TensorInfo*>& inputs,
29  const TensorInfo& output,
30  const OriginsDescriptor& descriptor)
31 
32 {
33  std::vector<arm_compute::TensorInfo> aclInputs;
34  for (const TensorInfo* input : inputs)
35  {
36  arm_compute::TensorInfo aclInputInfo = BuildArmComputeTensorInfo(*input, armnn::DataLayout::NCHW);
37  aclInputs.emplace_back(aclInputInfo);
38  }
39  const arm_compute::TensorInfo aclOutputInfo = BuildArmComputeTensorInfo(output);
40  std::vector<arm_compute::ITensorInfo*> aclInputPtrs;
41  for (arm_compute::ITensorInfo& input : aclInputs)
42  {
43  aclInputPtrs.emplace_back(&input);
44  }
45 
46  size_t aclAxis = CalcAxis(descriptor);
47  return arm_compute::NEConcatenateLayer::validate(aclInputPtrs, &aclOutputInfo, aclAxis);
48 }
49 
51 const ConcatQueueDescriptor& descriptor, const WorkloadInfo& info)
52  : BaseWorkload<ConcatQueueDescriptor>(descriptor, info)
53 {
54  bool allInputsAreSubtensors = true;
55 
56  // Check that all inputs are sub-tensors
57  for (auto input : descriptor.m_Inputs)
58  {
59  if (!input->GetParent())
60  {
61  // Non sub-tensor input found so we need to execute the concat function
62  allInputsAreSubtensors = false;
63  break;
64  }
65  }
66 
67  if (allInputsAreSubtensors)
68  {
69  // Can skip configuring the concat function since it's not executed
70  return;
71  }
72 
73  std::vector<arm_compute::ITensor *> aclInputs;
74  for (auto input : m_Data.m_Inputs)
75  {
76  arm_compute::ITensor& aclInput = boost::polymorphic_pointer_downcast<IAclTensorHandle>(input)->GetTensor();
77  aclInputs.emplace_back(&aclInput);
78  }
79  arm_compute::ITensor& output = boost::polymorphic_pointer_downcast<IAclTensorHandle>(
80  m_Data.m_Outputs[0])->GetTensor();
81 
82  // Create the layer function
83  m_Layer.reset(new arm_compute::NEConcatenateLayer());
84 
85  // Configure input and output tensors
86  size_t aclAxis = CalcAxis(descriptor.m_Parameters);
87  m_Layer->configure(aclInputs, &output, aclAxis);
88 
89  // Prepare
90  m_Layer->prepare();
91 }
92 
94 {
95  if (m_Layer)
96  {
97  ARMNN_SCOPED_PROFILING_EVENT_NEON("NeonConcatWorkload_Execute");
98  m_Layer->run();
99  }
100 }
101 
102 } //namespace armnn
103 
const ConcatQueueDescriptor m_Data
Definition: Workload.hpp:46
#define ARMNN_SCOPED_PROFILING_EVENT_NEON(name)
NeonConcatWorkload(const ConcatQueueDescriptor &descriptor, const WorkloadInfo &info)
Copyright (c) 2020 ARM Limited.
An OriginsDescriptor for the ConcatLayer.
void Execute() const override
Status
enumeration
Definition: Types.hpp:26
arm_compute::Status NeonConcatWorkloadValidate(const std::vector< const TensorInfo *> &inputs, const TensorInfo &output, const OriginsDescriptor &descriptor)
std::vector< ITensorHandle * > m_Outputs
uint32_t GetNumDimensions() const
Get the number of dimensions.
Contains information about inputs and outputs to a layer.
std::vector< ITensorHandle * > m_Inputs
unsigned int GetConcatAxis() const
Get the concatenation axis value.