1 //
2 // Copyright © 2020 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5
6 #include "ClSoftmaxWorkload.hpp"
7 #include "ClWorkloadUtils.hpp"
8
9 #include <aclCommon/ArmComputeTensorUtils.hpp>
10 #include <aclCommon/ArmComputeUtils.hpp>
11
12 #include <cl/ClTensorHandle.hpp>
13
14 namespace armnn
15 {
16
ClSoftmaxWorkloadValidate(const TensorInfo & input,const TensorInfo & output,const SoftmaxDescriptor & descriptor)17 arm_compute::Status ClSoftmaxWorkloadValidate(const TensorInfo& input,
18 const TensorInfo& output,
19 const SoftmaxDescriptor& descriptor)
20 {
21 const arm_compute::TensorInfo aclInputInfo = armcomputetensorutils::BuildArmComputeTensorInfo(input);
22 const arm_compute::TensorInfo aclOutputInfo = armcomputetensorutils::BuildArmComputeTensorInfo(output);
23
24 int aclAxis = ComputeAclAxis(descriptor.m_Axis, input);
25 return arm_compute::CLSoftmaxLayer::validate(&aclInputInfo, &aclOutputInfo, descriptor.m_Beta, aclAxis);
26 }
27
ClSoftmaxWorkload(const SoftmaxQueueDescriptor & descriptor,const WorkloadInfo & info,std::shared_ptr<arm_compute::MemoryManagerOnDemand> & memoryManager,const arm_compute::CLCompileContext & clCompileContext)28 ClSoftmaxWorkload::ClSoftmaxWorkload(const SoftmaxQueueDescriptor& descriptor,
29 const WorkloadInfo& info,
30 std::shared_ptr<arm_compute::MemoryManagerOnDemand>& memoryManager,
31 const arm_compute::CLCompileContext& clCompileContext)
32 : ClBaseWorkload<SoftmaxQueueDescriptor>(descriptor, info)
33 , m_SoftmaxLayer(memoryManager)
34 {
35 // Report Profiling Details
36 ARMNN_REPORT_PROFILING_WORKLOAD_DESC("ClSoftmaxWorkload_Construct",
37 descriptor.m_Parameters,
38 info,
39 this->GetGuid());
40
41 m_Data.ValidateInputsOutputs("ClSoftmaxWorkload", 1, 1);
42
43 arm_compute::ICLTensor& input = static_cast<ClTensorHandle*>(m_Data.m_Inputs[0])->GetTensor();
44 arm_compute::ICLTensor& output = static_cast<ClTensorHandle*>(m_Data.m_Outputs[0])->GetTensor();
45
46 int aclAxis = ComputeAclAxis(m_Data.m_Parameters.m_Axis, info.m_InputTensorInfos[0]);
47 {
48 ARMNN_SCOPED_PROFILING_EVENT(Compute::Undefined, "ClSoftmaxWorkload_configure");
49 m_SoftmaxLayer.configure(clCompileContext, &input, &output, m_Data.m_Parameters.m_Beta, aclAxis);
50 }
51 }
52
Execute() const53 void ClSoftmaxWorkload::Execute() const
54 {
55 ARMNN_SCOPED_PROFILING_EVENT_CL_GUID("ClSoftmaxWorkload_Execute", this->GetGuid());
56 RunClFunction(m_SoftmaxLayer, CHECK_LOCATION());
57 }
58
59 } // namespace armnn
60