blob: d1e49d954c47ff292e5bd51d980898bcfef0eca2 [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
Ferran Balaguerb2b5a262019-06-24 12:43:38 +010028 if (((!outputQuantization.scale.empty()) && (outputQuantization.scale[0] != (1.0f / 256.0f))) ||
29 ((!outputQuantization.offset.empty()) && (outputQuantization.offset[0] != 0)) ||
30 (outputQuantization.scale.empty()) ||
31 (outputQuantization.offset.empty()))
telsoa014fcda012018-03-09 14:13:49 +000032 {
33 throw InvalidArgumentException(
34 "Invalid quantization for output. Only scale = 1.0f / 256.0f and offset = 0 supported");
35 }
Ferran Balaguerb2b5a262019-06-24 12:43:38 +010036
Narumol Prangnawarat65d30962019-03-14 11:55:03 +000037 unsigned int aclAxis = ComputeSoftmaxAclAxis(info.m_InputTensorInfos[0]);
telsoa014fcda012018-03-09 14:13:49 +000038
Matthew Benthamd80a7122019-01-08 17:52:37 +000039 auto layer = std::make_unique<arm_compute::NESoftmaxLayer>(memoryManager);
Narumol Prangnawarat65d30962019-03-14 11:55:03 +000040 layer->configure(&input, &output, descriptor.m_Parameters.m_Beta, aclAxis);
Matthew Benthamd80a7122019-01-08 17:52:37 +000041 m_SoftmaxLayer.reset(layer.release());
telsoa014fcda012018-03-09 14:13:49 +000042}
43
44void NeonSoftmaxUint8Workload::Execute() const
45{
telsoa01c577f2c2018-08-31 09:22:23 +010046 ARMNN_SCOPED_PROFILING_EVENT_NEON("NeonSoftmaxUint8Workload_Execute");
telsoa014fcda012018-03-09 14:13:49 +000047
Matthew Benthamd80a7122019-01-08 17:52:37 +000048 m_SoftmaxLayer->run();
telsoa014fcda012018-03-09 14:13:49 +000049}
surmeh013537c2c2018-05-18 16:31:43 +010050
telsoa014fcda012018-03-09 14:13:49 +000051} //namespace armnn
52