ArmNN
 21.02
NeonSoftmaxWorkload.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2020 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
7 #include "NeonWorkloadUtils.hpp"
8 
10 
13 
14 #include <arm_compute/runtime/NEON/functions/NESoftmaxLayer.h>
15 
16 namespace armnn
17 {
18 
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 
26  int aclAxis = ComputeAclAxis(descriptor.m_Axis, input);
27  return arm_compute::NESoftmaxLayer::validate(&aclInputInfo,
28  &aclOutputInfo,
29  descriptor.m_Beta,
30  aclAxis);
31 }
32 
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);
45  layer->configure(&input, &output, m_Data.m_Parameters.m_Beta, aclAxis);
46  m_SoftmaxLayer.reset(layer.release());
47 }
48 
50 {
51  ARMNN_SCOPED_PROFILING_EVENT_NEON("NeonSoftmaxWorkload_Execute");
52  m_SoftmaxLayer->run();
53 }
54 
55 } //namespace armnn
56 
virtual void Execute() const override
int ComputeAclAxis(const int &armnnAxis, const armnn::TensorInfo &tensor)
Function to convert ArmNN axis (left to right) to ACL axis (right to left) ranging from [-rank...
int m_Axis
Scalar, defaulted to the last index (-1), specifying the dimension the activation will be performed o...
const SoftmaxQueueDescriptor m_Data
Definition: Workload.hpp:46
#define ARMNN_SCOPED_PROFILING_EVENT_NEON(name)
float m_Beta
Exponentiation value.
void ValidateInputsOutputs(const std::string &descName, unsigned int numExpectedIn, unsigned int numExpectedOut) const
Copyright (c) 2021 ARM Limited and Contributors.
std::vector< TensorInfo > m_InputTensorInfos
Status
enumeration
Definition: Types.hpp:26
NeonSoftmaxWorkload(const SoftmaxQueueDescriptor &descriptor, const WorkloadInfo &info, std::shared_ptr< arm_compute::MemoryManagerOnDemand > &memoryManager)
std::vector< ITensorHandle * > m_Outputs
arm_compute::Status NeonSoftmaxWorkloadValidate(const TensorInfo &input, const TensorInfo &output, const SoftmaxDescriptor &descriptor)
Contains information about inputs and outputs to a layer.
std::vector< ITensorHandle * > m_Inputs
A SoftmaxDescriptor for the SoftmaxLayer.