ArmNN
 24.02
NeonFusedWorkload.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2023 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #include "NeonFusedWorkload.hpp"
7 #include "NeonWorkloadUtils.hpp"
8 
11 
14 
15 #include <arm_compute/runtime/NEON/functions/NEAddMulAdd.h>
16 
17 namespace armnn
18 {
19 
20 using namespace armcomputetensorutils;
21 
22 arm_compute::Status NeonFusedWorkloadValidate(const std::vector<std::reference_wrapper<TensorInfo>>& inputInfos,
23  const std::vector<std::reference_wrapper<TensorInfo>>& outputInfos,
24  const FusedDescriptor& fusedDescriptor,
25  const ActivationDescriptor* activationDescriptor)
26 {
27  std::vector<arm_compute::TensorInfo> actInputInfos;
28  actInputInfos.reserve(inputInfos.size());
29  for (size_t i = 0u; i < inputInfos.size(); ++i)
30  {
31  actInputInfos.emplace_back(BuildArmComputeTensorInfo(inputInfos[i]));
32  }
33 
34  std::vector<arm_compute::TensorInfo> actOutputInfos;
35  actOutputInfos.reserve(outputInfos.size());
36  for (size_t i = 0u; i < outputInfos.size(); ++i)
37  {
38  actOutputInfos.emplace_back(BuildArmComputeTensorInfo(outputInfos[i]));
39  }
40 
41  const arm_compute::ActivationLayerInfo activationInfo =
43 
44  switch (fusedDescriptor.m_FusedKernelType)
45  {
47  return arm_compute::NEAddMulAdd::validate(
48  &actInputInfos[0],
49  &actInputInfos[1],
50  &actInputInfos[2], // bn_mul
51  &actInputInfos[3], // bn_add
52  actOutputInfos.size() == 1 ? nullptr : &actOutputInfos[0], // add_output
53  actOutputInfos.size() == 1 ? &actOutputInfos[0] : &actOutputInfos[1], // final_output
54  arm_compute::ConvertPolicy::SATURATE,
55  activationInfo);
56  default:
57  return arm_compute::Status{arm_compute::ErrorCode::RUNTIME_ERROR,
58  "NeonFusedWorkloadValidate: no valid kernel type"};
59  }
60 }
61 
62 
65 {
66  m_Data.ValidateInputsOutputs("NeonFusedWorkload",
67  static_cast<unsigned int>(info.m_InputTensorInfos.size()),
68  static_cast<unsigned int>(info.m_OutputTensorInfos.size()));
69 
70  std::vector<arm_compute::ITensor*> inputs;
71  inputs.reserve(info.m_InputTensorInfos.size());
72  for (auto input : m_Data.m_Inputs)
73  {
74  inputs.emplace_back(&PolymorphicDowncast<IAclTensorHandle*>(input)->GetTensor());
75  }
76 
77  std::vector<arm_compute::ITensor*> outputs;
78  outputs.reserve(info.m_OutputTensorInfos.size());
79  for (auto output : m_Data.m_Outputs)
80  {
81  outputs.emplace_back(&PolymorphicDowncast<IAclTensorHandle*>(output)->GetTensor());
82  }
83 
84  const arm_compute::ActivationLayerInfo activationInfo =
86 
87  switch (descriptor.m_Parameters.m_FusedKernelType)
88  {
90  {
91  auto layer = std::make_unique<arm_compute::NEAddMulAdd>();
92  layer->configure(inputs[0],
93  inputs[1],
94  inputs[2], // bn_mul
95  inputs[3], // bn_add
96  outputs.size() == 1 ? nullptr : outputs[0], // add_output
97  outputs.size() == 1 ? outputs[0] : outputs[1], // final_output
98  arm_compute::ConvertPolicy::SATURATE,
99  activationInfo);
100  m_FusedLayer.reset(layer.release());
101  break;
102  }
103  default:
104  throw Exception("NeonFusedWorkload: no valid kernel type.");
105  }
106 }
107 
109 {
110  ARMNN_SCOPED_PROFILING_EVENT_NEON_GUID("NeonFusedWorkload_Execute", this->GetGuid());
111  m_FusedLayer->run();
112 }
113 
114 } //namespace armnn
115 
armnn::ActivationDescriptor
An ActivationDescriptor for the ActivationLayer.
Definition: Descriptors.hpp:36
armnn::FusedDescriptor::m_FusedKernelType
FusedKernelType m_FusedKernelType
Definition: Descriptors.hpp:961
NeonFusedWorkload.hpp
armnn::NeonFusedWorkload::Execute
virtual void Execute() const override
Definition: NeonFusedWorkload.cpp:108
armnn::QueueDescriptor::ValidateInputsOutputs
void ValidateInputsOutputs(const std::string &descName, unsigned int numExpectedIn, unsigned int numExpectedOut) const
Definition: WorkloadData.cpp:446
armnn::ConvertAdditionalInfoToAclActivationLayerInfo
arm_compute::ActivationLayerInfo ConvertAdditionalInfoToAclActivationLayerInfo(const QueueDescriptor &queueDescriptor)
Definition: ArmComputeUtils.hpp:105
armnn::FusedQueueDescriptor
Definition: WorkloadData.hpp:185
armnn::FusedKernelType::AddMulAdd
@ AddMulAdd
ARMNN_SCOPED_PROFILING_EVENT_NEON_GUID
#define ARMNN_SCOPED_PROFILING_EVENT_NEON_GUID(name, guid)
Definition: NeonWorkloadUtils.hpp:24
armnn::FusedDescriptor
A FusedDescriptor for the FusedLayer.
Definition: Descriptors.hpp:944
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::NeonFusedWorkload::NeonFusedWorkload
NeonFusedWorkload(const FusedQueueDescriptor &descriptor, const WorkloadInfo &info)
Definition: NeonFusedWorkload.cpp:63
ArmComputeUtils.hpp
armnn::Exception
Base class for all ArmNN exceptions so that users can filter to just those.
Definition: Exceptions.hpp:46
armnn::ConvertActivationDescriptorToAclActivationLayerInfo
arm_compute::ActivationLayerInfo ConvertActivationDescriptorToAclActivationLayerInfo(const ActivationDescriptor &actDesc)
Definition: ArmComputeUtils.hpp:87
armnn::BoostLogSeverityMapping::info
@ info
armnn::QueueDescriptor::m_Outputs
std::vector< ITensorHandle * > m_Outputs
Definition: WorkloadData.hpp:27
armnn::BaseWorkload< FusedQueueDescriptor >::GetGuid
arm::pipe::ProfilingGuid GetGuid() const final
Definition: Workload.hpp:67
TensorHandle.hpp
armnn::Status
Status
Definition: Types.hpp:42
armnn::BaseWorkload< FusedQueueDescriptor >::m_Data
FusedQueueDescriptor m_Data
Definition: Workload.hpp:89
armnn::NeonFusedWorkloadValidate
arm_compute::Status NeonFusedWorkloadValidate(const std::vector< std::reference_wrapper< TensorInfo >> &inputInfos, const std::vector< std::reference_wrapper< TensorInfo >> &outputInfos, const FusedDescriptor &fusedDescriptor, const ActivationDescriptor *activationDescriptor)
Definition: NeonFusedWorkload.cpp:22
NeonWorkloadUtils.hpp
armnn
Copyright (c) 2021 ARM Limited and Contributors.
Definition: 01_00_quick_start.dox:6
ArmComputeTensorUtils.hpp
armnn::NeonBaseWorkload
Definition: NeonBaseWorkload.hpp:13
armnn::QueueDescriptor::m_Inputs
std::vector< ITensorHandle * > m_Inputs
Definition: WorkloadData.hpp:26