Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2017 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 __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" |
| 29 | |
| 30 | #include "arm_compute/core/IKernel.h" |
| 31 | |
| 32 | namespace arm_compute |
| 33 | { |
| 34 | class IGCTensor; |
| 35 | class Window; |
| 36 | |
| 37 | /** Common interface for all the GLES kernels */ |
| 38 | class IGCKernel : public IKernel |
| 39 | { |
| 40 | public: |
| 41 | /** Constructor */ |
| 42 | IGCKernel(); |
| 43 | /** Returns a reference to the GLES kernel of this object. |
| 44 | * |
| 45 | * @return A reference to the GLES kernel of this object. |
| 46 | */ |
| 47 | GCKernel &kernel(); |
| 48 | |
| 49 | class BufferParam |
| 50 | { |
| 51 | public: |
| 52 | /** Tensor's binding point in this kernel. */ |
| 53 | unsigned int binding_point = 0; |
| 54 | /** The base 2 logarithm of SSBO buffer data type size (Number of bits to be shift for offset calculation) */ |
| 55 | unsigned int buffer_data_type_shift = 0; |
| 56 | |
| 57 | /** Constructor |
| 58 | * |
| 59 | * @param[in] binding Tensor's binding point. |
| 60 | * @param[in] shift Number of bits to be shift for offset calculation |
| 61 | */ |
| 62 | BufferParam(const unsigned int binding, const unsigned int shift) |
| 63 | : binding_point(binding), buffer_data_type_shift(shift) |
| 64 | { |
| 65 | } |
| 66 | }; |
| 67 | |
| 68 | /** Add the passed 1D 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_1D_tensor_argument(unsigned int &idx, const IGCTensor *tensor, const unsigned int binding_point, const Window &window); |
| 76 | |
| 77 | /** Add the passed 1D tensor's parameters to the object's kernel's arguments starting from the index idx. |
| 78 | * |
| 79 | * @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. |
| 80 | * @param[in] tensor Tensor to set as an argument of the object's kernel. |
| 81 | * @param[in] param Additional parameter for GLES SSBO buffer. |
| 82 | * @param[in] window Window the kernel will be executed on. |
| 83 | */ |
| 84 | void add_1D_tensor_argument(unsigned int &idx, const IGCTensor *tensor, const BufferParam ¶m, const Window &window); |
| 85 | |
| 86 | /** Add the passed 2D tensor's parameters to the object's kernel's arguments starting from the index idx. |
| 87 | * |
| 88 | * @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. |
| 89 | * @param[in] tensor Tensor to set as an argument of the object's kernel. |
| 90 | * @param[in] binding_point Tensor's binding point in this kernel. |
| 91 | * @param[in] window Window the kernel will be executed on. |
| 92 | */ |
| 93 | void add_2D_tensor_argument(unsigned int &idx, const IGCTensor *tensor, const unsigned int binding_point, const Window &window); |
| 94 | |
| 95 | /** Add the passed 2D tensor's parameters to the object's kernel's arguments starting from the index idx. |
| 96 | * |
| 97 | * @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. |
| 98 | * @param[in] tensor Tensor to set as an argument of the object's kernel. |
| 99 | * @param[in] param Additional parameter for GLES SSBO buffer. |
| 100 | * @param[in] window Window the kernel will be executed on. |
| 101 | */ |
| 102 | void add_2D_tensor_argument(unsigned int &idx, const IGCTensor *tensor, const BufferParam ¶m, const Window &window); |
| 103 | |
| 104 | /** Add the passed 3D tensor's parameters to the object's kernel's arguments starting from the index idx. |
| 105 | * |
| 106 | * @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. |
| 107 | * @param[in] tensor Tensor to set as an argument of the object's kernel. |
| 108 | * @param[in] binding_point Tensor's binding point in this kernel. |
| 109 | * @param[in] window Window the kernel will be executed on. |
| 110 | */ |
| 111 | void add_3D_tensor_argument(unsigned int &idx, const IGCTensor *tensor, const unsigned int binding_point, const Window &window); |
| 112 | |
| 113 | /** Add the passed 3D tensor's parameters to the object's kernel's arguments starting from the index idx. |
| 114 | * |
| 115 | * @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. |
| 116 | * @param[in] tensor Tensor to set as an argument of the object's kernel. |
| 117 | * @param[in] param Additional parameter for GLES SSBO buffer. |
| 118 | * @param[in] window Window the kernel will be executed on. |
| 119 | */ |
| 120 | void add_3D_tensor_argument(unsigned int &idx, const IGCTensor *tensor, const BufferParam ¶m, const Window &window); |
| 121 | |
| 122 | /** Returns the number of arguments enqueued per 1D tensor object. |
| 123 | * |
| 124 | * @return The number of arguments enqueues per 1D tensor object. |
| 125 | */ |
| 126 | unsigned int num_arguments_per_1D_tensor() const; |
| 127 | /** Returns the number of arguments enqueued per 2D tensor object. |
| 128 | * |
| 129 | * @return The number of arguments enqueues per 2D tensor object. |
| 130 | */ |
| 131 | unsigned int num_arguments_per_2D_tensor() const; |
| 132 | /** Returns the number of arguments enqueued per 3D tensor object. |
| 133 | * |
| 134 | * @return The number of arguments enqueues per 3D tensor object. |
| 135 | */ |
| 136 | unsigned int num_arguments_per_3D_tensor() const; |
| 137 | /** Enqueue the OpenGL ES shader to process the given window |
| 138 | * |
| 139 | * @param[in] window Region on which to execute the kernel. (Must be a valid region of the window returned by window()). |
| 140 | */ |
| 141 | virtual void run(const Window &window) = 0; |
| 142 | |
| 143 | private: |
| 144 | /** Add the passed tensor's parameters to the object's kernel's arguments starting from the index idx. |
| 145 | * |
| 146 | * @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. |
| 147 | * @param[in] tensor Tensor to set as an argument of the object's kernel. |
| 148 | * @param[in] param Additional parameter for GLES SSBO buffer. |
| 149 | * @param[in] window Window the kernel will be executed on. |
| 150 | */ |
| 151 | template <unsigned int dimension_size> |
| 152 | void add_tensor_argument(unsigned int &idx, const IGCTensor *tensor, const BufferParam ¶m, const Window &window); |
| 153 | |
| 154 | /** Returns the number of arguments enqueued per tensor object. |
| 155 | * |
| 156 | * @return The number of arguments enqueued per tensor object. |
| 157 | */ |
| 158 | template <unsigned int dimension_size> |
| 159 | unsigned int num_arguments_per_tensor() const; |
| 160 | |
| 161 | protected: |
| 162 | GCKernel _kernel; /**< GLES kernel to run */ |
| 163 | }; |
| 164 | |
| 165 | /** Add the kernel to the command queue with the given window. |
| 166 | * |
| 167 | * @note Depending on the size of the window, this might translate into several jobs being enqueued. |
| 168 | * |
| 169 | * @note If kernel->kernel() is empty then the function will return without adding anything to the queue. |
| 170 | * |
| 171 | * @param[in] kernel Kernel to enqueue |
| 172 | * @param[in] window Window the kernel has to process. |
| 173 | * @param[in] lws Local workgroup size requested, by default (1, 1, 1) |
| 174 | * |
| 175 | * @note If any dimension of the lws is greater than the global workgroup size then no lws will be passed. |
| 176 | */ |
| 177 | void enqueue(IGCKernel &kernel, const Window &window, const gles::NDRange &lws = gles::NDRange(1U, 1U, 1U)); |
| 178 | } |
| 179 | #endif /*__ARM_COMPUTE_IGCKERNEL_H__ */ |