Georgios Pinitas | 399f623 | 2021-06-29 15:31:58 +0100 | [diff] [blame] | 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 | */ |
Georgios Pinitas | 7891a73 | 2021-08-20 21:39:25 +0100 | [diff] [blame] | 24 | #include "src/gpu/cl/operators/ClGemmLowpOutputStage.h" |
Georgios Pinitas | 399f623 | 2021-06-29 15:31:58 +0100 | [diff] [blame] | 25 | |
| 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 Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 30 | #include "src/common/utils/Log.h" |
Georgios Pinitas | 7891a73 | 2021-08-20 21:39:25 +0100 | [diff] [blame] | 31 | #include "src/gpu/cl/kernels/ClGemmLowpQuantizeDownInt32ScaleByFixedPointKernel.h" |
| 32 | #include "src/gpu/cl/kernels/ClGemmLowpQuantizeDownInt32ScaleByFloatKernel.h" |
| 33 | #include "src/gpu/cl/kernels/ClGemmLowpQuantizeDownInt32ScaleKernel.h" |
Georgios Pinitas | 399f623 | 2021-06-29 15:31:58 +0100 | [diff] [blame] | 34 | |
| 35 | namespace arm_compute |
| 36 | { |
| 37 | namespace opencl |
| 38 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 39 | void ClGemmLowpOutputStage::configure(const CLCompileContext &compile_context, |
| 40 | const ITensorInfo *src, |
| 41 | const ITensorInfo *bias, |
| 42 | ITensorInfo *dst, |
| 43 | const GEMMLowpOutputStageInfo &info) |
Georgios Pinitas | 399f623 | 2021-06-29 15:31:58 +0100 | [diff] [blame] | 44 | { |
| 45 | ARM_COMPUTE_ERROR_ON_NULLPTR(src, dst); |
ramelg01 | 2e53f17 | 2021-09-22 10:48:25 +0100 | [diff] [blame] | 46 | ARM_COMPUTE_LOG_PARAMS(src, bias, dst, info); |
Georgios Pinitas | 399f623 | 2021-06-29 15:31:58 +0100 | [diff] [blame] | 47 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 48 | switch (info.type) |
Georgios Pinitas | 399f623 | 2021-06-29 15:31:58 +0100 | [diff] [blame] | 49 | { |
| 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 Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 76 | Status ClGemmLowpOutputStage::validate(const ITensorInfo *src, |
| 77 | const ITensorInfo *bias, |
| 78 | const ITensorInfo *dst, |
| 79 | const GEMMLowpOutputStageInfo &info) |
Georgios Pinitas | 399f623 | 2021-06-29 15:31:58 +0100 | [diff] [blame] | 80 | { |
| 81 | ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(dst); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 82 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(dst, 1, DataType::QASYMM8, DataType::QASYMM8_SIGNED, |
| 83 | DataType::QSYMM16); |
Georgios Pinitas | 399f623 | 2021-06-29 15:31:58 +0100 | [diff] [blame] | 84 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 85 | switch (info.type) |
Georgios Pinitas | 399f623 | 2021-06-29 15:31:58 +0100 | [diff] [blame] | 86 | { |
| 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 | |
| 98 | void 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 Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 104 | ITensorPack pack{{ACL_SRC, src}, {ACL_BIAS, bias}, {ACL_DST, dst}}; |
Georgios Pinitas | 399f623 | 2021-06-29 15:31:58 +0100 | [diff] [blame] | 105 | CLScheduler::get().enqueue_op(*_kernel, pack, true); |
| 106 | } |
| 107 | } // namespace opencl |
| 108 | } // namespace arm_compute |