Giorgio Arena | 232c452 | 2022-03-03 10:09:01 +0000 | [diff] [blame] | 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 | */ |
SiCong Li | b63b119 | 2022-01-28 18:24:39 +0000 | [diff] [blame^] | 24 | #ifndef ENABLE_EXPERIMENTAL_DYNAMIC_FUSION |
| 25 | #error "This experimental feature must be enabled with -DENABLE_EXPERIMENTAL_DYNAMIC_FUSION" |
| 26 | #endif /* ENABLE_EXPERIMENTAL_DYNAMIC_FUSION */ |
Giorgio Arena | 232c452 | 2022-03-03 10:09:01 +0000 | [diff] [blame] | 27 | |
| 28 | #ifndef ARM_COMPUTE_EXPERIMENTAL_DYNAMICFUSION_CLCOMPOSITEKERNEL_H |
| 29 | #define ARM_COMPUTE_EXPERIMENTAL_DYNAMICFUSION_CLCOMPOSITEKERNEL_H |
| 30 | |
SiCong Li | b63b119 | 2022-01-28 18:24:39 +0000 | [diff] [blame^] | 31 | #include "arm_compute/core/experimental/ClWorkload.h" |
Giorgio Arena | 232c452 | 2022-03-03 10:09:01 +0000 | [diff] [blame] | 32 | #include "src/gpu/cl/ClCompileContext.h" |
| 33 | #include "src/gpu/cl/IClKernel.h" |
| 34 | |
| 35 | namespace arm_compute |
| 36 | { |
| 37 | namespace experimental |
| 38 | { |
| 39 | namespace dynamic_fusion |
| 40 | { |
SiCong Li | b63b119 | 2022-01-28 18:24:39 +0000 | [diff] [blame^] | 41 | struct ClExecutionDescriptor; |
| 42 | struct ClKernelCode; |
| 43 | |
| 44 | class ClCompositeKernel final : public opencl::IClKernel |
Giorgio Arena | 232c452 | 2022-03-03 10:09:01 +0000 | [diff] [blame] | 45 | { |
| 46 | public: |
| 47 | void configure(const opencl::ClCompileContext &, const ClKernelCode &); |
| 48 | |
| 49 | /** Run the composite kernel |
SiCong Li | b63b119 | 2022-01-28 18:24:39 +0000 | [diff] [blame^] | 50 | * @note The slots / keys in ITensorPack are the argument Ids of the tensors in blueprint |
Giorgio Arena | 232c452 | 2022-03-03 10:09:01 +0000 | [diff] [blame] | 51 | * |
SiCong Li | b63b119 | 2022-01-28 18:24:39 +0000 | [diff] [blame^] | 52 | * @param tensors ITensorPack object containing run-time tensor memories |
Giorgio Arena | 232c452 | 2022-03-03 10:09:01 +0000 | [diff] [blame] | 53 | * @param window Execution window |
| 54 | * @param queue OpenCL Command queue |
| 55 | * @param exec_desc Descriptor containing execution information |
| 56 | */ |
SiCong Li | b63b119 | 2022-01-28 18:24:39 +0000 | [diff] [blame^] | 57 | virtual void run_composite_op(ITensorPack &tensors, const Window &window, cl::CommandQueue &queue, const ClExecutionDescriptor &exec_desc) override; |
Giorgio Arena | 232c452 | 2022-03-03 10:09:01 +0000 | [diff] [blame] | 58 | |
| 59 | private: |
SiCong Li | b63b119 | 2022-01-28 18:24:39 +0000 | [diff] [blame^] | 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 ClKernelArgDescriptor &arg, const ICLTensor *tensor, const Window &arg_slice, std::vector<cl::Image2D> &cl_images); |
Giorgio Arena | 232c452 | 2022-03-03 10:09:01 +0000 | [diff] [blame] | 69 | |
| 70 | private: |
| 71 | ClKernelArgList _arguments{}; /** All kernel arguments required by runtime */ |
| 72 | }; |
| 73 | |
Giorgio Arena | 232c452 | 2022-03-03 10:09:01 +0000 | [diff] [blame] | 74 | } // namespace dynamic_fusion |
| 75 | } // namespace experimental |
| 76 | } // namespace arm_compute |
SiCong Li | b63b119 | 2022-01-28 18:24:39 +0000 | [diff] [blame^] | 77 | #endif // ARM_COMPUTE_EXPERIMENTAL_DYNAMICFUSION_CLCOMPOSITEKERNEL_H |