xref: /aosp_15_r20/external/ComputeLibrary/src/runtime/CL/functions/CLGEMMLowpOutputStage.cpp (revision c217d954acce2dbc11938adb493fc0abd69584f3)
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  */
24 #include "arm_compute/runtime/CL/functions/CLGEMMLowpOutputStage.h"
25 
26 #include "arm_compute/core/CL/CLHelpers.h"
27 #include "arm_compute/core/CL/CLKernelLibrary.h"
28 #include "arm_compute/core/CL/ICLTensor.h"
29 #include "arm_compute/core/Helpers.h"
30 #include "arm_compute/core/KernelDescriptors.h"
31 #include "arm_compute/core/TensorInfo.h"
32 #include "arm_compute/core/Types.h"
33 
34 #include "src/core/CL/ICLKernel.h"
35 #include "src/gpu/cl/operators/ClGemmLowpOutputStage.h"
36 
37 #include <algorithm>
38 
39 namespace arm_compute
40 {
41 struct CLGEMMLowpOutputStage::Impl
42 {
43     const ICLTensor                               *src{ nullptr };
44     const ICLTensor                               *bias{ nullptr };
45     ICLTensor                                     *dst{ nullptr };
46     std::unique_ptr<opencl::ClGemmLowpOutputStage> op{ nullptr };
47     ITensorPack                                    run_pack{};
48 };
49 
CLGEMMLowpOutputStage()50 CLGEMMLowpOutputStage::CLGEMMLowpOutputStage()
51     : _impl(std::make_unique<Impl>())
52 {
53 }
54 CLGEMMLowpOutputStage::CLGEMMLowpOutputStage(CLGEMMLowpOutputStage &&) = default;
55 CLGEMMLowpOutputStage &CLGEMMLowpOutputStage::operator=(CLGEMMLowpOutputStage &&) = default;
56 CLGEMMLowpOutputStage::~CLGEMMLowpOutputStage()                                   = default;
57 
configure(const ICLTensor * input,const ICLTensor * bias,ICLTensor * output,const GEMMLowpOutputStageInfo & info)58 void CLGEMMLowpOutputStage::configure(const ICLTensor *input, const ICLTensor *bias, ICLTensor *output, const GEMMLowpOutputStageInfo &info)
59 {
60     configure(CLKernelLibrary::get().get_compile_context(), input, bias, output, info);
61 }
62 
configure(const CLCompileContext & compile_context,const ICLTensor * input,const ICLTensor * bias,ICLTensor * output,const GEMMLowpOutputStageInfo & info)63 void CLGEMMLowpOutputStage::configure(const CLCompileContext &compile_context, const ICLTensor *input, const ICLTensor *bias, ICLTensor *output, const GEMMLowpOutputStageInfo &info)
64 {
65     ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
66 
67     _impl->src  = input;
68     _impl->bias = bias;
69     _impl->dst  = output;
70 
71     _impl->op = std::make_unique<opencl::ClGemmLowpOutputStage>();
72     _impl->op->configure(compile_context, input->info(), bias != nullptr ? bias->info() : nullptr, output->info(), info);
73     _impl->run_pack = { { ACL_SRC, _impl->src }, { ACL_BIAS, _impl->bias }, { ACL_DST, _impl->dst } };
74 }
75 
validate(const ITensorInfo * input,const ITensorInfo * bias,const ITensorInfo * output,const GEMMLowpOutputStageInfo & info)76 Status CLGEMMLowpOutputStage::validate(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output, const GEMMLowpOutputStageInfo &info)
77 {
78     return opencl::ClGemmLowpOutputStage::validate(input, bias, output, info);
79 }
80 
run()81 void CLGEMMLowpOutputStage::run()
82 {
83     _impl->op->run(_impl->run_pack);
84 }
85 } // namespace arm_compute
86