Compute Library
 23.08
NESoftmaxLayer.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017-2021 Arm Limited.
3  *
4  * SPDX-License-Identifier: MIT
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to
8  * deal in the Software without restriction, including without limitation the
9  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10  * sell copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
32 
33 namespace arm_compute
34 {
35 template <bool IS_LOG>
36 struct NESoftmaxLayerGeneric<IS_LOG>::Impl
37 {
38  const ITensor *src{ nullptr };
39  ITensor *dst{ nullptr };
40  Tensor max{ nullptr };
41  std::unique_ptr<cpu::CpuSoftmaxGeneric<IS_LOG>> op{ nullptr };
42  MemoryGroup memory_group{};
43  ITensorPack run_pack{};
44  WorkspaceData<Tensor> workspace_tensors{};
45 };
46 
47 template <bool IS_LOG>
48 NESoftmaxLayerGeneric<IS_LOG>::NESoftmaxLayerGeneric(std::shared_ptr<IMemoryManager> memory_manager)
49  : _impl(std::make_unique<Impl>())
50 {
51  _impl->memory_group = MemoryGroup(std::move(memory_manager));
52 }
53 
54 template <bool IS_LOG>
56 template <bool IS_LOG>
58 template <bool IS_LOG>
60 
61 template <bool IS_LOG>
62 void NESoftmaxLayerGeneric<IS_LOG>::configure(ITensor *input, ITensor *output, float beta, int32_t axis)
63 {
65 
66  _impl->src = input;
67  _impl->dst = output;
68  _impl->op = std::make_unique<cpu::CpuSoftmaxGeneric<IS_LOG>>();
69  _impl->op->configure(input->info(), output->info(), beta, axis);
70 
71  _impl->run_pack = { { TensorType::ACL_SRC, _impl->src }, { TensorType::ACL_DST, _impl->dst } };
72  _impl->workspace_tensors = manage_workspace<Tensor>(_impl->op->workspace(), _impl->memory_group, _impl->run_pack);
73 }
74 
75 template <bool IS_LOG>
76 Status NESoftmaxLayerGeneric<IS_LOG>::validate(const ITensorInfo *input, const ITensorInfo *output, float beta, int32_t axis)
77 {
80  return Status{};
81 }
82 
83 template <bool IS_LOG>
85 {
86  // Acquire all the temporaries
87  MemoryGroupResourceScope scope_mg(_impl->memory_group);
88  ARM_COMPUTE_ERROR_ON_NULLPTR(_impl->src, _impl->dst);
89  _impl->op->run(_impl->run_pack);
90 }
91 
92 template class NESoftmaxLayerGeneric<false>;
93 template class NESoftmaxLayerGeneric<true>;
94 
95 } // namespace arm_compute
arm_compute::test::validation::src
SimpleTensor< float > src
Definition: DFT.cpp:155
NESoftmaxLayer.h
CpuSoftmaxKernel.h
arm_compute::NESoftmaxLayerGeneric::operator=
NESoftmaxLayerGeneric & operator=(const NESoftmaxLayerGeneric &)=delete
Prevent instances of this class from being copied (As this class contains pointers)
arm_compute::test::validation::dst
auto dst
Definition: DFT.cpp:170
arm_compute::ITensor
Interface for CPU tensor.
Definition: ITensor.h:36
arm_compute::NESoftmaxLayerGeneric
Basic function to compute a SoftmaxLayer and a Log SoftmaxLayer.
Definition: NESoftmaxLayer.h:40
ARM_COMPUTE_RETURN_ON_ERROR
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:204
SoftmaxHelpers.h
arm_compute::NESoftmaxLayerGeneric::validate
static Status validate(const ITensorInfo *input, const ITensorInfo *output, float beta=1.0f, int32_t axis=0)
Static function to check if given info will lead to a valid configuration of NESoftmaxLayer.
Definition: NESoftmaxLayer.cpp:76
MemoryGroup.h
ARM_COMPUTE_ERROR_ON_NULLPTR
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161
arm_compute::ITensor::info
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
arm_compute::cpu::CpuSoftmaxGeneric
Basic function to compute a SoftmaxLayer and a Log SoftmaxLayer.
Definition: CpuSoftmax.h:57
arm_compute::NESoftmaxLayerGeneric::NESoftmaxLayerGeneric
NESoftmaxLayerGeneric(std::shared_ptr< IMemoryManager > memory_manager=nullptr)
Constructor.
Definition: NESoftmaxLayer.cpp:48
arm_compute::ACL_DST
@ ACL_DST
Definition: Types.h:55
arm_compute::Status
Status class.
Definition: Error.h:52
arm_compute::detail::ObjectType::Tensor
@ Tensor
arm_compute::NESoftmaxLayerGeneric::run
void run() override
Run the kernels contained in the function.
Definition: NESoftmaxLayer.cpp:84
Tensor.h
CpuSoftmax.h
MemoryHelpers.h
arm_compute::MemoryGroupResourceScope
Memory group resources scope handling class.
Definition: IMemoryGroup.h:82
arm_compute
Copyright (c) 2017-2023 Arm Limited.
Definition: introduction.dox:24
ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
Definition: Validate.h:163
arm_compute::NESoftmaxLayerGeneric::configure
void configure(ITensor *input, ITensor *output, float beta=1.0f, int32_t axis=0)
Set the input and output tensors.
Definition: NESoftmaxLayer.cpp:62
arm_compute::ACL_SRC
@ ACL_SRC
Definition: Types.h:44
arm_compute::ITensorInfo
Store the tensor's metadata.
Definition: ITensorInfo.h:43
Validate.h
arm_compute::NESoftmaxLayerGeneric::~NESoftmaxLayerGeneric
~NESoftmaxLayerGeneric()
Default destructor.
arm_compute::MemoryGroup
Memory group.
Definition: MemoryGroup.h:43
arm_compute::test::validation::input
auto input
Definition: LSTMLayerQuantized.cpp:486