blob: f2bc0849131bdb03bc35650a8118c99605051f79 [file] [log] [blame]
Sadik Armaganbe88a572020-04-30 11:39:37 +01001//
Teresa Charlin588cbdf2022-01-19 15:55:37 +00002// Copyright © 2020 Arm Ltd and Contributors. All rights reserved.
Sadik Armaganbe88a572020-04-30 11:39:37 +01003// SPDX-License-Identifier: MIT
4//
5
6#include "NeonSoftmaxWorkload.hpp"
7#include "NeonWorkloadUtils.hpp"
8
9#include <armnn/utility/PolymorphicDowncast.hpp>
10
11#include <aclCommon/ArmComputeUtils.hpp>
12#include <aclCommon/ArmComputeTensorUtils.hpp>
13
14#include <arm_compute/runtime/NEON/functions/NESoftmaxLayer.h>
15
16namespace armnn
17{
18
19arm_compute::Status NeonSoftmaxWorkloadValidate(const TensorInfo& input,
20 const TensorInfo& output,
21 const SoftmaxDescriptor& descriptor)
22{
23 const arm_compute::TensorInfo aclInputInfo = armcomputetensorutils::BuildArmComputeTensorInfo(input);
24 const arm_compute::TensorInfo aclOutputInfo = armcomputetensorutils::BuildArmComputeTensorInfo(output);
25
Teresa Charline3866762020-08-28 15:13:05 +010026 int aclAxis = ComputeAclAxis(descriptor.m_Axis, input);
Teresa Charlin9cf7f882020-08-07 16:00:38 +010027 return arm_compute::NESoftmaxLayer::validate(&aclInputInfo,
28 &aclOutputInfo,
29 descriptor.m_Beta,
Teresa Charline3866762020-08-28 15:13:05 +010030 aclAxis);
Sadik Armaganbe88a572020-04-30 11:39:37 +010031}
32
33NeonSoftmaxWorkload::NeonSoftmaxWorkload(const SoftmaxQueueDescriptor& descriptor,
34 const WorkloadInfo& info, std::shared_ptr<arm_compute::MemoryManagerOnDemand>& memoryManager)
Teresa Charlin588cbdf2022-01-19 15:55:37 +000035 : NeonBaseWorkload<SoftmaxQueueDescriptor>(descriptor, info)
Sadik Armaganbe88a572020-04-30 11:39:37 +010036{
Keith Davis2d0679f2021-08-05 11:35:00 +010037 // Report Profiling Details
38 ARMNN_REPORT_PROFILING_WORKLOAD_DESC("NeonSoftmaxWorkload_Construct",
39 descriptor.m_Parameters,
40 info,
41 this->GetGuid());
42
Sadik Armaganbe88a572020-04-30 11:39:37 +010043 m_Data.ValidateInputsOutputs("NeonSoftmaxWorkload", 1, 1);
44
45 // The ArmCompute softmax layer uses 2D input/output tensors, so flatten the first three dimensions.
46 arm_compute::ITensor& input = PolymorphicDowncast<IAclTensorHandle*>(m_Data.m_Inputs[0])->GetTensor();
47 arm_compute::ITensor& output = PolymorphicDowncast<IAclTensorHandle*>(m_Data.m_Outputs[0])->GetTensor();
48
49 auto layer = std::make_unique<arm_compute::NESoftmaxLayer>(memoryManager);
Teresa Charline3866762020-08-28 15:13:05 +010050 int aclAxis = ComputeAclAxis(m_Data.m_Parameters.m_Axis, info.m_InputTensorInfos[0]);
51 layer->configure(&input, &output, m_Data.m_Parameters.m_Beta, aclAxis);
Sadik Armaganbe88a572020-04-30 11:39:37 +010052 m_SoftmaxLayer.reset(layer.release());
53}
54
55void NeonSoftmaxWorkload::Execute() const
56{
Keith Davis2d0679f2021-08-05 11:35:00 +010057 ARMNN_SCOPED_PROFILING_EVENT_NEON_GUID("NeonSoftmaxWorkload_Execute", this->GetGuid());
Sadik Armaganbe88a572020-04-30 11:39:37 +010058 m_SoftmaxLayer->run();
59}
60
61} //namespace armnn
62