ArmNN
 24.02
NeonSplitterWorkload.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 
7 
8 #include <arm_compute/runtime/NEON/functions/NESplit.h>
9 
15 
16 #include "NeonWorkloadUtils.hpp"
17 
18 namespace armnn
19 {
20 
21 using namespace armcomputetensorutils;
22 
23 namespace
24 {
25 unsigned int CalcAclAxis(unsigned int numDimensions, unsigned int splitAxis)
26 {
27  return (numDimensions - splitAxis) - 1;
28 }
29 
30 } //namespace
31 
33  const std::vector<std::reference_wrapper<TensorInfo>>& outputs,
34  unsigned int splitAxis)
35 {
36  const arm_compute::TensorInfo aclInputInfo = BuildArmComputeTensorInfo(input);
37 
38  size_t numOutputs = outputs.size();
39 
40  std::vector<arm_compute::TensorInfo> aclOutputs;
41  aclOutputs.reserve(numOutputs);
42 
43  std::vector<arm_compute::ITensorInfo*> aclOutputPtr;
44  aclOutputPtr.reserve(numOutputs);
45 
46  for (size_t i = 0u; i < outputs.size(); ++i)
47  {
48  aclOutputs.emplace_back(BuildArmComputeTensorInfo(outputs[i]));
49  aclOutputPtr.emplace_back(&aclOutputs.back());
50  }
51 
52  unsigned int aclAxis = CalcAclAxis(input.GetNumDimensions(), splitAxis);
53  return arm_compute::NESplit::validate(&aclInputInfo, aclOutputPtr, aclAxis);
54 }
55 
58 {
59  // Report Profiling Details
60  ARMNN_REPORT_PROFILING_WORKLOAD_DESC("NeonSplitterWorkload_Construct",
61  descriptor.m_Parameters,
62  info,
63  this->GetGuid());
64 
65  bool allOutputsAreSubtensors = true;
66 
67  // Check that all outputs are sub-tensors
68  for (auto output : m_Data.m_Outputs)
69  {
70  if (output && !output->GetParent())
71  {
72  // Non sub-tensor input found so we need to execute the split function
73  allOutputsAreSubtensors = false;
74  break;
75  }
76  }
77 
78  if (allOutputsAreSubtensors)
79  {
80  // Can skip configuring the split function since it's not executed
81  return;
82  }
83 
84  arm_compute::ITensor& input = PolymorphicDowncast<IAclTensorHandle*>(m_Data.m_Inputs[0])->GetTensor();
85 
86  std::vector<arm_compute::ITensor *> aclOutputs;
87  for (auto output : m_Data.m_Outputs)
88  {
89  arm_compute::ITensor& aclOutput = PolymorphicPointerDowncast<IAclTensorHandle>(output)->GetTensor();
90  aclOutputs.emplace_back(&aclOutput);
91  }
92 
93  // Create the layer function
94  std::unique_ptr<arm_compute::NESplit> layer(new arm_compute::NESplit());
95 
96  // Configure input and output tensors
97  std::set<unsigned int> splitAxis = ComputeSplitAxis(descriptor.m_Parameters, m_Data.m_Inputs[0]->GetShape());
98  if (splitAxis.size() != 1)
99  {
100  throw InvalidArgumentException("Cannot derive split axis from SplitterDescriptor");
101  }
102 
103  unsigned int aclAxis = CalcAclAxis(descriptor.m_Parameters.GetNumDimensions(), *splitAxis.begin());
104  layer->configure(&input, aclOutputs, aclAxis);
105 
106  // Prepare
107  layer->prepare();
108  m_Layer.reset(layer.release());
109 }
110 
112 {
113  if (m_Layer)
114  {
115  ARMNN_SCOPED_PROFILING_EVENT_NEON_NAME_GUID("NeonSplitterWorkload_Execute");
116  m_Layer->run();
117  }
118 }
119 
120 } //namespace armnn
121 
armnn::TensorInfo
Definition: Tensor.hpp:152
NeonTensorHandle.hpp
armnn::TensorInfo::GetNumDimensions
unsigned int GetNumDimensions() const
Definition: Tensor.hpp:197
armnn::NeonSplitterWorkload::Execute
void Execute() const override
Definition: NeonSplitterWorkload.cpp:111
armnn::ComputeSplitAxis
std::set< unsigned int > ComputeSplitAxis(const armnn::SplitterDescriptor &desc, const TensorShape &input)
Definition: ArmComputeUtils.hpp:246
armnn::SplitterQueueDescriptor
Definition: WorkloadData.hpp:111
armnn::QueueDescriptorWithParameters::m_Parameters
LayerDescriptor m_Parameters
Definition: WorkloadData.hpp:66
armnn::NeonSplitterWorkload::NeonSplitterWorkload
NeonSplitterWorkload(const SplitterQueueDescriptor &descriptor, const WorkloadInfo &info)
Definition: NeonSplitterWorkload.cpp:56
armnn::WorkloadInfo
Contains information about TensorInfos of a layer.
Definition: WorkloadInfo.hpp:16
PolymorphicDowncast.hpp
armnn::InvalidArgumentException
Definition: Exceptions.hpp:80
ArmComputeUtils.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
armnn::BaseWorkload< SplitterQueueDescriptor >::m_Data
SplitterQueueDescriptor m_Data
Definition: Workload.hpp:89
armnn::NeonSplitterWorkloadValidate
arm_compute::Status NeonSplitterWorkloadValidate(const TensorInfo &input, const std::vector< std::reference_wrapper< TensorInfo >> &outputs, unsigned int splitAxis)
Definition: NeonSplitterWorkload.cpp:32
armnn::ViewsDescriptor::GetNumDimensions
uint32_t GetNumDimensions() const
Get the number of dimensions.
Definition: Descriptors.cpp:306
NeonWorkloadUtils.hpp
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:32
armnn::NeonBaseWorkload
Definition: NeonBaseWorkload.hpp:13
NeonSplitterWorkload.hpp
armnn::QueueDescriptor::m_Inputs
std::vector< ITensorHandle * > m_Inputs
Definition: WorkloadData.hpp:26