blob: 505844e24aef78e4add18225a3f1549325d8d080 [file] [log] [blame]
Sadik Armaganbe88a572020-04-30 11:39:37 +01001//
2// Copyright © 2020 Arm Ltd. All rights reserved.
3// 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)
35 : BaseWorkload<SoftmaxQueueDescriptor>(descriptor, info)
36{
37 m_Data.ValidateInputsOutputs("NeonSoftmaxWorkload", 1, 1);
38
39 // The ArmCompute softmax layer uses 2D input/output tensors, so flatten the first three dimensions.
40 arm_compute::ITensor& input = PolymorphicDowncast<IAclTensorHandle*>(m_Data.m_Inputs[0])->GetTensor();
41 arm_compute::ITensor& output = PolymorphicDowncast<IAclTensorHandle*>(m_Data.m_Outputs[0])->GetTensor();
42
43 auto layer = std::make_unique<arm_compute::NESoftmaxLayer>(memoryManager);
Teresa Charline3866762020-08-28 15:13:05 +010044 int aclAxis = ComputeAclAxis(m_Data.m_Parameters.m_Axis, info.m_InputTensorInfos[0]);
45 layer->configure(&input, &output, m_Data.m_Parameters.m_Beta, aclAxis);
Sadik Armaganbe88a572020-04-30 11:39:37 +010046 m_SoftmaxLayer.reset(layer.release());
47}
48
49void NeonSoftmaxWorkload::Execute() const
50{
51 ARMNN_SCOPED_PROFILING_EVENT_NEON("NeonSoftmaxWorkload_Execute");
52 m_SoftmaxLayer->run();
53}
54
55} //namespace armnn
56