blob: 3d6349fb25650b095a8598ab5b2b159388df3d23 [file] [log] [blame]
Georgios Pinitas5ee66ea2017-09-07 17:29:16 +01001/*
Sheri Zhang7e20e292021-02-02 11:49:34 +00002 * Copyright (c) 2017-2021 Arm Limited.
Georgios Pinitas5ee66ea2017-09-07 17:29:16 +01003 *
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/CLReshapeLayer.h"
25
Sheri Zhang7e20e292021-02-02 11:49:34 +000026#include "arm_compute/core/CL/CLKernelLibrary.h"
Georgios Pinitas5ee66ea2017-09-07 17:29:16 +010027#include "arm_compute/core/CL/ICLTensor.h"
Sheri Zhang7e20e292021-02-02 11:49:34 +000028#include "arm_compute/core/Types.h"
29#include "arm_compute/core/Validate.h"
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010030
Sheri Zhang7e20e292021-02-02 11:49:34 +000031#include "src/core/CL/ICLKernel.h"
Georgios Pinitas7891a732021-08-20 21:39:25 +010032#include "src/gpu/cl/operators/ClReshape.h"
Georgios Pinitas5ee66ea2017-09-07 17:29:16 +010033
Vidhya Sudhan Loganathand646ae12018-11-19 15:18:20 +000034/** [CLReshapeLayer snippet] **/
Michalis Spyrou2aad21a2020-07-02 12:43:53 +010035namespace arm_compute
Georgios Pinitas5ee66ea2017-09-07 17:29:16 +010036{
Michalis Spyrou2aad21a2020-07-02 12:43:53 +010037struct CLReshapeLayer::Impl
38{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010039 const ICLTensor *src{nullptr};
40 ICLTensor *dst{nullptr};
41 std::unique_ptr<opencl::ClReshape> op{nullptr};
Michalis Spyrou2aad21a2020-07-02 12:43:53 +010042};
43
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010044CLReshapeLayer::CLReshapeLayer() : _impl(std::make_unique<Impl>())
Michalis Spyrou2aad21a2020-07-02 12:43:53 +010045{
46}
47
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010048CLReshapeLayer::CLReshapeLayer(CLReshapeLayer &&) = default;
Michalis Spyrou2aad21a2020-07-02 12:43:53 +010049CLReshapeLayer &CLReshapeLayer::operator=(CLReshapeLayer &&) = default;
50CLReshapeLayer::~CLReshapeLayer() = default;
51
52void CLReshapeLayer::configure(const ICLTensor *input, ICLTensor *output)
53{
54 configure(CLKernelLibrary::get().get_compile_context(), input, output);
55}
56
57void CLReshapeLayer::configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output)
58{
59 _impl->src = input;
60 _impl->dst = output;
Sheri Zhang7e20e292021-02-02 11:49:34 +000061 _impl->op = std::make_unique<opencl::ClReshape>();
Michalis Spyrou2aad21a2020-07-02 12:43:53 +010062 _impl->op->configure(compile_context, input->info(), output->info());
63}
64
65Status CLReshapeLayer::validate(const ITensorInfo *input, const ITensorInfo *output)
66{
67 ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input, output);
Sheri Zhang7e20e292021-02-02 11:49:34 +000068 ARM_COMPUTE_RETURN_ON_ERROR(opencl::ClReshape::validate(input, output));
Michalis Spyrou2aad21a2020-07-02 12:43:53 +010069
70 return Status{};
71}
72
73void CLReshapeLayer::run()
74{
Georgios Pinitas0499dff2020-07-31 22:21:38 +010075 ITensorPack pack;
76 pack.add_tensor(TensorType::ACL_SRC, _impl->src);
77 pack.add_tensor(TensorType::ACL_DST, _impl->dst);
78 _impl->op->run(pack);
Michalis Spyrou2aad21a2020-07-02 12:43:53 +010079}
80} // namespace arm_compute
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010081 /** [CLReshapeLayer snippet] **/