blob: 427f6b4f9214eebad51a6370155d933ddf29d2c2 [file] [log] [blame]
Sang-Hoon Park201e0fe2021-01-27 13:14:56 +00001/*
Viet-Hoa Do29254ae2023-10-13 17:40:32 +01002 * Copyright (c) 2021, 2023 Arm Limited.
Sang-Hoon Park201e0fe2021-01-27 13:14:56 +00003 *
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 */
Georgios Pinitas7891a732021-08-20 21:39:25 +010024#include "src/gpu/cl/operators/ClSoftmax.h"
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010025
Viet-Hoa Do29254ae2023-10-13 17:40:32 +010026#include "arm_compute/core/experimental/Types.h"
27#include "arm_compute/core/ITensorPack.h"
28#include "arm_compute/runtime/CL/CLScheduler.h"
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010029
30#include "src/common/utils/Log.h"
Manuel Bottini94f799e2021-06-09 16:37:32 +010031#include "src/core/helpers/MemoryHelpers.h"
Georgios Pinitas7891a732021-08-20 21:39:25 +010032#include "src/gpu/cl/kernels/ClSoftmaxKernel.h"
Georgios Pinitas7891a732021-08-20 21:39:25 +010033#include "src/gpu/cl/utils/ClAuxTensorHandler.h"
Sang-Hoon Park201e0fe2021-01-27 13:14:56 +000034
Manuel Bottini94f799e2021-06-09 16:37:32 +010035using namespace arm_compute::experimental;
36
Sang-Hoon Park201e0fe2021-01-27 13:14:56 +000037namespace arm_compute
38{
39namespace opencl
40{
Viet-Hoa Do29254ae2023-10-13 17:40:32 +010041
42ClSoftmax::ClSoftmax() : _aux_mem(InternalTensorIdx::COUNT)
Sang-Hoon Park201e0fe2021-01-27 13:14:56 +000043{
44}
45
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010046void ClSoftmax::configure(const CLCompileContext &compile_context,
47 const ITensorInfo &src,
48 ITensorInfo &dst,
49 const SoftmaxKernelInfo &info)
Sang-Hoon Park201e0fe2021-01-27 13:14:56 +000050{
ramelg012e53f172021-09-22 10:48:25 +010051 ARM_COMPUTE_LOG_PARAMS(src, dst, info);
Sang-Hoon Park201e0fe2021-01-27 13:14:56 +000052
Viet-Hoa Do29254ae2023-10-13 17:40:32 +010053 auto k = std::make_unique<kernels::ClSoftmaxKernel>();
54 k->configure(compile_context, src, dst, info);
Sang-Hoon Park201e0fe2021-01-27 13:14:56 +000055
Viet-Hoa Do29254ae2023-10-13 17:40:32 +010056 _tmp_info = k->tmp_tensor_info();
Sang-Hoon Park201e0fe2021-01-27 13:14:56 +000057
Viet-Hoa Do29254ae2023-10-13 17:40:32 +010058 _kernel = std::move(k);
Sang-Hoon Park201e0fe2021-01-27 13:14:56 +000059
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010060 _aux_mem[InternalTensorIdx::TMP] =
61 MemoryInfo(offset_int_vec(InternalTensorIdx::TMP), MemoryLifetime::Temporary, _tmp_info.total_size());
Sang-Hoon Park201e0fe2021-01-27 13:14:56 +000062}
63
64Status ClSoftmax::validate(const ITensorInfo &src, const ITensorInfo &dst, const SoftmaxKernelInfo &info)
65{
Viet-Hoa Do29254ae2023-10-13 17:40:32 +010066 return kernels::ClSoftmaxKernel::validate(src, dst, info);
Sang-Hoon Park201e0fe2021-01-27 13:14:56 +000067}
68
Sang-Hoon Park201e0fe2021-01-27 13:14:56 +000069void ClSoftmax::run(ITensorPack &tensors)
70{
Viet-Hoa Do29254ae2023-10-13 17:40:32 +010071 CLAuxTensorHandler tmp(offset_int_vec(InternalTensorIdx::TMP), _tmp_info, tensors);
Sang-Hoon Park201e0fe2021-01-27 13:14:56 +000072
Viet-Hoa Do29254ae2023-10-13 17:40:32 +010073 tensors.add_tensor(TensorType::ACL_INT_0, tmp.get());
Manuel Bottini94f799e2021-06-09 16:37:32 +010074
Viet-Hoa Do29254ae2023-10-13 17:40:32 +010075 CLScheduler::get().enqueue_op(*_kernel, tensors, false);
Sang-Hoon Park201e0fe2021-01-27 13:14:56 +000076}
77
78experimental::MemoryRequirements ClSoftmax::workspace() const
79{
Manuel Bottini94f799e2021-06-09 16:37:32 +010080 return _aux_mem;
Sang-Hoon Park201e0fe2021-01-27 13:14:56 +000081}
Viet-Hoa Do29254ae2023-10-13 17:40:32 +010082
Sang-Hoon Park201e0fe2021-01-27 13:14:56 +000083} // namespace opencl
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010084} // namespace arm_compute