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