ArmNN
 20.02
ClSplitterWorkload.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 "ClSplitterWorkload.hpp"
7 
8 #include "ClWorkloadUtils.hpp"
9 
12 #include <arm_compute/runtime/CL/functions/CLSplit.h>
14 #include <cl/ClTensorHandle.hpp>
15 
16 
17 namespace armnn
18 {
19 
20 using namespace armcomputetensorutils;
21 
22 namespace
23 {
24  unsigned int CalcAclAxis(unsigned int numDimensions, unsigned int splitAxis)
25  {
26  return (numDimensions - splitAxis) - 1;
27  }
28 
29 } //namespace
30 
32  const std::vector<std::reference_wrapper<TensorInfo>>& outputs,
33  unsigned int splitAxis)
34 {
35  const arm_compute::TensorInfo aclInputInfo = BuildArmComputeTensorInfo(input);
36 
37  size_t numOutputs = outputs.size();
38 
39  std::vector<arm_compute::TensorInfo> aclOutputs;
40  aclOutputs.reserve(numOutputs);
41 
42  std::vector<arm_compute::ITensorInfo*> aclOutputPtr;
43  aclOutputPtr.reserve(numOutputs);
44 
45  for (size_t i = 0u; i < outputs.size(); ++i)
46  {
47  aclOutputs.emplace_back(BuildArmComputeTensorInfo(outputs[i]));
48  aclOutputPtr.emplace_back(&aclOutputs.back());
49  }
50 
51  unsigned int aclAxis = CalcAclAxis(input.GetNumDimensions(), splitAxis);
52  return arm_compute::CLSplit::validate(&aclInputInfo, aclOutputPtr, aclAxis);
53 }
54 
56  : BaseWorkload<SplitterQueueDescriptor>(descriptor, info)
57 {
58  bool allOutputsAreSubtensors = true;
59 
60  // Check that all outputs are sub-tensors
61  for (auto output : m_Data.m_Outputs)
62  {
63  if (output && !output->GetParent())
64  {
65  // Non sub-tensor input found so we need to execute the split function
66  allOutputsAreSubtensors = false;
67  break;
68  }
69  }
70 
71  if (allOutputsAreSubtensors)
72  {
73  // Can skip configuring the split function since it's not executed
74  return;
75  }
76 
77  arm_compute::ICLTensor& input = boost::polymorphic_pointer_downcast<IClTensorHandle>(
78  m_Data.m_Inputs[0])->GetTensor();
79 
80  std::vector<arm_compute::ICLTensor *> aclOutputs;
81  for (auto output : m_Data.m_Outputs)
82  {
83  arm_compute::ICLTensor& aclOutput = boost::polymorphic_pointer_downcast<IClTensorHandle>(output)->GetTensor();
84  aclOutputs.emplace_back(&aclOutput);
85  }
86 
87  // Create the layer function
88 
89  // Configure input and output tensors
90  std::set<unsigned int> splitAxis = ComputeSplitAxis(descriptor.m_Parameters, m_Data.m_Inputs[0]->GetShape());
91  if (splitAxis.size() != 1)
92  {
93  throw InvalidArgumentException("Cannot derive split axis from SplitterDescriptor");
94  }
95 
96  unsigned int aclAxis = CalcAclAxis(descriptor.m_Parameters.GetNumDimensions(), *splitAxis.begin());
97  auto layer = std::make_unique<arm_compute::CLSplit>();
98  layer->configure(&input, aclOutputs, aclAxis);
99 
100  // Prepare
101  layer->prepare();
102 
103  m_Layer = std::move(layer);
104 }
105 
107 {
108  if (m_Layer)
109  {
110  ARMNN_SCOPED_PROFILING_EVENT_CL("ClSplitterWorkload_Execute");
111  m_Layer->run();
112  }
113 }
114 
115 } //namespace armnn
ClSplitterWorkload(const SplitterQueueDescriptor &descriptor, const WorkloadInfo &info)
arm_compute::Status ClSplitterWorkloadValidate(const TensorInfo &input, const std::vector< std::reference_wrapper< TensorInfo >> &outputs, unsigned int splitAxis)
uint32_t GetNumDimensions() const
Get the number of dimensions.
#define ARMNN_SCOPED_PROFILING_EVENT_CL(name)
const SplitterQueueDescriptor m_Data
Definition: Workload.hpp:46
Copyright (c) 2020 ARM Limited.
std::set< unsigned int > ComputeSplitAxis(const armnn::SplitterDescriptor &desc, const TensorShape &input)
Status
enumeration
Definition: Types.hpp:26
std::vector< ITensorHandle * > m_Outputs
void Execute() const override
Contains information about inputs and outputs to a layer.
std::vector< ITensorHandle * > m_Inputs
unsigned int GetNumDimensions() const
Definition: Tensor.hpp:92