blob: 6feed0d7130cb5a59af4bb4bcda99f15a5986c5a [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{
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
Georgios Pinitas4a578b92021-06-25 12:13:49 +010050CLGEMMLowpOutputStage::CLGEMMLowpOutputStage()
Georgios Pinitas399f6232021-06-29 15:31:58 +010051 : _impl(std::make_unique<Impl>())
Gian Marco58c57942017-11-28 09:10:03 +000052{
Manuel Bottini2b84be52020-04-08 10:15:51 +010053}
Georgios Pinitas4a578b92021-06-25 12:13:49 +010054CLGEMMLowpOutputStage::CLGEMMLowpOutputStage(CLGEMMLowpOutputStage &&) = default;
55CLGEMMLowpOutputStage &CLGEMMLowpOutputStage::operator=(CLGEMMLowpOutputStage &&) = default;
56CLGEMMLowpOutputStage::~CLGEMMLowpOutputStage() = default;
Manuel Bottini9c9b70b2019-07-01 17:35:56 +010057
Sheri Zhang0cdbda52020-02-25 15:57:21 +000058void CLGEMMLowpOutputStage::configure(const ICLTensor *input, const ICLTensor *bias, ICLTensor *output, const GEMMLowpOutputStageInfo &info)
59{
Manuel Bottini2b84be52020-04-08 10:15:51 +010060 configure(CLKernelLibrary::get().get_compile_context(), input, bias, output, info);
61}
62
63void CLGEMMLowpOutputStage::configure(const CLCompileContext &compile_context, const ICLTensor *input, const ICLTensor *bias, ICLTensor *output, const GEMMLowpOutputStageInfo &info)
64{
Sheri Zhang0cdbda52020-02-25 15:57:21 +000065 ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
Sheri Zhang0cdbda52020-02-25 15:57:21 +000066
Georgios Pinitas399f6232021-06-29 15:31:58 +010067 _impl->src = input;
68 _impl->bias = bias;
69 _impl->dst = output;
Georgios Pinitas4a578b92021-06-25 12:13:49 +010070
Georgios Pinitas399f6232021-06-29 15:31:58 +010071 _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 } };
Sheri Zhang0cdbda52020-02-25 15:57:21 +000074}
75
76Status CLGEMMLowpOutputStage::validate(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output, const GEMMLowpOutputStageInfo &info)
77{
Georgios Pinitas399f6232021-06-29 15:31:58 +010078 return opencl::ClGemmLowpOutputStage::validate(input, bias, output, info);
Sheri Zhang0cdbda52020-02-25 15:57:21 +000079}
Georgios Pinitas4a578b92021-06-25 12:13:49 +010080
81void CLGEMMLowpOutputStage::run()
82{
Georgios Pinitas399f6232021-06-29 15:31:58 +010083 _impl->op->run(_impl->run_pack);
Georgios Pinitas4a578b92021-06-25 12:13:49 +010084}
Sang-Hoon Parka45abfd2020-08-17 13:50:15 +010085} // namespace arm_compute