Debian Codegraph @

arm_compute/runtime/experimental/operators/CpuSoftmax.h

raw
1 /*
2 * Copyright (c) 2021-2024 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
25 #ifndef ACL_ARM_COMPUTE_RUNTIME_EXPERIMENTAL_OPERATORS_CPUSOFTMAX_H
26 #define ACL_ARM_COMPUTE_RUNTIME_EXPERIMENTAL_OPERATORS_CPUSOFTMAX_H
27
28 #include "arm_compute/core/TensorInfo.h"
29 #include "arm_compute/runtime/IOperator.h"
30
31 #include <memory>
32
33 namespace arm_compute
34 {
35 namespace experimental
36 {
37 namespace op
38 {
39 class CpuSoftmaxKernel;
40
41 /*
42 * A shallow wrapper for arm_compute::cpu::CpuSoftmaxGeneric.
43 * Any new features should be added to arm_compute::cpu::CpuSoftmaxGeneric
44 * and arm_compute::experimental::op::CpuSoftmax should remain a shallow wrapper.
45 */
46 class CpuSoftmax : public IOperator
47 {
48 public:
49 /** Constructor **/
50 CpuSoftmax();
51 /** Prevent instances of this class from being copied (As this class contains pointers) */
52 CpuSoftmax(const CpuSoftmax &) = delete;
53 /** Prevent copy assignment */
54 CpuSoftmax &operator=(const CpuSoftmax &) = delete;
55 /** Default move constructor */
56 CpuSoftmax(CpuSoftmax &&) = default;
57 /** Default move assignment */
58 CpuSoftmax &operator=(CpuSoftmax &&) = default;
59 /** Default destructor */
60 ~CpuSoftmax() override;
61 /** Set the input and output tensors.
62 *
63 * Valid data type configurations:
64 * |src |dst |
65 * |:--------------|:--------------|
66 * |QASYMM8 |QASYMM8 |
67 * |QASYMM8_SIGNED |QASYMM8_SIGNED |
68 * |F16 |F16 |
69 * |F32 |F32 |
70 *
71 * @param[in,out] src Source tensor info. Data types supported: QASYMM8/QASYMM8_SIGNED/F16/F32.
72 * last value of each row to the nearest multiple.
73 * @param[out] dst Destination tensor ifo. Data types supported: same as @p input.
74 * @param[in] beta (Optional) A scaling factor for the exponent.
75 * @param[in] axis (Optional) The dimension in which to apply the function. E.g. for input of shape 4x5x6 and
76 * axis=1, softmax will be applied to 4x6=24 vectors of size 5. Defaults to 0
77 * @param[in] is_log True if the operation is log-softmax
78 */
79 void configure(const ITensorInfo *src, ITensorInfo *dst, float beta = 1.0f, int32_t axis = 0, bool is_log = false);
80 /** Static function to check if given info will lead to a valid configuration
81 *
82 * Similar to @ref CpuSoftmax::configure()
83 *
84 * @return a status
85 */
86 static Status
87 validate(const ITensorInfo *src, const ITensorInfo *dst, float beta = 1.0f, int32_t axis = 0, bool is_log = false);
88
89 // Inherited methods overridden:
90 void run(ITensorPack &tensors) override;
91 experimental::MemoryRequirements workspace() const override;
92
93 // Unused
94 void prepare(ITensorPack &constants) override;
95
96 private:
97 struct Impl;
98 std::unique_ptr<Impl> impl_;
99 };
100
101 } // namespace op
102 } // namespace experimental
103 } // namespace arm_compute
104 #endif // ACL_ARM_COMPUTE_RUNTIME_EXPERIMENTAL_OPERATORS_CPUSOFTMAX_H