blob: 7f295d6548c766d3155e1808fb559d81fa20c2bd [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
23 arm_compute::ITensor& input = boost::polymorphic_downcast<INeonTensorHandle*>(m_Data.m_Inputs[0])->GetTensor();
24 arm_compute::ITensor& output = boost::polymorphic_downcast<INeonTensorHandle*>(m_Data.m_Outputs[0])->GetTensor();
25
26 const auto outputQuantization = output.info()->quantization_info();
27
28 if ((outputQuantization.scale != (1.0f / 256.0f)) || (outputQuantization.offset != 0))
29 {
30 throw InvalidArgumentException(
31 "Invalid quantization for output. Only scale = 1.0f / 256.0f and offset = 0 supported");
32 }
Narumol Prangnawarat65d30962019-03-14 11:55:03 +000033 unsigned int aclAxis = ComputeSoftmaxAclAxis(info.m_InputTensorInfos[0]);
telsoa014fcda012018-03-09 14:13:49 +000034
Matthew Benthamd80a7122019-01-08 17:52:37 +000035 auto layer = std::make_unique<arm_compute::NESoftmaxLayer>(memoryManager);
Narumol Prangnawarat65d30962019-03-14 11:55:03 +000036 layer->configure(&input, &output, descriptor.m_Parameters.m_Beta, aclAxis);
Matthew Benthamd80a7122019-01-08 17:52:37 +000037 m_SoftmaxLayer.reset(layer.release());
telsoa014fcda012018-03-09 14:13:49 +000038}
39
40void NeonSoftmaxUint8Workload::Execute() const
41{
telsoa01c577f2c2018-08-31 09:22:23 +010042 ARMNN_SCOPED_PROFILING_EVENT_NEON("NeonSoftmaxUint8Workload_Execute");
telsoa014fcda012018-03-09 14:13:49 +000043
Matthew Benthamd80a7122019-01-08 17:52:37 +000044 m_SoftmaxLayer->run();
telsoa014fcda012018-03-09 14:13:49 +000045}
surmeh013537c2c2018-05-18 16:31:43 +010046
telsoa014fcda012018-03-09 14:13:49 +000047} //namespace armnn
48