telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
David Beck | ecb56cd | 2018-09-05 12:52:57 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 4 | // |
| 5 | |
| 6 | #include "NeonSoftmaxUint8Workload.hpp" |
Matthew Bentham | d80a712 | 2019-01-08 17:52:37 +0000 | [diff] [blame] | 7 | #include "NeonWorkloadUtils.hpp" |
| 8 | |
Narumol Prangnawarat | 65d3096 | 2019-03-14 11:55:03 +0000 | [diff] [blame] | 9 | #include <aclCommon/ArmComputeUtils.hpp> |
| 10 | |
Matthew Bentham | d80a712 | 2019-01-08 17:52:37 +0000 | [diff] [blame] | 11 | #include <arm_compute/runtime/NEON/functions/NESoftmaxLayer.h> |
| 12 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 13 | namespace armnn |
| 14 | { |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 15 | |
| 16 | NeonSoftmaxUint8Workload::NeonSoftmaxUint8Workload(const SoftmaxQueueDescriptor& descriptor, |
| 17 | const WorkloadInfo& info, |
| 18 | std::shared_ptr<arm_compute::MemoryManagerOnDemand>& memoryManager) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 19 | : Uint8Workload<SoftmaxQueueDescriptor>(descriptor, info) |
| 20 | { |
| 21 | m_Data.ValidateInputsOutputs("NeonSoftmaxUint8Workload", 1, 1); |
| 22 | |
Derek Lamberti | c81855f | 2019-06-13 17:34:19 +0100 | [diff] [blame] | 23 | 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(); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 25 | |
| 26 | const auto outputQuantization = output.info()->quantization_info(); |
| 27 | |
James Conroy | 33fa0a6 | 2019-07-04 16:56:44 +0100 | [diff] [blame^] | 28 | 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()) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 31 | { |
| 32 | throw InvalidArgumentException( |
| 33 | "Invalid quantization for output. Only scale = 1.0f / 256.0f and offset = 0 supported"); |
| 34 | } |
Ferran Balaguer | b2b5a26 | 2019-06-24 12:43:38 +0100 | [diff] [blame] | 35 | |
Narumol Prangnawarat | 65d3096 | 2019-03-14 11:55:03 +0000 | [diff] [blame] | 36 | unsigned int aclAxis = ComputeSoftmaxAclAxis(info.m_InputTensorInfos[0]); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 37 | |
Matthew Bentham | d80a712 | 2019-01-08 17:52:37 +0000 | [diff] [blame] | 38 | auto layer = std::make_unique<arm_compute::NESoftmaxLayer>(memoryManager); |
Narumol Prangnawarat | 65d3096 | 2019-03-14 11:55:03 +0000 | [diff] [blame] | 39 | layer->configure(&input, &output, descriptor.m_Parameters.m_Beta, aclAxis); |
Matthew Bentham | d80a712 | 2019-01-08 17:52:37 +0000 | [diff] [blame] | 40 | m_SoftmaxLayer.reset(layer.release()); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | void NeonSoftmaxUint8Workload::Execute() const |
| 44 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 45 | ARMNN_SCOPED_PROFILING_EVENT_NEON("NeonSoftmaxUint8Workload_Execute"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 46 | |
Matthew Bentham | d80a712 | 2019-01-08 17:52:37 +0000 | [diff] [blame] | 47 | m_SoftmaxLayer->run(); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 48 | } |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 49 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 50 | } //namespace armnn |
| 51 | |