blob: 7b2aad7ceca0bbe1dda4166807abd87f4797e746 [file] [log] [blame]
Anthony Barbier7068f992017-10-26 15:23:08 +01001/*
Michalis Spyrouf4643372019-11-29 16:17:13 +00002 * Copyright (c) 2017-2019 ARM Limited.
Anthony Barbier7068f992017-10-26 15:23:08 +01003 *
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 */
Michalis Spyrouf4643372019-11-29 16:17:13 +000024#ifndef ARM_COMPUTE_IGCKERNEL_H
25#define ARM_COMPUTE_IGCKERNEL_H
Anthony Barbier7068f992017-10-26 15:23:08 +010026
27#include "arm_compute/core/GLES_COMPUTE/GCKernelLibrary.h"
28#include "arm_compute/core/GLES_COMPUTE/OpenGLES.h"
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +010029#include "arm_compute/core/GPUTarget.h"
Anthony Barbier7068f992017-10-26 15:23:08 +010030
31#include "arm_compute/core/IKernel.h"
32
33namespace arm_compute
34{
35class IGCTensor;
36class Window;
37
38/** Common interface for all the GLES kernels */
39class IGCKernel : public IKernel
40{
41public:
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 Barbier7068f992017-10-26 15:23:08 +010050 /** 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 Barbier7068f992017-10-26 15:23:08 +010059 /** 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 Barbier7068f992017-10-26 15:23:08 +010068 /** 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 Barbier7068f992017-10-26 15:23:08 +010077 /** 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
steli01d0643892018-01-02 14:56:06 +080098 /** 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 Giorgiob8fc60f2018-04-25 11:58:07 +0100109 /** 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 Barbier7068f992017-10-26 15:23:08 +0100127private:
128 /** Add the passed tensor's parameters to the object's kernel's arguments starting from the index idx.
129 *
Joel Liangabd03cf2018-01-08 15:20:48 +0800130 * @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 Barbier7068f992017-10-26 15:23:08 +0100134 */
135 template <unsigned int dimension_size>
Joel Liangabd03cf2018-01-08 15:20:48 +0800136 void add_tensor_argument(unsigned int &idx, const IGCTensor *tensor, const unsigned int binding_point, const Window &window);
Anthony Barbier7068f992017-10-26 15:23:08 +0100137
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
145protected:
steli01d0643892018-01-02 14:56:06 +0800146 GCKernel _kernel; /**< GLES kernel to run */
147 gles::NDRange _lws_hint; /**< Local workgroup size hint for the GLES kernel */
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +0100148 GPUTarget _target; /**< The targeted GPU */
Anthony Barbier7068f992017-10-26 15:23:08 +0100149};
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 */
163void enqueue(IGCKernel &kernel, const Window &window, const gles::NDRange &lws = gles::NDRange(1U, 1U, 1U));
164}
Michalis Spyrouf4643372019-11-29 16:17:13 +0000165#endif /*ARM_COMPUTE_IGCKERNEL_H */