blob: e3363e36857e0d8bb94e96e390649b09f36212b1 [file] [log] [blame]
Georgios Pinitas399f6232021-06-29 15:31:58 +01001/*
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 */
Georgios Pinitas7891a732021-08-20 21:39:25 +010024#include "src/gpu/cl/operators/ClGemmLowpOutputStage.h"
Georgios Pinitas399f6232021-06-29 15:31:58 +010025
26#include "arm_compute/core/CL/ICLTensor.h"
27#include "arm_compute/core/Types.h"
28#include "arm_compute/runtime/CL/CLScheduler.h"
29
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010030#include "src/common/utils/Log.h"
Georgios Pinitas7891a732021-08-20 21:39:25 +010031#include "src/gpu/cl/kernels/ClGemmLowpQuantizeDownInt32ScaleByFixedPointKernel.h"
32#include "src/gpu/cl/kernels/ClGemmLowpQuantizeDownInt32ScaleByFloatKernel.h"
33#include "src/gpu/cl/kernels/ClGemmLowpQuantizeDownInt32ScaleKernel.h"
Georgios Pinitas399f6232021-06-29 15:31:58 +010034
35namespace arm_compute
36{
37namespace opencl
38{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010039void ClGemmLowpOutputStage::configure(const CLCompileContext &compile_context,
40 const ITensorInfo *src,
41 const ITensorInfo *bias,
42 ITensorInfo *dst,
43 const GEMMLowpOutputStageInfo &info)
Georgios Pinitas399f6232021-06-29 15:31:58 +010044{
45 ARM_COMPUTE_ERROR_ON_NULLPTR(src, dst);
ramelg012e53f172021-09-22 10:48:25 +010046 ARM_COMPUTE_LOG_PARAMS(src, bias, dst, info);
Georgios Pinitas399f6232021-06-29 15:31:58 +010047
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010048 switch (info.type)
Georgios Pinitas399f6232021-06-29 15:31:58 +010049 {
50 case GEMMLowpOutputStageType::QUANTIZE_DOWN_FIXEDPOINT:
51 {
52 auto k = std::make_unique<opencl::kernels::ClGemmLowpQuantizeDownInt32ScaleByFixedPointKernel>();
53 k->configure(compile_context, src, bias, dst, &info);
54 _kernel = std::move(k);
55 break;
56 }
57 case GEMMLowpOutputStageType::QUANTIZE_DOWN:
58 {
59 auto k = std::make_unique<opencl::kernels::ClGemmLowpQuantizeDownInt32ScaleKernel>();
60 k->configure(compile_context, src, bias, dst, &info);
61 _kernel = std::move(k);
62 break;
63 }
64 case GEMMLowpOutputStageType::QUANTIZE_DOWN_FLOAT:
65 {
66 auto k = std::make_unique<opencl::kernels::ClGemmLowpQuantizeDownInt32ScaleByFloatKernel>();
67 k->configure(compile_context, src, bias, dst, &info);
68 _kernel = std::move(k);
69 break;
70 }
71 default:
72 ARM_COMPUTE_ERROR("Unsupported GEMMLowpOutputStage type.");
73 }
74}
75
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010076Status ClGemmLowpOutputStage::validate(const ITensorInfo *src,
77 const ITensorInfo *bias,
78 const ITensorInfo *dst,
79 const GEMMLowpOutputStageInfo &info)
Georgios Pinitas399f6232021-06-29 15:31:58 +010080{
81 ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(dst);
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010082 ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(dst, 1, DataType::QASYMM8, DataType::QASYMM8_SIGNED,
83 DataType::QSYMM16);
Georgios Pinitas399f6232021-06-29 15:31:58 +010084
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010085 switch (info.type)
Georgios Pinitas399f6232021-06-29 15:31:58 +010086 {
87 case GEMMLowpOutputStageType::QUANTIZE_DOWN_FIXEDPOINT:
88 return opencl::kernels::ClGemmLowpQuantizeDownInt32ScaleByFixedPointKernel::validate(src, bias, dst, &info);
89 case GEMMLowpOutputStageType::QUANTIZE_DOWN:
90 return opencl::kernels::ClGemmLowpQuantizeDownInt32ScaleKernel::validate(src, bias, dst, &info);
91 case GEMMLowpOutputStageType::QUANTIZE_DOWN_FLOAT:
92 return opencl::kernels::ClGemmLowpQuantizeDownInt32ScaleByFloatKernel::validate(src, bias, dst, &info);
93 default:
94 return ARM_COMPUTE_CREATE_ERROR(ErrorCode::RUNTIME_ERROR, "Unsupported GEMMLowpOutputStage type.");
95 }
96}
97
98void ClGemmLowpOutputStage::run(ITensorPack &tensors)
99{
100 const ITensor *src = tensors.get_const_tensor(ACL_SRC);
101 const ITensor *bias = tensors.get_const_tensor(ACL_BIAS);
102 ITensor *dst = tensors.get_tensor(ACL_DST);
103
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100104 ITensorPack pack{{ACL_SRC, src}, {ACL_BIAS, bias}, {ACL_DST, dst}};
Georgios Pinitas399f6232021-06-29 15:31:58 +0100105 CLScheduler::get().enqueue_op(*_kernel, pack, true);
106}
107} // namespace opencl
108} // namespace arm_compute