SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 1 | /* |
SiCong Li | 23882a9 | 2023-06-28 09:49:45 +0100 | [diff] [blame] | 2 | * Copyright (c) 2022-2023 Arm Limited. |
SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 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 | #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 Li | 23882a9 | 2023-06-28 09:49:45 +0100 | [diff] [blame] | 32 | #include <vector> |
| 33 | |
SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 34 | namespace arm_compute |
| 35 | { |
| 36 | namespace experimental |
| 37 | { |
| 38 | namespace dynamic_fusion |
| 39 | { |
SiCong Li | a2b131b | 2022-11-04 10:11:32 +0000 | [diff] [blame] | 40 | /** Forward declaration */ |
| 41 | class GpuKernelSourceCode; |
SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 42 | |
| 43 | /** OpenCL runtime to run a single kernel */ |
| 44 | class ClKernelRuntime final : public opencl::IClKernel |
| 45 | { |
| 46 | public: |
| 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 | |
| 61 | private: |
SiCong Li | 23882a9 | 2023-06-28 09:49:45 +0100 | [diff] [blame] | 62 | #ifndef ACL_INTERNAL_TEST_CKW_IN_DF |
SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 63 | /** 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 Li | 23882a9 | 2023-06-28 09:49:45 +0100 | [diff] [blame] | 72 | #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 Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 82 | |
| 83 | private: |
SiCong Li | 23882a9 | 2023-06-28 09:49:45 +0100 | [diff] [blame] | 84 | GpuKernelArgumentList _arguments{}; |
SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 85 | }; |
| 86 | |
| 87 | } // namespace dynamic_fusion |
| 88 | } // namespace experimental |
| 89 | } // namespace arm_compute |
| 90 | #endif /* SRC_DYNAMIC_FUSION_RUNTIME_GPU_CL_CLKERNELRUNTIME */ |