24.02.1
CLSoftmaxLayer.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2017-2021, 2023 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
*/
24
#ifndef ACL_ARM_COMPUTE_RUNTIME_CL_FUNCTIONS_CLSOFTMAXLAYER_H
25
#define ACL_ARM_COMPUTE_RUNTIME_CL_FUNCTIONS_CLSOFTMAXLAYER_H
26
27
#include "
arm_compute/runtime/IFunction.h
"
28
#include "
arm_compute/runtime/IMemoryManager.h
"
29
#include "
arm_compute/runtime/MemoryGroup.h
"
30
31
#include <memory>
32
33
namespace
arm_compute
34
{
35
class
ICLTensor;
36
class
ITensorInfo;
37
class
CLCompileContext;
38
39
/** Basic function to compute a SoftmaxLayer.
40
*
41
* Softmax is calculated by :
42
* @f[ out = exp((x - max(x)) * beta) / sum(exp((x - max(x)) * beta)) @f]
43
*
44
* Log Softmax is calculated by :
45
* @f[ out = (x - max(x) * beta) - log(\sum{e^{x - max(x) * beta}}) @f]
46
*/
47
template
<
bool
IS_LOG = false>
48
class
CLSoftmaxLayerGeneric
:
public
IFunction
49
{
50
public
:
51
/** Constructor */
52
CLSoftmaxLayerGeneric
(std::shared_ptr<IMemoryManager> memory_manager =
nullptr
);
53
/** Default destructor */
54
~CLSoftmaxLayerGeneric
();
55
/** Set the input and output tensors.
56
*
57
* Valid data layouts:
58
* - All
59
*
60
* Valid data type configurations:
61
* |src |dst |
62
* |:--------------|:--------------|
63
* |QASYMM8 |QASYMM8 |
64
* |QASYMM8_SIGNED |QASYMM8_SIGNED |
65
* |F16 |F16 |
66
* |F32 |F32 |
67
*
68
* @param[in] input Source tensor. Data types supported: QASYMM8/QASYMM8_SIGNED/F16/F32 for Softmax and F16/F32 for Log Softmax
69
* @param[out] output Destination tensor. Data types supported: same as @p input
70
* @param[in] beta (Optional) A scaling factor for the exponent. Defaults to 1.f
71
* @param[in] axis (Optional) The dimension in which to apply the function. E.g. for input of shape 4x5x6 and
72
* axis=1, softmax will be applied to 4x6=24 vectors of size 5. Defaults to 0
73
*/
74
void
configure
(
const
ICLTensor
*
input
,
ICLTensor
*output,
float
beta = 1.0f, int32_t axis = 0);
75
/** Set the input and output tensors.
76
*
77
* @param[in] compile_context The compile context to be used.
78
* @param[in] input Source tensor. Data types supported: QASYMM8/QASYMM8_SIGNED/F16/F32 for Softmax and F16/F32 for Log Softmax
79
* @param[out] output Destination tensor. Data types supported: same as @p input
80
* @param[in] beta (Optional) A scaling factor for the exponent. Defaults to 1.f
81
* @param[in] axis (Optional) The dimension in which to apply the function. E.g. for input of shape 4x5x6 and
82
* axis=1, softmax will be applied to 4x6=24 vectors of size 5. Defaults to 0
83
*/
84
void
configure
(
const
CLCompileContext
&compile_context,
85
const
ICLTensor
*
input
,
86
ICLTensor
*output,
87
float
beta = 1.0f,
88
int32_t axis = 0);
89
/** Static function to check if given info will lead to a valid configuration of @ref CLSoftmaxLayer
90
*
91
* @param[in] input Source tensor. Data types supported: QASYMM8/QASYMM8_SIGNED/F16/F32 for Softmax and F16/F32 for Log Softmax
92
* @param[in] output Destination tensor. Data types supported: same as @p input
93
* @param[in] beta (Optional) A scaling factor for the exponent. Defaults to 1.f
94
* @param[in] axis (Optional) The dimension in which to apply the function. E.g. for input of shape 4x5x6 and
95
* axis=1, softmax will be applied to 4x6=24 vectors of size 5. Defaults to 0
96
*
97
* @return a status
98
*/
99
static
Status
validate
(
const
ITensorInfo
*
input
,
const
ITensorInfo
*output,
float
beta = 1.0f, int32_t axis = 0);
100
101
// Inherited methods overridden:
102
void
run
()
override
;
103
104
private
:
105
struct
Impl;
106
std::unique_ptr<Impl> _impl;
107
};
108
109
using
CLSoftmaxLayer
=
CLSoftmaxLayerGeneric<false>
;
110
using
CLLogSoftmaxLayer
=
CLSoftmaxLayerGeneric<true>
;
111
}
// namespace arm_compute
112
#endif // ACL_ARM_COMPUTE_RUNTIME_CL_FUNCTIONS_CLSOFTMAXLAYER_H
arm_compute::CLSoftmaxLayerGeneric::run
void run() override
Run the kernels contained in the function.
Definition:
CLSoftmaxLayer.cpp:93
arm_compute::IFunction
Base class for all functions.
Definition:
IFunction.h:30
arm_compute::ICLTensor
Interface for OpenCL tensor.
Definition:
ICLTensor.h:41
arm_compute::CLSoftmaxLayerGeneric::CLSoftmaxLayerGeneric
CLSoftmaxLayerGeneric(std::shared_ptr< IMemoryManager > memory_manager=nullptr)
Constructor.
Definition:
CLSoftmaxLayer.cpp:54
arm_compute::CLSoftmaxLayerGeneric::configure
void configure(const ICLTensor *input, ICLTensor *output, float beta=1.0f, int32_t axis=0)
Set the input and output tensors.
Definition:
CLSoftmaxLayer.cpp:64
MemoryGroup.h
IMemoryManager.h
arm_compute::CLCompileContext
CLCompileContext class.
Definition:
CLCompileContext.h:204
arm_compute::Status
Status class.
Definition:
Error.h:52
arm_compute::CLSoftmaxLayerGeneric::~CLSoftmaxLayerGeneric
~CLSoftmaxLayerGeneric()
Default destructor.
arm_compute::CLSoftmaxLayerGeneric
Basic function to compute a SoftmaxLayer.
Definition:
CLSoftmaxLayer.h:48
IFunction.h
arm_compute::CLSoftmaxLayerGeneric::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 CLSoftmaxLayer.
Definition:
CLSoftmaxLayer.cpp:86
arm_compute
Copyright (c) 2017-2024 Arm Limited.
Definition:
introduction.dox:24
arm_compute::ITensorInfo
Store the tensor's metadata.
Definition:
ITensorInfo.h:44
arm_compute::test::validation::input
auto input
Definition:
LSTMLayerQuantized.cpp:486
arm_compute
runtime
CL
functions
CLSoftmaxLayer.h
Generated on Mon Mar 18 2024 11:31:55 for Compute Library by
1.8.17