Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 1 | /* |
Stephen Li | e855c23 | 2018-01-04 14:13:22 +0800 | [diff] [blame] | 2 | * Copyright (c) 2017-2018 ARM Limited. |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +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 __ARM_COMPUTE_IGCKERNEL_H__ |
| 25 | #define __ARM_COMPUTE_IGCKERNEL_H__ |
| 26 | |
| 27 | #include "arm_compute/core/GLES_COMPUTE/GCKernelLibrary.h" |
| 28 | #include "arm_compute/core/GLES_COMPUTE/OpenGLES.h" |
Michele Di Giorgio | b8fc60f | 2018-04-25 11:58:07 +0100 | [diff] [blame] | 29 | #include "arm_compute/core/GPUTarget.h" |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 30 | |
| 31 | #include "arm_compute/core/IKernel.h" |
| 32 | |
| 33 | namespace arm_compute |
| 34 | { |
| 35 | class IGCTensor; |
| 36 | class Window; |
| 37 | |
| 38 | /** Common interface for all the GLES kernels */ |
| 39 | class IGCKernel : public IKernel |
| 40 | { |
| 41 | public: |
| 42 | /** Constructor */ |
| 43 | IGCKernel(); |
| 44 | /** Returns a reference to the GLES kernel of this object. |
| 45 | * |
| 46 | * @return A reference to the GLES kernel of this object. |
| 47 | */ |
| 48 | GCKernel &kernel(); |
| 49 | |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 50 | /** Add the passed 1D tensor's parameters to the object's kernel's arguments starting from the index idx. |
| 51 | * |
| 52 | * @param[in] idx Index at which to start adding the tensor's arguments.Input and output tensor will have sperated index, multiple indices start from 1, single index have to be set to 0. |
| 53 | * @param[in] tensor Tensor to set as an argument of the object's kernel. |
| 54 | * @param[in] binding_point Tensor's binding point in this kernel. |
| 55 | * @param[in] window Window the kernel will be executed on. |
| 56 | */ |
| 57 | void add_1D_tensor_argument(unsigned int &idx, const IGCTensor *tensor, const unsigned int binding_point, const Window &window); |
| 58 | |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 59 | /** Add the passed 2D tensor's parameters to the object's kernel's arguments starting from the index idx. |
| 60 | * |
| 61 | * @param[in] idx Index at which to start adding the tensor's arguments.Input and output tensor will have sperated index, multiple indices start from 1, single index have to be set to 0. |
| 62 | * @param[in] tensor Tensor to set as an argument of the object's kernel. |
| 63 | * @param[in] binding_point Tensor's binding point in this kernel. |
| 64 | * @param[in] window Window the kernel will be executed on. |
| 65 | */ |
| 66 | void add_2D_tensor_argument(unsigned int &idx, const IGCTensor *tensor, const unsigned int binding_point, const Window &window); |
| 67 | |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 68 | /** Add the passed 3D tensor's parameters to the object's kernel's arguments starting from the index idx. |
| 69 | * |
| 70 | * @param[in] idx Index at which to start adding the tensor's arguments.Input and output tensor will have sperated index, multiple indices start from 1, single index have to be set to 0. |
| 71 | * @param[in] tensor Tensor to set as an argument of the object's kernel. |
| 72 | * @param[in] binding_point Tensor's binding point in this kernel. |
| 73 | * @param[in] window Window the kernel will be executed on. |
| 74 | */ |
| 75 | void add_3D_tensor_argument(unsigned int &idx, const IGCTensor *tensor, const unsigned int binding_point, const Window &window); |
| 76 | |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 77 | /** Returns the number of arguments enqueued per 1D tensor object. |
| 78 | * |
| 79 | * @return The number of arguments enqueues per 1D tensor object. |
| 80 | */ |
| 81 | unsigned int num_arguments_per_1D_tensor() const; |
| 82 | /** Returns the number of arguments enqueued per 2D tensor object. |
| 83 | * |
| 84 | * @return The number of arguments enqueues per 2D tensor object. |
| 85 | */ |
| 86 | unsigned int num_arguments_per_2D_tensor() const; |
| 87 | /** Returns the number of arguments enqueued per 3D tensor object. |
| 88 | * |
| 89 | * @return The number of arguments enqueues per 3D tensor object. |
| 90 | */ |
| 91 | unsigned int num_arguments_per_3D_tensor() const; |
| 92 | /** Enqueue the OpenGL ES shader to process the given window |
| 93 | * |
| 94 | * @param[in] window Region on which to execute the kernel. (Must be a valid region of the window returned by window()). |
| 95 | */ |
| 96 | virtual void run(const Window &window) = 0; |
| 97 | |
steli01 | d064389 | 2018-01-02 14:56:06 +0800 | [diff] [blame] | 98 | /** Set the Local-Workgroup-Size hint |
| 99 | * |
| 100 | * @note This method should be called after the configuration of the kernel |
| 101 | * |
| 102 | * @param[in] lws_hint Local-Workgroup-Size to use |
| 103 | */ |
| 104 | void set_lws_hint(gles::NDRange &lws_hint) |
| 105 | { |
| 106 | _lws_hint = lws_hint; |
| 107 | } |
| 108 | |
Michele Di Giorgio | b8fc60f | 2018-04-25 11:58:07 +0100 | [diff] [blame] | 109 | /** Set the targeted GPU architecture |
| 110 | * |
| 111 | * @param[in] target The targeted GPU architecture |
| 112 | */ |
| 113 | void set_target(GPUTarget target) |
| 114 | { |
| 115 | _target = target; |
| 116 | } |
| 117 | |
| 118 | /** Get the targeted GPU architecture |
| 119 | * |
| 120 | * @return The targeted GPU architecture. |
| 121 | */ |
| 122 | GPUTarget get_target() const |
| 123 | { |
| 124 | return _target; |
| 125 | } |
| 126 | |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 127 | private: |
| 128 | /** Add the passed tensor's parameters to the object's kernel's arguments starting from the index idx. |
| 129 | * |
Joel Liang | abd03cf | 2018-01-08 15:20:48 +0800 | [diff] [blame] | 130 | * @param[in] idx Index at which to start adding the tensor's arguments.Input and output tensor will have sperated index, multiple indices start from 1, single index have to be set to 0. |
| 131 | * @param[in] tensor Tensor to set as an argument of the object's kernel. |
| 132 | * @param[in] binding_point Tensor's binding point in this kernel. |
| 133 | * @param[in] window Window the kernel will be executed on. |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 134 | */ |
| 135 | template <unsigned int dimension_size> |
Joel Liang | abd03cf | 2018-01-08 15:20:48 +0800 | [diff] [blame] | 136 | void add_tensor_argument(unsigned int &idx, const IGCTensor *tensor, const unsigned int binding_point, const Window &window); |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 137 | |
| 138 | /** Returns the number of arguments enqueued per tensor object. |
| 139 | * |
| 140 | * @return The number of arguments enqueued per tensor object. |
| 141 | */ |
| 142 | template <unsigned int dimension_size> |
| 143 | unsigned int num_arguments_per_tensor() const; |
| 144 | |
| 145 | protected: |
steli01 | d064389 | 2018-01-02 14:56:06 +0800 | [diff] [blame] | 146 | GCKernel _kernel; /**< GLES kernel to run */ |
| 147 | gles::NDRange _lws_hint; /**< Local workgroup size hint for the GLES kernel */ |
Michele Di Giorgio | b8fc60f | 2018-04-25 11:58:07 +0100 | [diff] [blame] | 148 | GPUTarget _target; /**< The targeted GPU */ |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 149 | }; |
| 150 | |
| 151 | /** Add the kernel to the command queue with the given window. |
| 152 | * |
| 153 | * @note Depending on the size of the window, this might translate into several jobs being enqueued. |
| 154 | * |
| 155 | * @note If kernel->kernel() is empty then the function will return without adding anything to the queue. |
| 156 | * |
| 157 | * @param[in] kernel Kernel to enqueue |
| 158 | * @param[in] window Window the kernel has to process. |
| 159 | * @param[in] lws Local workgroup size requested, by default (1, 1, 1) |
| 160 | * |
| 161 | * @note If any dimension of the lws is greater than the global workgroup size then no lws will be passed. |
| 162 | */ |
| 163 | void enqueue(IGCKernel &kernel, const Window &window, const gles::NDRange &lws = gles::NDRange(1U, 1U, 1U)); |
| 164 | } |
| 165 | #endif /*__ARM_COMPUTE_IGCKERNEL_H__ */ |