blob: c75a1383011e4f05768e755e59ff2c6f1c3cde63 [file] [log] [blame]
telsoa014fcda012018-03-09 14:13:49 +00001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
David Beckecb56cd2018-09-05 12:52:57 +01003// SPDX-License-Identifier: MIT
telsoa014fcda012018-03-09 14:13:49 +00004//
5
Nattapat Chaimanowongd4b70592018-10-12 11:21:49 +01006#include "NeonActivationWorkload.hpp"
Matthew Benthamd80a7122019-01-08 17:52:37 +00007#include "NeonWorkloadUtils.hpp"
Aron Virginas-Tarc9cc8042018-11-01 16:15:57 +00008#include <aclCommon/ArmComputeUtils.hpp>
telsoa014fcda012018-03-09 14:13:49 +00009
Matthew Benthamd80a7122019-01-08 17:52:37 +000010#include <arm_compute/runtime/NEON/functions/NEActivationLayer.h>
11
telsoa014fcda012018-03-09 14:13:49 +000012namespace armnn
13{
telsoa01c577f2c2018-08-31 09:22:23 +010014
15arm_compute::Status NeonActivationWorkloadValidate(const TensorInfo& input,
16 const TensorInfo& output,
17 const ActivationDescriptor& descriptor)
18{
19 const arm_compute::TensorInfo aclInput = armcomputetensorutils::BuildArmComputeTensorInfo(input);
20 const arm_compute::TensorInfo aclOutput = armcomputetensorutils::BuildArmComputeTensorInfo(output);
21
22 const arm_compute::ActivationLayerInfo activationLayerInfo =
23 ConvertActivationDescriptorToAclActivationLayerInfo(descriptor);
24
25 if (input.GetDataType() == DataType::QuantisedAsymm8 &&
26 activationLayerInfo.activation() == arm_compute::ActivationLayerInfo::ActivationFunction::LOGISTIC)
27 {
28 return arm_compute::Status{arm_compute::ErrorCode::RUNTIME_ERROR,
29 "Neon: Logistic Activations unsupported with QAsymm8 data type."};
30 }
31
32 return arm_compute::NEActivationLayer::validate(&aclInput,
33 &aclOutput,
34 activationLayerInfo);
35}
36
Nattapat Chaimanowongd4b70592018-10-12 11:21:49 +010037NeonActivationWorkload::NeonActivationWorkload(const ActivationQueueDescriptor& descriptor,
38 const WorkloadInfo& info)
39 : BaseWorkload<ActivationQueueDescriptor>(descriptor, info)
telsoa014fcda012018-03-09 14:13:49 +000040{
Nattapat Chaimanowongd4b70592018-10-12 11:21:49 +010041 m_Data.ValidateInputsOutputs("NeonActivationWorkload", 1, 1);
telsoa014fcda012018-03-09 14:13:49 +000042
43 const arm_compute::ActivationLayerInfo activationLayerInfo =
44 ConvertActivationDescriptorToAclActivationLayerInfo(m_Data.m_Parameters);
45
46 arm_compute::ITensor& input = boost::polymorphic_downcast<INeonTensorHandle*>(m_Data.m_Inputs[0])->GetTensor();
47 arm_compute::ITensor& output = boost::polymorphic_downcast<INeonTensorHandle*>(m_Data.m_Outputs[0])->GetTensor();
48
Matthew Benthamd80a7122019-01-08 17:52:37 +000049 auto layer = std::make_unique<arm_compute::NEActivationLayer>();
50 layer->configure(&input, &output, activationLayerInfo);
51
52 m_ActivationLayer.reset(layer.release());
telsoa014fcda012018-03-09 14:13:49 +000053}
54
Nattapat Chaimanowongd4b70592018-10-12 11:21:49 +010055void NeonActivationWorkload::Execute() const
telsoa014fcda012018-03-09 14:13:49 +000056{
Nattapat Chaimanowongd4b70592018-10-12 11:21:49 +010057 ARMNN_SCOPED_PROFILING_EVENT_NEON("NeonActivationWorkload_Execute");
Matthew Benthamd80a7122019-01-08 17:52:37 +000058 m_ActivationLayer->run();
telsoa014fcda012018-03-09 14:13:49 +000059}
60
61} //namespace armnn