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 | |
Georgios Pinitas | 7891a73 | 2021-08-20 21:39:25 +0100 | [diff] [blame] | 30 | #include "src/gpu/cl/kernels/ClGemmLowpQuantizeDownInt32ScaleByFixedPointKernel.h" |
| 31 | #include "src/gpu/cl/kernels/ClGemmLowpQuantizeDownInt32ScaleByFloatKernel.h" |
| 32 | #include "src/gpu/cl/kernels/ClGemmLowpQuantizeDownInt32ScaleKernel.h" |
Georgios Pinitas | 399f623 | 2021-06-29 15:31:58 +0100 | [diff] [blame] | 33 | |
ramelg01 | 2e53f17 | 2021-09-22 10:48:25 +0100 | [diff] [blame] | 34 | #include "src/common/utils/Log.h" |
| 35 | |
Georgios Pinitas | 399f623 | 2021-06-29 15:31:58 +0100 | [diff] [blame] | 36 | namespace arm_compute |
| 37 | { |
| 38 | namespace opencl |
| 39 | { |
| 40 | void ClGemmLowpOutputStage::configure(const CLCompileContext &compile_context, const ITensorInfo *src, const ITensorInfo *bias, ITensorInfo *dst, const GEMMLowpOutputStageInfo &info) |
| 41 | { |
| 42 | ARM_COMPUTE_ERROR_ON_NULLPTR(src, dst); |
ramelg01 | 2e53f17 | 2021-09-22 10:48:25 +0100 | [diff] [blame] | 43 | ARM_COMPUTE_LOG_PARAMS(src, bias, dst, info); |
Georgios Pinitas | 399f623 | 2021-06-29 15:31:58 +0100 | [diff] [blame] | 44 | |
| 45 | switch(info.type) |
| 46 | { |
| 47 | case GEMMLowpOutputStageType::QUANTIZE_DOWN_FIXEDPOINT: |
| 48 | { |
| 49 | auto k = std::make_unique<opencl::kernels::ClGemmLowpQuantizeDownInt32ScaleByFixedPointKernel>(); |
| 50 | k->configure(compile_context, src, bias, dst, &info); |
| 51 | _kernel = std::move(k); |
| 52 | break; |
| 53 | } |
| 54 | case GEMMLowpOutputStageType::QUANTIZE_DOWN: |
| 55 | { |
| 56 | auto k = std::make_unique<opencl::kernels::ClGemmLowpQuantizeDownInt32ScaleKernel>(); |
| 57 | k->configure(compile_context, src, bias, dst, &info); |
| 58 | _kernel = std::move(k); |
| 59 | break; |
| 60 | } |
| 61 | case GEMMLowpOutputStageType::QUANTIZE_DOWN_FLOAT: |
| 62 | { |
| 63 | auto k = std::make_unique<opencl::kernels::ClGemmLowpQuantizeDownInt32ScaleByFloatKernel>(); |
| 64 | k->configure(compile_context, src, bias, dst, &info); |
| 65 | _kernel = std::move(k); |
| 66 | break; |
| 67 | } |
| 68 | default: |
| 69 | ARM_COMPUTE_ERROR("Unsupported GEMMLowpOutputStage type."); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | Status ClGemmLowpOutputStage::validate(const ITensorInfo *src, const ITensorInfo *bias, const ITensorInfo *dst, const GEMMLowpOutputStageInfo &info) |
| 74 | { |
| 75 | ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(dst); |
| 76 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(dst, 1, DataType::QASYMM8, DataType::QASYMM8_SIGNED, DataType::QSYMM16); |
| 77 | |
| 78 | switch(info.type) |
| 79 | { |
| 80 | case GEMMLowpOutputStageType::QUANTIZE_DOWN_FIXEDPOINT: |
| 81 | return opencl::kernels::ClGemmLowpQuantizeDownInt32ScaleByFixedPointKernel::validate(src, bias, dst, &info); |
| 82 | case GEMMLowpOutputStageType::QUANTIZE_DOWN: |
| 83 | return opencl::kernels::ClGemmLowpQuantizeDownInt32ScaleKernel::validate(src, bias, dst, &info); |
| 84 | case GEMMLowpOutputStageType::QUANTIZE_DOWN_FLOAT: |
| 85 | return opencl::kernels::ClGemmLowpQuantizeDownInt32ScaleByFloatKernel::validate(src, bias, dst, &info); |
| 86 | default: |
| 87 | return ARM_COMPUTE_CREATE_ERROR(ErrorCode::RUNTIME_ERROR, "Unsupported GEMMLowpOutputStage type."); |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | void ClGemmLowpOutputStage::run(ITensorPack &tensors) |
| 92 | { |
| 93 | const ITensor *src = tensors.get_const_tensor(ACL_SRC); |
| 94 | const ITensor *bias = tensors.get_const_tensor(ACL_BIAS); |
| 95 | ITensor *dst = tensors.get_tensor(ACL_DST); |
| 96 | |
| 97 | ITensorPack pack{ { ACL_SRC, src }, { ACL_BIAS, bias }, { ACL_DST, dst } }; |
| 98 | CLScheduler::get().enqueue_op(*_kernel, pack, true); |
| 99 | } |
| 100 | } // namespace opencl |
| 101 | } // namespace arm_compute |