1 /* 2 * Copyright (c) 2017-2019 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 #include "arm_compute/core/GPUTarget.h" 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 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 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 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 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 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 */ set_lws_hint(gles::NDRange & lws_hint)104 void set_lws_hint(gles::NDRange &lws_hint) 105 { 106 _lws_hint = lws_hint; 107 } 108 109 /** Set the targeted GPU architecture 110 * 111 * @param[in] target The targeted GPU architecture 112 */ set_target(GPUTarget target)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 */ get_target()122 GPUTarget get_target() const 123 { 124 return _target; 125 } 126 127 private: 128 /** Add the passed tensor's parameters to the object's kernel's arguments starting from the index idx. 129 * 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. 134 */ 135 template <unsigned int dimension_size> 136 void add_tensor_argument(unsigned int &idx, const IGCTensor *tensor, const unsigned int binding_point, const Window &window); 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: 146 GCKernel _kernel; /**< GLES kernel to run */ 147 gles::NDRange _lws_hint; /**< Local workgroup size hint for the GLES kernel */ 148 GPUTarget _target; /**< The targeted GPU */ 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 */ 166