blob: 31898bafc4c7c7c198853c510a6a9260586244c2 [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"
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010029
Mohammed Suhail Munshia1b1e412023-03-23 22:21:31 +000030#include "src/core/helpers/MemoryHelpers.h"
31#include "src/cpu/operators/CpuMatMul.h"
Mohammed Suhail Munshia1b1e412023-03-23 22:21:31 +000032
33namespace arm_compute
34{
35struct NEMatMul::Impl
36{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010037 const ITensor *lhs{nullptr};
38 const ITensor *rhs{nullptr};
39 ITensor *output{nullptr};
40 std::unique_ptr<cpu::CpuMatMul> op{nullptr};
Mohammed Suhail Munshia1b1e412023-03-23 22:21:31 +000041 MemoryGroup memory_group{};
42 WorkspaceData<Tensor> workspace_tensors{};
43 ITensorPack run_pack{};
44};
45
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010046NEMatMul::NEMatMul() : _impl(std::make_unique<Impl>())
Mohammed Suhail Munshia1b1e412023-03-23 22:21:31 +000047{
48}
49
50NEMatMul::~NEMatMul() = default;
51
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010052void NEMatMul::configure(ITensor *lhs,
53 ITensor *rhs,
54 ITensor *output,
55 const MatMulInfo &info,
56 const CpuMatMulSettings &settings,
57 const ActivationLayerInfo &act_info)
Mohammed Suhail Munshia1b1e412023-03-23 22:21:31 +000058{
59 _impl->lhs = lhs;
60 _impl->rhs = rhs;
61 _impl->output = output;
62
63 ARM_COMPUTE_ERROR_ON_NULLPTR(_impl->lhs, _impl->rhs, _impl->output);
64 _impl->op = std::make_unique<cpu::CpuMatMul>();
Mohammed Suhail Munshi94abde42023-05-25 16:48:43 +010065 _impl->op->configure(lhs->info(), rhs->info(), output->info(), info, settings, act_info);
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010066 _impl->run_pack = {{ACL_SRC_0, lhs}, {ACL_SRC_1, rhs}, {ACL_DST, output}};
Mohammed Suhail Munshia1b1e412023-03-23 22:21:31 +000067 _impl->workspace_tensors = manage_workspace<Tensor>(_impl->op->workspace(), _impl->memory_group, _impl->run_pack);
68}
69
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010070Status NEMatMul::validate(const ITensorInfo *lhs,
71 const ITensorInfo *rhs,
72 const ITensorInfo *output,
73 const MatMulInfo &info,
74 const CpuMatMulSettings &settings,
75 const ActivationLayerInfo &act_info)
Mohammed Suhail Munshia1b1e412023-03-23 22:21:31 +000076{
Mohammed Suhail Munshi94abde42023-05-25 16:48:43 +010077 return cpu::CpuMatMul::validate(lhs, rhs, output, info, settings, act_info);
Mohammed Suhail Munshia1b1e412023-03-23 22:21:31 +000078}
79
80void NEMatMul::run()
81{
82 MemoryGroupResourceScope scope_mg(_impl->memory_group);
83 _impl->op->run(_impl->run_pack);
84}
85} // namespace arm_compute