blob: 15a7066861f7824ac0688e21e8b7237861ee885a [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
6#include "NeonSoftmaxUint8Workload.hpp"
Matthew Benthamd80a7122019-01-08 17:52:37 +00007#include "NeonWorkloadUtils.hpp"
8
Narumol Prangnawarat65d30962019-03-14 11:55:03 +00009#include <aclCommon/ArmComputeUtils.hpp>
10
Matthew Benthamd80a7122019-01-08 17:52:37 +000011#include <arm_compute/runtime/NEON/functions/NESoftmaxLayer.h>
12
telsoa014fcda012018-03-09 14:13:49 +000013namespace armnn
14{
surmeh013537c2c2018-05-18 16:31:43 +010015
16NeonSoftmaxUint8Workload::NeonSoftmaxUint8Workload(const SoftmaxQueueDescriptor& descriptor,
17 const WorkloadInfo& info,
18 std::shared_ptr<arm_compute::MemoryManagerOnDemand>& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +000019 : Uint8Workload<SoftmaxQueueDescriptor>(descriptor, info)
20{
21 m_Data.ValidateInputsOutputs("NeonSoftmaxUint8Workload", 1, 1);
22
Derek Lambertic81855f2019-06-13 17:34:19 +010023 arm_compute::ITensor& input = boost::polymorphic_downcast<IAclTensorHandle*>(m_Data.m_Inputs[0])->GetTensor();
24 arm_compute::ITensor& output = boost::polymorphic_downcast<IAclTensorHandle*>(m_Data.m_Outputs[0])->GetTensor();
telsoa014fcda012018-03-09 14:13:49 +000025
26 const auto outputQuantization = output.info()->quantization_info();
27
James Conroy33fa0a62019-07-04 16:56:44 +010028 if ((!outputQuantization.scale().empty() && outputQuantization.scale()[0] != (1.0f / 256.0f)) ||
29 (!outputQuantization.offset().empty() && outputQuantization.offset()[0] != 0) ||
30 outputQuantization.scale().empty() || outputQuantization.offset().empty())
telsoa014fcda012018-03-09 14:13:49 +000031 {
32 throw InvalidArgumentException(
33 "Invalid quantization for output. Only scale = 1.0f / 256.0f and offset = 0 supported");
34 }
Ferran Balaguerb2b5a262019-06-24 12:43:38 +010035
Matthew Benthamd80a7122019-01-08 17:52:37 +000036 auto layer = std::make_unique<arm_compute::NESoftmaxLayer>(memoryManager);
Colm Donelanc3c5fc22019-08-15 16:03:17 +010037 unsigned int aclAxis = ComputeSoftmaxAclAxis(m_Data.m_Parameters, info.m_InputTensorInfos[0]);
Narumol Prangnawarat65d30962019-03-14 11:55:03 +000038 layer->configure(&input, &output, descriptor.m_Parameters.m_Beta, aclAxis);
Matthew Benthamd80a7122019-01-08 17:52:37 +000039 m_SoftmaxLayer.reset(layer.release());
telsoa014fcda012018-03-09 14:13:49 +000040}
41
42void NeonSoftmaxUint8Workload::Execute() const
43{
telsoa01c577f2c2018-08-31 09:22:23 +010044 ARMNN_SCOPED_PROFILING_EVENT_NEON("NeonSoftmaxUint8Workload_Execute");
telsoa014fcda012018-03-09 14:13:49 +000045
Matthew Benthamd80a7122019-01-08 17:52:37 +000046 m_SoftmaxLayer->run();
telsoa014fcda012018-03-09 14:13:49 +000047}
surmeh013537c2c2018-05-18 16:31:43 +010048
telsoa014fcda012018-03-09 14:13:49 +000049} //namespace armnn
50