blob: 564ce2f514b408b4de17ba0575cee651c54ce20a [file] [log] [blame]
Georgios Pinitasc0b6f762020-11-02 01:37:17 +00001/*
Sheri Zhangac6499a2021-02-10 15:32:38 +00002 * Copyright (c) 2020-2021 Arm Limited.
Georgios Pinitasc0b6f762020-11-02 01:37:17 +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/NEON/functions/NEGEMMConv2d.h"
Georgios Pinitasec2256b2020-12-03 18:51:58 +000025
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000026#include "arm_compute/core/utils/misc/ShapeCalculator.h"
27#include "arm_compute/core/utils/quantization/AsymmHelpers.h"
28#include "arm_compute/runtime/NEON/NEScheduler.h"
Sang-Hoon Parkd89e2fa2021-05-17 17:04:50 +010029#include "src/runtime/cpu/operators/CpuGemmDirectConv2d.h"
Georgios Pinitas40f51a62020-11-21 03:04:18 +000030
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000031#include <set>
Georgios Pinitas40f51a62020-11-21 03:04:18 +000032
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000033namespace arm_compute
34{
Michele Di Giorgio8ae3cda2021-06-07 15:30:26 +010035using OperatorType = cpu::CpuGemmDirectConv2d;
Sang-Hoon Parkd89e2fa2021-05-17 17:04:50 +010036
37struct NEGEMMConv2d::Impl
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000038{
Sang-Hoon Parkd89e2fa2021-05-17 17:04:50 +010039 ITensorPack tensors{};
40 std::unique_ptr<OperatorType> op{ nullptr };
41};
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000042
43NEGEMMConv2d::NEGEMMConv2d(const std::shared_ptr<IMemoryManager> &memory_manager)
Sang-Hoon Parkd89e2fa2021-05-17 17:04:50 +010044 : _impl(std::make_unique<Impl>())
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000045{
Michele Di Giorgio8ae3cda2021-06-07 15:30:26 +010046 _impl->op = std::make_unique<OperatorType>(memory_manager);
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000047}
Georgios Pinitasec2256b2020-12-03 18:51:58 +000048
49NEGEMMConv2d::~NEGEMMConv2d() = default;
50
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000051void NEGEMMConv2d::configure(ITensor *input, const ITensor *weights, const ITensor *biases, ITensor *output, const Conv2dInfo &info)
52{
Sang-Hoon Parkd89e2fa2021-05-17 17:04:50 +010053 _impl->tensors.add_const_tensor(TensorType::ACL_SRC_0, input);
54 _impl->tensors.add_const_tensor(TensorType::ACL_SRC_1, weights);
55 _impl->tensors.add_const_tensor(TensorType::ACL_SRC_2, biases);
56 _impl->tensors.add_tensor(TensorType::ACL_DST, output);
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000057
Pablo Telloa5c428a2021-06-09 11:50:01 +010058 _impl->op->configure(input->info(), weights->info(), biases != nullptr ? biases->info() : nullptr, output->info(), info);
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000059}
Sang-Hoon Parkd89e2fa2021-05-17 17:04:50 +010060
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000061Status NEGEMMConv2d::validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output, const Conv2dInfo &info)
62{
Sang-Hoon Parkd89e2fa2021-05-17 17:04:50 +010063 return OperatorType::validate(input, weights, biases, output, info);
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000064}
65void NEGEMMConv2d::run()
66{
Sang-Hoon Parkd89e2fa2021-05-17 17:04:50 +010067 _impl->op->run(_impl->tensors);
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000068}
69void NEGEMMConv2d::prepare()
70{
Sang-Hoon Parkd89e2fa2021-05-17 17:04:50 +010071 _impl->op->prepare(_impl->tensors);
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000072}
73} // namespace arm_compute