blob: f14ea11c8257df27c96cad64803f979a06fb7d1c [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 "ClSoftmaxUint8Workload.hpp"
Narumol Prangnawarat65d30962019-03-14 11:55:03 +00007#include "ClWorkloadUtils.hpp"
8
9#include <aclCommon/ArmComputeUtils.hpp>
Aron Virginas-Tarc9cc8042018-11-01 16:15:57 +000010#include <cl/ClTensorHandle.hpp>
11#include <backendsCommon/CpuTensorHandle.hpp>
telsoa014fcda012018-03-09 14:13:49 +000012
13namespace armnn
14{
15
surmeh013537c2c2018-05-18 16:31:43 +010016ClSoftmaxUint8Workload::ClSoftmaxUint8Workload(const SoftmaxQueueDescriptor& descriptor, const WorkloadInfo& info,
17 std::shared_ptr<arm_compute::MemoryManagerOnDemand>& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +000018 : Uint8Workload<SoftmaxQueueDescriptor>(descriptor, info)
surmeh013537c2c2018-05-18 16:31:43 +010019 , m_SoftmaxLayer(memoryManager)
telsoa014fcda012018-03-09 14:13:49 +000020{
21 m_Data.ValidateInputsOutputs("ClSoftmaxUint8Workload", 1, 1);
22
23 arm_compute::ICLTensor& input = static_cast<ClTensorHandle*>(m_Data.m_Inputs[0])->GetTensor();
24 arm_compute::ICLTensor& output = static_cast<ClTensorHandle*>(m_Data.m_Outputs[0])->GetTensor();
25
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 }
35
Colm Donelanc3c5fc22019-08-15 16:03:17 +010036 unsigned int aclAxis = ComputeSoftmaxAclAxis(m_Data.m_Parameters, info.m_InputTensorInfos[0]);
Narumol Prangnawarat65d30962019-03-14 11:55:03 +000037 m_SoftmaxLayer.configure(&input, &output, descriptor.m_Parameters.m_Beta, aclAxis);
telsoa014fcda012018-03-09 14:13:49 +000038}
39
40void ClSoftmaxUint8Workload::Execute() const
41{
telsoa01c577f2c2018-08-31 09:22:23 +010042 ARMNN_SCOPED_PROFILING_EVENT_CL("ClSoftmaxUint8Workload_Execute");
Aron Virginas-Tara8e06ed2018-10-19 16:46:15 +010043 RunClFunction(m_SoftmaxLayer, CHECK_LOCATION());
telsoa014fcda012018-03-09 14:13:49 +000044}
45
46} //namespace armnn