blob: b36bf7695f6ecc311c84d02b69b47f3941a5b651 [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 Charlinefc5da42020-05-13 15:16:12 +010026 int aclAxis = ComputeSoftmaxAclAxis<int>(descriptor, input);
Sadik Armaganbe88a572020-04-30 11:39:37 +010027 return arm_compute::NESoftmaxLayer::validate(&aclInputInfo, &aclOutputInfo, descriptor.m_Beta, aclAxis);
28}
29
30NeonSoftmaxWorkload::NeonSoftmaxWorkload(const SoftmaxQueueDescriptor& descriptor,
31 const WorkloadInfo& info, std::shared_ptr<arm_compute::MemoryManagerOnDemand>& memoryManager)
32 : BaseWorkload<SoftmaxQueueDescriptor>(descriptor, info)
33{
34 m_Data.ValidateInputsOutputs("NeonSoftmaxWorkload", 1, 1);
35
36 // The ArmCompute softmax layer uses 2D input/output tensors, so flatten the first three dimensions.
37 arm_compute::ITensor& input = PolymorphicDowncast<IAclTensorHandle*>(m_Data.m_Inputs[0])->GetTensor();
38 arm_compute::ITensor& output = PolymorphicDowncast<IAclTensorHandle*>(m_Data.m_Outputs[0])->GetTensor();
39
40 auto layer = std::make_unique<arm_compute::NESoftmaxLayer>(memoryManager);
Teresa Charlinefc5da42020-05-13 15:16:12 +010041 int aclAxis = ComputeSoftmaxAclAxis<int>(m_Data.m_Parameters, info.m_InputTensorInfos[0]);
Sadik Armaganbe88a572020-04-30 11:39:37 +010042 layer->configure(&input, &output, m_Data.m_Parameters.m_Beta, aclAxis);
43 m_SoftmaxLayer.reset(layer.release());
44}
45
46void NeonSoftmaxWorkload::Execute() const
47{
48 ARMNN_SCOPED_PROFILING_EVENT_NEON("NeonSoftmaxWorkload_Execute");
49 m_SoftmaxLayer->run();
50}
51
52} //namespace armnn
53