blob: 84d735cdf78be6d97bd752f76289455ad54cba82 [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
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 }
36
Narumol Prangnawarat65d30962019-03-14 11:55:03 +000037 unsigned int aclAxis = ComputeSoftmaxAclAxis(info.m_InputTensorInfos[0]);
38 m_SoftmaxLayer.configure(&input, &output, descriptor.m_Parameters.m_Beta, aclAxis);
telsoa014fcda012018-03-09 14:13:49 +000039}
40
41void ClSoftmaxUint8Workload::Execute() const
42{
telsoa01c577f2c2018-08-31 09:22:23 +010043 ARMNN_SCOPED_PROFILING_EVENT_CL("ClSoftmaxUint8Workload_Execute");
Aron Virginas-Tara8e06ed2018-10-19 16:46:15 +010044 RunClFunction(m_SoftmaxLayer, CHECK_LOCATION());
telsoa014fcda012018-03-09 14:13:49 +000045}
46
47} //namespace armnn