blob: 58640f40eaf1449318f31945569b5232574ef393 [file] [log] [blame]
Mohammed Suhail Munshia1b1e412023-03-23 22:21:31 +00001/*
2 * Copyright (c) 2023 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/NEON/functions/NEMatMul.h"
25
26#include "arm_compute/core/Validate.h"
27#include "arm_compute/runtime/MemoryGroup.h"
Mohammed Suhail Munshi94abde42023-05-25 16:48:43 +010028#include "arm_compute/runtime/Tensor.h"
Mohammed Suhail Munshia1b1e412023-03-23 22:21:31 +000029#include "src/core/helpers/MemoryHelpers.h"
30#include "src/cpu/operators/CpuMatMul.h"
Mohammed Suhail Munshia1b1e412023-03-23 22:21:31 +000031
32namespace arm_compute
33{
34struct NEMatMul::Impl
35{
36 const ITensor *lhs{ nullptr };
37 const ITensor *rhs{ nullptr };
38 ITensor *output{ nullptr };
39 std::unique_ptr<cpu::CpuMatMul> op{ nullptr };
40 MemoryGroup memory_group{};
41 WorkspaceData<Tensor> workspace_tensors{};
42 ITensorPack run_pack{};
43};
44
45NEMatMul::NEMatMul()
46 : _impl(std::make_unique<Impl>())
47{
48}
49
50NEMatMul::~NEMatMul() = default;
51
Mohammed Suhail Munshi94abde42023-05-25 16:48:43 +010052void NEMatMul::configure(ITensor *lhs, ITensor *rhs, ITensor *output, const MatMulInfo &info, const CpuMatMulSettings &settings, const ActivationLayerInfo &act_info)
Mohammed Suhail Munshia1b1e412023-03-23 22:21:31 +000053{
54 _impl->lhs = lhs;
55 _impl->rhs = rhs;
56 _impl->output = output;
57
58 ARM_COMPUTE_ERROR_ON_NULLPTR(_impl->lhs, _impl->rhs, _impl->output);
59 _impl->op = std::make_unique<cpu::CpuMatMul>();
Mohammed Suhail Munshi94abde42023-05-25 16:48:43 +010060 _impl->op->configure(lhs->info(), rhs->info(), output->info(), info, settings, act_info);
Mohammed Suhail Munshia1b1e412023-03-23 22:21:31 +000061 _impl->run_pack = { { ACL_SRC_0, lhs }, { ACL_SRC_1, rhs }, { ACL_DST, output } };
62 _impl->workspace_tensors = manage_workspace<Tensor>(_impl->op->workspace(), _impl->memory_group, _impl->run_pack);
63}
64
Mohammed Suhail Munshi94abde42023-05-25 16:48:43 +010065Status NEMatMul::validate(const ITensorInfo *lhs, const ITensorInfo *rhs, const ITensorInfo *output, const MatMulInfo &info, const CpuMatMulSettings &settings, const ActivationLayerInfo &act_info)
Mohammed Suhail Munshia1b1e412023-03-23 22:21:31 +000066{
Mohammed Suhail Munshi94abde42023-05-25 16:48:43 +010067 return cpu::CpuMatMul::validate(lhs, rhs, output, info, settings, act_info);
Mohammed Suhail Munshia1b1e412023-03-23 22:21:31 +000068}
69
70void NEMatMul::run()
71{
72 MemoryGroupResourceScope scope_mg(_impl->memory_group);
73 _impl->op->run(_impl->run_pack);
74}
75} // namespace arm_compute