blob: 92e73503cecee2d332257ded4294af597da9e401 [file] [log] [blame]
SiCong Lif44bbc52022-08-29 18:25:51 +01001/*
SiCong Li23882a92023-06-28 09:49:45 +01002 * Copyright (c) 2022-2023 Arm Limited.
SiCong Lif44bbc52022-08-29 18:25:51 +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#ifndef SRC_DYNAMIC_FUSION_RUNTIME_GPU_CL_CLKERNELRUNTIME
25#define SRC_DYNAMIC_FUSION_RUNTIME_GPU_CL_CLKERNELRUNTIME
26
27#include "src/dynamic_fusion/sketch/gpu/GpuKernelArgument.h"
28#include "src/dynamic_fusion/sketch/gpu/GpuKernelSourceCode.h"
29#include "src/gpu/cl/ClCompileContext.h"
30#include "src/gpu/cl/IClKernel.h"
31
SiCong Li23882a92023-06-28 09:49:45 +010032#include <vector>
33
SiCong Lif44bbc52022-08-29 18:25:51 +010034namespace arm_compute
35{
36namespace experimental
37{
38namespace dynamic_fusion
39{
SiCong Lia2b131b2022-11-04 10:11:32 +000040/** Forward declaration */
41class GpuKernelSourceCode;
SiCong Lif44bbc52022-08-29 18:25:51 +010042
43/** OpenCL runtime to run a single kernel */
44class ClKernelRuntime final : public opencl::IClKernel
45{
46public:
47 /** Configure the kernel runtime
48 *
49 * @param[in] compile_ctx OpenCL compile context
50 * @param[in] code Kernel source code
51 */
52 void configure(const opencl::ClCompileContext &compile_ctx, const GpuKernelSourceCode &code);
53 /** Run the kernel
54 *
55 * @param[in,out] tensors @ref ITensorPack object containing run-time tensor memories
56 * @param[in] window Execution window
57 * @param[in] queue OpenCL command queue
58 */
59 virtual void run_op(ITensorPack &tensors, const Window &window, cl::CommandQueue &queue) override;
60
61private:
SiCong Li23882a92023-06-28 09:49:45 +010062#ifndef ACL_INTERNAL_TEST_CKW_IN_DF
SiCong Lif44bbc52022-08-29 18:25:51 +010063 /** Set a kernel tensor argument
64 *
65 * @param[in,out] idx Index at which to start adding the tensor's arguments. Will be incremented by the number of kernel arguments set.
66 * @param[in] arg Kernel argument descriptor accompanying @p tensor
67 * @param[in] tensor Tensor to set as an argument of the object's kernel
68 * @param[in] arg_slice Window the kernel will be run on
69 * @param[out] cl_images Extra cl images created from the tensor (will need to be retained until the kernel is enqueued)
70 */
71 inline void add_tensor_argument(unsigned int &idx, const GpuKernelArgumentInfo &arg, const ICLTensor *tensor, const Window &arg_slice, std::vector<cl::Image2D> &cl_images);
SiCong Li23882a92023-06-28 09:49:45 +010072#else // ACL_INTERNAL_TEST_CKW_IN_DF
73 /** Set a kernel argument as part of a tensor
74 *
75 * @param[in,out] idx Index at which to start adding the tensor's arguments. Will be incremented by the number of kernel arguments set.
76 * @param[in] arg Kernel argument binding, as part of @p tensor
77 * @param[in] tensor Tensor of which the kernel argument @p arg is a part of
78 * @param[out] cl_images Extra cl images created from the tensor (will need to be retained until the kernel is enqueued)
79 */
80 inline void add_kernel_argument(unsigned int &idx, const GpuKernelArgumentBinding &arg, const ICLTensor *tensor, std::vector<cl::Image2D> &cl_images);
81#endif // ACL_INTERNAL_TEST_CKW_IN_DF
SiCong Lif44bbc52022-08-29 18:25:51 +010082
83private:
SiCong Li23882a92023-06-28 09:49:45 +010084 GpuKernelArgumentList _arguments{};
SiCong Lif44bbc52022-08-29 18:25:51 +010085};
86
87} // namespace dynamic_fusion
88} // namespace experimental
89} // namespace arm_compute
90#endif /* SRC_DYNAMIC_FUSION_RUNTIME_GPU_CL_CLKERNELRUNTIME */