1 /* 2 * Copyright (c) 2022 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 #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 32 namespace arm_compute 33 { 34 namespace experimental 35 { 36 namespace dynamic_fusion 37 { 38 /** Forward declaration */ 39 class GpuKernelSourceCode; 40 41 /** OpenCL runtime to run a single kernel */ 42 class ClKernelRuntime final : public opencl::IClKernel 43 { 44 public: 45 /** Configure the kernel runtime 46 * 47 * @param[in] compile_ctx OpenCL compile context 48 * @param[in] code Kernel source code 49 */ 50 void configure(const opencl::ClCompileContext &compile_ctx, const GpuKernelSourceCode &code); 51 /** Run the kernel 52 * 53 * @param[in,out] tensors @ref ITensorPack object containing run-time tensor memories 54 * @param[in] window Execution window 55 * @param[in] queue OpenCL command queue 56 */ 57 virtual void run_op(ITensorPack &tensors, const Window &window, cl::CommandQueue &queue) override; 58 59 private: 60 /** Set a kernel tensor argument 61 * 62 * @param[in,out] idx Index at which to start adding the tensor's arguments. Will be incremented by the number of kernel arguments set. 63 * @param[in] arg Kernel argument descriptor accompanying @p tensor 64 * @param[in] tensor Tensor to set as an argument of the object's kernel 65 * @param[in] arg_slice Window the kernel will be run on 66 * @param[out] cl_images Extra cl images created from the tensor (will need to be retained until the kernel is enqueued) 67 */ 68 inline void add_tensor_argument(unsigned int &idx, const GpuKernelArgumentInfo &arg, const ICLTensor *tensor, const Window &arg_slice, std::vector<cl::Image2D> &cl_images); 69 70 private: 71 GpuKernelArgumentList _arguments{}; /** All kernel arguments required by the runtime */ 72 }; 73 74 } // namespace dynamic_fusion 75 } // namespace experimental 76 } // namespace arm_compute 77 #endif /* SRC_DYNAMIC_FUSION_RUNTIME_GPU_CL_CLKERNELRUNTIME */ 78