blob: 3dd8c5f1012037f221e7c9a68ce2853c4c1b760d [file] [log] [blame]
Gian Marco05288a22017-11-21 10:57:50 +00001/*
Georgios Pinitas4a578b92021-06-25 12:13:49 +01002 * Copyright (c) 2017-2021 Arm Limited.
Gian Marco05288a22017-11-21 10:57:50 +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 */
24#include "arm_compute/runtime/CL/functions/CLGEMMLowpOutputStage.h"
25
Georgios Pinitas399f6232021-06-29 15:31:58 +010026#include "arm_compute/core/CL/CLHelpers.h"
27#include "arm_compute/core/CL/CLKernelLibrary.h"
Gian Marco05288a22017-11-21 10:57:50 +000028#include "arm_compute/core/CL/ICLTensor.h"
Georgios Pinitas399f6232021-06-29 15:31:58 +010029#include "arm_compute/core/Helpers.h"
30#include "arm_compute/core/KernelDescriptors.h"
31#include "arm_compute/core/TensorInfo.h"
Sang-Hoon Parkbef7fa22020-10-21 15:58:54 +010032#include "arm_compute/core/Types.h"
Georgios Pinitas4a578b92021-06-25 12:13:49 +010033
Georgios Pinitas399f6232021-06-29 15:31:58 +010034#include "src/core/CL/ICLKernel.h"
Georgios Pinitas7891a732021-08-20 21:39:25 +010035#include "src/gpu/cl/operators/ClGemmLowpOutputStage.h"
Gian Marco05288a22017-11-21 10:57:50 +000036
Sang-Hoon Parkbef7fa22020-10-21 15:58:54 +010037#include <algorithm>
38
Georgios Pinitas932491f2018-09-21 16:33:15 +010039namespace arm_compute
40{
Georgios Pinitas399f6232021-06-29 15:31:58 +010041struct CLGEMMLowpOutputStage::Impl
42{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010043 const ICLTensor *src{nullptr};
44 const ICLTensor *bias{nullptr};
45 ICLTensor *dst{nullptr};
46 std::unique_ptr<opencl::ClGemmLowpOutputStage> op{nullptr};
Georgios Pinitas399f6232021-06-29 15:31:58 +010047 ITensorPack run_pack{};
48};
49
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010050CLGEMMLowpOutputStage::CLGEMMLowpOutputStage() : _impl(std::make_unique<Impl>())
Gian Marco58c57942017-11-28 09:10:03 +000051{
Manuel Bottini2b84be52020-04-08 10:15:51 +010052}
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010053CLGEMMLowpOutputStage::CLGEMMLowpOutputStage(CLGEMMLowpOutputStage &&) = default;
Georgios Pinitas4a578b92021-06-25 12:13:49 +010054CLGEMMLowpOutputStage &CLGEMMLowpOutputStage::operator=(CLGEMMLowpOutputStage &&) = default;
55CLGEMMLowpOutputStage::~CLGEMMLowpOutputStage() = default;
Manuel Bottini9c9b70b2019-07-01 17:35:56 +010056
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010057void CLGEMMLowpOutputStage::configure(const ICLTensor *input,
58 const ICLTensor *bias,
59 ICLTensor *output,
60 const GEMMLowpOutputStageInfo &info)
Sheri Zhang0cdbda52020-02-25 15:57:21 +000061{
Manuel Bottini2b84be52020-04-08 10:15:51 +010062 configure(CLKernelLibrary::get().get_compile_context(), input, bias, output, info);
63}
64
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010065void CLGEMMLowpOutputStage::configure(const CLCompileContext &compile_context,
66 const ICLTensor *input,
67 const ICLTensor *bias,
68 ICLTensor *output,
69 const GEMMLowpOutputStageInfo &info)
Manuel Bottini2b84be52020-04-08 10:15:51 +010070{
Sheri Zhang0cdbda52020-02-25 15:57:21 +000071 ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
Sheri Zhang0cdbda52020-02-25 15:57:21 +000072
Georgios Pinitas399f6232021-06-29 15:31:58 +010073 _impl->src = input;
74 _impl->bias = bias;
75 _impl->dst = output;
Georgios Pinitas4a578b92021-06-25 12:13:49 +010076
Georgios Pinitas399f6232021-06-29 15:31:58 +010077 _impl->op = std::make_unique<opencl::ClGemmLowpOutputStage>();
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010078 _impl->op->configure(compile_context, input->info(), bias != nullptr ? bias->info() : nullptr, output->info(),
79 info);
80 _impl->run_pack = {{ACL_SRC, _impl->src}, {ACL_BIAS, _impl->bias}, {ACL_DST, _impl->dst}};
Sheri Zhang0cdbda52020-02-25 15:57:21 +000081}
82
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010083Status CLGEMMLowpOutputStage::validate(const ITensorInfo *input,
84 const ITensorInfo *bias,
85 const ITensorInfo *output,
86 const GEMMLowpOutputStageInfo &info)
Sheri Zhang0cdbda52020-02-25 15:57:21 +000087{
Georgios Pinitas399f6232021-06-29 15:31:58 +010088 return opencl::ClGemmLowpOutputStage::validate(input, bias, output, info);
Sheri Zhang0cdbda52020-02-25 15:57:21 +000089}
Georgios Pinitas4a578b92021-06-25 12:13:49 +010090
91void CLGEMMLowpOutputStage::run()
92{
Georgios Pinitas399f6232021-06-29 15:31:58 +010093 _impl->op->run(_impl->run_pack);
Georgios Pinitas4a578b92021-06-25 12:13:49 +010094}
Sang-Hoon Parka45abfd2020-08-17 13:50:15 +010095} // namespace arm_compute