aboutsummaryrefslogtreecommitdiff
path: root/src/gpu/cl/operators/ClMatMul.cpp
blob: dadaa1f7796f4999e8834151a681935920d42422 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
 * Copyright (c) 2023 Arm Limited.
 *
 * SPDX-License-Identifier: MIT
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to
 * deal in the Software without restriction, including without limitation the
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 * sell copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
#include "src/gpu/cl/operators/ClMatMul.h"
#include "arm_compute/core/Error.h"
#include "arm_compute/runtime/CL/CLScheduler.h"
#include "src/common/utils/Log.h"
#include "src/gpu/cl/kernels/ClNativeMatMulKernel.h"

namespace arm_compute
{
namespace opencl
{
using namespace arm_compute::opencl::kernels;
ClMatMul::ClMatMul()
    : _native_matmul_kernel(std::make_unique<ClNativeMatMulKernel>())
{
}
ClMatMul::~ClMatMul()
{
}
Status ClMatMul::validate(const ITensorInfo *lhs, const ITensorInfo *rhs, const ITensorInfo *output, const MatMulInfo &matmul_info)
{
    MatMulKernelInfo kernel_info;
    kernel_info.adj_lhs = matmul_info.adj_lhs();
    kernel_info.adj_rhs = matmul_info.adj_rhs();
    return ClNativeMatMulKernel::validate(lhs, rhs, output, kernel_info);
}
void ClMatMul::configure(const CLCompileContext &compile_context, ITensorInfo *lhs, ITensorInfo *rhs, ITensorInfo *output, const MatMulInfo &matmul_info)
{
    ARM_COMPUTE_ERROR_ON_NULLPTR(lhs, rhs, output);
    ARM_COMPUTE_LOG_PARAMS(lhs, rhs, output, matmul_info);

    // Perform validation step
    ARM_COMPUTE_ERROR_THROW_ON(validate(lhs, rhs, output, matmul_info));
    const GPUTarget gpu_target = CLScheduler::get().target();

    // Placeholder: Getting the heuristics calculated values for M0, N0, K0, and whether to export RHS to texture pipe

    // Filling the MatMul Kernel info
    MatMulKernelInfo kernel_info;
    kernel_info.adj_lhs                = matmul_info.adj_lhs();
    kernel_info.adj_rhs                = matmul_info.adj_rhs();
    kernel_info.m0                     = 1;     // to be properly calculated from heuristics
    kernel_info.n0                     = 4;     // to be properly calculated from heuristics
    kernel_info.k0                     = 4;     // to be properly calculated from heuristics
    kernel_info.export_rhs_to_cl_image = false; // to be properly determined from heuristics

    // Set the target for the kernels
    _native_matmul_kernel->set_target(gpu_target);

    // Configure the native matrix multiply kernel
    _native_matmul_kernel->configure(compile_context, lhs, rhs, output, kernel_info);
}
void ClMatMul::run(ITensorPack &tensors)
{
    CLScheduler::get().enqueue_op(*_native_matmul_kernel, tensors, true);
}
} // namespace opencl
} // namespace arm_compute