ArmNN
 24.02
NeonMultiplicationWorkload.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017,2019-2023 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
7 
8 #include "NeonWorkloadUtils.hpp"
9 
11 
13 
14 #include <arm_compute/runtime/NEON/functions/NEPixelWiseMultiplication.h>
15 
16 namespace armnn
17 {
18 
20  const TensorInfo& input1,
21  const TensorInfo& output,
22  const ActivationDescriptor* activationDescriptor)
23 {
24  const arm_compute::TensorInfo aclInput1 = armcomputetensorutils::BuildArmComputeTensorInfo(input0);
25  const arm_compute::TensorInfo aclInput2 = armcomputetensorutils::BuildArmComputeTensorInfo(input1);
26  const arm_compute::TensorInfo aclOutput = armcomputetensorutils::BuildArmComputeTensorInfo(output);
27 
28  auto convertPolicy = (IsQuantizedType(input0.GetDataType()) || IsQuantizedType(input1.GetDataType())) ?
29  arm_compute::ConvertPolicy::SATURATE :
30  arm_compute::ConvertPolicy::WRAP;
31 
32  const arm_compute::ActivationLayerInfo activationInfo = ConvertActivationDescriptorToAclActivationLayerInfo(
33  activationDescriptor);
34 
35  // At the time of writing, configure() will fail if a rounding policy other than TO_ZERO is supplied to it,
36  // when providing a scale of 1.0 for F32 tensors, even though the provided rounding policy appears to be
37  // ignored for F32 tensors.
38  return arm_compute::NEPixelWiseMultiplication::validate(&aclInput1,
39  &aclInput2,
40  &aclOutput,
41  1.0f,
42  convertPolicy,
43  arm_compute::RoundingPolicy::TO_ZERO,
44  activationInfo);
45 }
46 
48  const WorkloadInfo& info)
50 {
51  m_Data.ValidateInputsOutputs("NeonMultiplicationWorkload", 2, 1);
52 
53  arm_compute::ITensor& input1 = PolymorphicDowncast<IAclTensorHandle*>(m_Data.m_Inputs[0])->GetTensor();
54  arm_compute::ITensor& input2 = PolymorphicDowncast<IAclTensorHandle*>(m_Data.m_Inputs[1])->GetTensor();
55  arm_compute::ITensor& output = PolymorphicDowncast<IAclTensorHandle*>(m_Data.m_Outputs[0])->GetTensor();
56 
57  auto convertPolicy = (IsQuantizedType(info.m_InputTensorInfos[0].GetDataType()) ||
58  IsQuantizedType(info.m_InputTensorInfos[1].GetDataType())) ?
59  arm_compute::ConvertPolicy::SATURATE :
60  arm_compute::ConvertPolicy::WRAP;
61 
62  const arm_compute::ActivationLayerInfo activationInfo = ConvertAdditionalInfoToAclActivationLayerInfo(descriptor);
63 
64  // At the time of writing, configure() will fail if a rounding policy other than TO_ZERO is supplied to it,
65  // when providing a scale of 1.0 for F32 tensors, even though the provided rounding policy appears to be
66  // ignored for F32 tensors.
67  auto layer = std::make_unique<arm_compute::NEPixelWiseMultiplication>();
68  layer->configure(&input1,
69  &input2,
70  &output,
71  1.0f,
72  convertPolicy,
73  arm_compute::RoundingPolicy::TO_ZERO,
74  activationInfo);
75  m_PixelWiseMultiplication.reset(layer.release());
76 }
77 
79 {
80  ARMNN_SCOPED_PROFILING_EVENT_NEON_NAME_GUID("NeonMultiplicationWorkload_Execute");
81  m_PixelWiseMultiplication->run();
82 }
83 
84 } //namespace armnn
armnn::ActivationDescriptor
An ActivationDescriptor for the ActivationLayer.
Definition: Descriptors.hpp:36
armnn::NeonMultiplicationWorkloadValidate
arm_compute::Status NeonMultiplicationWorkloadValidate(const TensorInfo &input0, const TensorInfo &input1, const TensorInfo &output, const ActivationDescriptor *activationDescriptor)
Definition: NeonMultiplicationWorkload.cpp:19
armnn::MultiplicationQueueDescriptor
Definition: WorkloadData.hpp:264
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::TensorInfo
Definition: Tensor.hpp:152
armnn::NeonMultiplicationWorkload::NeonMultiplicationWorkload
NeonMultiplicationWorkload(const MultiplicationQueueDescriptor &descriptor, const WorkloadInfo &info)
Definition: NeonMultiplicationWorkload.cpp:47
armnn::WorkloadInfo
Contains information about TensorInfos of a layer.
Definition: WorkloadInfo.hpp:16
PolymorphicDowncast.hpp
armnn::NeonMultiplicationWorkload::Execute
virtual void Execute() const override
Definition: NeonMultiplicationWorkload.cpp:78
ArmComputeUtils.hpp
armnn::ConvertActivationDescriptorToAclActivationLayerInfo
arm_compute::ActivationLayerInfo ConvertActivationDescriptorToAclActivationLayerInfo(const ActivationDescriptor &actDesc)
Definition: ArmComputeUtils.hpp:87
armnn::BoostLogSeverityMapping::info
@ info
armnn::TensorInfo::GetDataType
DataType GetDataType() const
Definition: Tensor.hpp:200
armnn::QueueDescriptor::m_Outputs
std::vector< ITensorHandle * > m_Outputs
Definition: WorkloadData.hpp:27
armnn::Status
Status
Definition: Types.hpp:42
armnn::BaseWorkload< MultiplicationQueueDescriptor >::m_Data
MultiplicationQueueDescriptor m_Data
Definition: Workload.hpp:89
NeonWorkloadUtils.hpp
armnn::IsQuantizedType
constexpr bool IsQuantizedType()
Definition: TypesUtils.hpp:311
armnn
Copyright (c) 2021 ARM Limited and Contributors.
Definition: 01_00_quick_start.dox:6
NeonMultiplicationWorkload.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
armnn::QueueDescriptor::m_Inputs
std::vector< ITensorHandle * > m_Inputs
Definition: WorkloadData.hpp:26