Compute Library
 21.02
GCKernelLibrary.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017-2021 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  */
25 
26 #include "arm_compute/core/Error.h"
27 #include "arm_compute/core/Utils.h"
28 
29 #include <fstream>
30 #include <iomanip>
31 #include <regex>
32 #include <utility>
33 #include <vector>
34 
35 using namespace arm_compute;
36 
38  : _name(), _source()
39 {
40 }
41 
42 GCProgram::GCProgram(std::string name, std::string source)
43  : _name(std::move(name)), _source(std::move(source))
44 {
45 }
46 
47 GLuint GCProgram::link_program(GLuint shader)
48 {
49  GLuint program = ARM_COMPUTE_GL_CHECK(glCreateProgram());
50 
51  GLint rvalue;
52  GLsizei length;
53 
54  ARM_COMPUTE_GL_CHECK(glAttachShader(program, shader));
56  ARM_COMPUTE_GL_CHECK(glDetachShader(program, shader));
58 
59  // Check if there were some issues when linking the shader.
60  ARM_COMPUTE_GL_CHECK(glGetProgramiv(program, GL_LINK_STATUS, &rvalue));
61 
62  if(rvalue == 0)
63  {
64  ARM_COMPUTE_GL_CHECK(glGetProgramiv(program, GL_INFO_LOG_LENGTH, &length));
65 
66  std::vector<GLchar> log(length);
67  ARM_COMPUTE_GL_CHECK(glGetProgramInfoLog(program, length, nullptr, log.data()));
68  ARM_COMPUTE_ERROR_VAR("Error: Linker log:\n%s\n", log.data());
69 
70  return 0;
71  }
72 
74 
75  return program;
76 }
77 
78 GLuint GCProgram::compile_shader(const std::string &build_options)
79 {
80  GLuint shader = ARM_COMPUTE_GL_CHECK(glCreateShader(GL_COMPUTE_SHADER));
81 
82  const char *src[]
83  {
84  "#version 310 es\n",
85  build_options.c_str(),
86  _source.c_str()
87  };
88 
89  ARM_COMPUTE_GL_CHECK(glShaderSource(shader, sizeof(src) / sizeof(src[0]), src, nullptr));
90 
92 
93  // Check if there were any issues when compiling the shader
94  GLint rvalue;
95  GLsizei length;
96 
97  ARM_COMPUTE_GL_CHECK(glGetShaderiv(shader, GL_COMPILE_STATUS, &rvalue));
98 
99  if(rvalue == 0)
100  {
101  ARM_COMPUTE_GL_CHECK(glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &length));
102 
103  std::vector<GLchar> log(length);
104  ARM_COMPUTE_GL_CHECK(glGetShaderInfoLog(shader, length, nullptr, log.data()));
105 
106 #ifdef ARM_COMPUTE_DEBUG_ENABLED
107  std::istringstream ss(_source);
108  std::stringstream output_stream;
109  std::string line;
110  size_t line_num = 1;
111 
112  ARM_COMPUTE_LOG_INFO_MSG_WITH_FORMAT_CORE("GLES Shader build options:\n%s\n", build_options.c_str());
113  while(std::getline(ss, line, '\n'))
114  {
115  output_stream << std::setw(6) << line_num << ": " << line << std::endl;
116  line_num++;
117  }
118  ARM_COMPUTE_LOG_INFO_STREAM_CORE("GLES Shader source code:\n"
119  << output_stream.rdbuf());
120 #endif /* ARM_COMPUTE_DEBUG_ENABLED */
121 
122  ARM_COMPUTE_ERROR_VAR("Error: Compiler log:\n%s\n", log.data());
123 
124  return 0;
125  }
126 
127  return shader;
128 }
129 
131  : _name(), _program(), _shader_arguments(), _shader_params_ubo_name(), _shader_params_binding_point(), _shader_params_index(), _shader_params_size()
132 {
133 }
134 
135 // Add a default destructor in cpp file to workaround the free unallocated value issue on Android
137 {
138 }
139 
140 GCKernel::GCKernel(std::string name, GLuint program)
141  : _name(std::move(name)),
142  _program(program),
143  _shader_arguments(),
144  _shader_params_ubo_name(0),
145  _shader_params_binding_point(0),
146  _shader_params_index(0),
147  _shader_params_size(0)
148 {
149  _shader_arguments.clear();
150 
151  ARM_COMPUTE_GL_CHECK(glGenBuffers(1, &_shader_params_ubo_name));
152 
153  _shader_params_index = ARM_COMPUTE_GL_CHECK(glGetUniformBlockIndex(_program, _shader_params_name));
154  ARM_COMPUTE_ERROR_ON_MSG_VAR(_shader_params_index == GL_INVALID_INDEX, "Failed to get index of %s", _shader_params_name);
155  ARM_COMPUTE_GL_CHECK(glGetActiveUniformBlockiv(_program, _shader_params_index, GL_UNIFORM_BLOCK_DATA_SIZE, &_shader_params_size));
156  ARM_COMPUTE_ERROR_ON_MSG_VAR(_shader_params_size == 0, "Failed to get size of %s", _shader_params_name);
157 }
158 
160 {
161  ARM_COMPUTE_GL_CHECK(glDeleteBuffers(1, &_shader_params_ubo_name));
162  ARM_COMPUTE_GL_CHECK(glBindBuffer(GL_UNIFORM_BUFFER, 0));
165 }
166 
168 {
170 }
171 
173 {
175 }
176 
178 {
179  ARM_COMPUTE_ERROR_ON_MSG_VAR((_shader_params_size != (int)(_shader_arguments.size() * sizeof(_shader_arguments[0]))), "Arguments size (%zu) is not equal to shader params block size (%d)",
180  _shader_arguments.size() * sizeof(_shader_arguments[0]), _shader_params_size);
181 
182  ARM_COMPUTE_GL_CHECK(glUniformBlockBinding(_program, _shader_params_index, _shader_params_binding_point));
183  ARM_COMPUTE_GL_CHECK(glBindBufferBase(GL_UNIFORM_BUFFER, _shader_params_binding_point, _shader_params_ubo_name));
184  ARM_COMPUTE_GL_CHECK(glBindBuffer(GL_UNIFORM_BUFFER, _shader_params_ubo_name));
185  ARM_COMPUTE_GL_CHECK(glBufferData(GL_UNIFORM_BUFFER, _shader_params_size, _shader_arguments.data(), GL_DYNAMIC_DRAW));
186  ARM_COMPUTE_GL_CHECK(glBindBuffer(GL_UNIFORM_BUFFER, 0));
187 }
188 
189 const std::map<std::string, std::string> GCKernelLibrary::_shader_program_map =
190 {
191  { "absdiff", "absdiff.cs" },
192  { "tensorshift", "tensor_shift.cs" },
193  { "direct_convolution1x1", "direct_convolution1x1.cs" },
194  { "direct_convolution3x3", "direct_convolution3x3.cs" },
195  { "direct_convolution5x5", "direct_convolution5x5.cs" },
196  { "pooling_layer_2", "pooling_layer.cs" },
197  { "pooling_layer_3", "pooling_layer.cs" },
198  { "pooling_layer_7", "pooling_layer.cs" },
199  { "pooling_layer_3_optimized", "pooling_layer.cs" },
200  { "pooling_layer_n", "pooling_layer.cs" },
201  { "fill_image_borders_replicate", "fill_border.cs" },
202  { "fill_image_borders_constant", "fill_border.cs" },
203  { "gemm_accumulate_biases", "gemm.cs" },
204  { "gemm_interleave4x4", "gemm.cs" },
205  { "gemm_ma", "gemm.cs" },
206  { "gemm_mm_interleaved_transposed", "gemm.cs" },
207  { "gemm_mm_floating_point", "gemm.cs" },
208  { "gemm_transpose1x4", "gemm.cs" },
209  { "reshape_to_columns", "convolution_layer.cs" },
210  { "im2col_kernel3x3_padx0_pady0", "convolution_layer.cs" },
211  { "im2col_generic", "convolution_layer.cs" },
212  { "im2col_reduced", "convolution_layer.cs" },
213  { "col2im", "convolution_layer.cs" },
214  { "transpose", "transpose.cs" },
215  { "activation_layer", "activation_layer.cs" },
216  { "softmax_layer_max", "softmax_layer.cs" },
217  { "softmax_layer_shift_exp_sum", "softmax_layer.cs" },
218  { "softmax_layer_norm", "softmax_layer.cs" },
219  { "pixelwise_mul_float", "pixelwise_mul_float.cs" },
220  { "normalization_layer", "normalization_layer.cs" },
221  { "batchnormalization_layer", "batchnormalization_layer.cs" },
222  { "concatenate_depth", "concatenate.cs" },
223  { "dropout", "dropout.cs" },
224  { "normalize_planar_yuv_layer", "normalize_planar_yuv_layer.cs" },
225  { "scale_nearest_neighbour", "scale.cs" },
226  { "arithmetic_add", "arithmetic_add.cs" },
227  { "depthwise_convolution_3x3", "depthwise_convolution3x3.cs" },
228 };
229 
230 const std::map<std::string, std::string> GCKernelLibrary::_program_source_map =
231 {
232 #ifdef EMBEDDED_KERNELS
233  {
234  "helpers_cs.h",
235 #include "./cs_shaders/helpers_cs.hembed"
236  },
237  {
238  "activation_layer_helpers_cs.h",
239 #include "./cs_shaders/activation_layer_helpers_cs.hembed"
240  },
241  {
242  "absdiff.cs",
243 #include "./cs_shaders/absdiff.csembed"
244  },
245  {
246  "tensor_shift.cs",
247 #include "./cs_shaders/tensor_shift.csembed"
248  },
249  {
250  "convolution_layer.cs",
251 #include "./cs_shaders/convolution_layer.csembed"
252  },
253  {
254  "direct_convolution1x1.cs",
255 #include "./cs_shaders/direct_convolution1x1.csembed"
256  },
257  {
258  "direct_convolution3x3.cs",
259 #include "./cs_shaders/direct_convolution3x3.csembed"
260  },
261  {
262  "direct_convolution5x5.cs",
263 #include "./cs_shaders/direct_convolution5x5.csembed"
264  },
265  {
266  "pooling_layer.cs",
267 #include "./cs_shaders/pooling_layer.csembed"
268  },
269  {
270  "fill_border.cs",
271 #include "./cs_shaders/fill_border.csembed"
272  },
273  {
274  "gemm.cs",
275 #include "./cs_shaders/gemm.csembed"
276  },
277  {
278  "transpose.cs",
279 #include "./cs_shaders/transpose.csembed"
280  },
281  {
282  "activation_layer.cs",
283 #include "./cs_shaders/activation_layer.csembed"
284  },
285  {
286  "softmax_layer.cs",
287 #include "./cs_shaders/softmax_layer.csembed"
288  },
289  {
290  "pixelwise_mul_float.cs",
291 #include "./cs_shaders/pixelwise_mul_float.csembed"
292  },
293  {
294  "normalization_layer.cs",
295 #include "./cs_shaders/normalization_layer.csembed"
296  },
297  {
298  "batchnormalization_layer.cs",
299 #include "./cs_shaders/batchnormalization_layer.csembed"
300  },
301  {
302  "concatenate.cs",
303 #include "./cs_shaders/concatenate.csembed"
304  },
305  {
306  "dropout.cs",
307 #include "./cs_shaders/dropout.csembed"
308  },
309  {
310  "normalize_planar_yuv_layer.cs",
311 #include "./cs_shaders/normalize_planar_yuv_layer.csembed"
312  },
313  {
314  "scale.cs",
315 #include "./cs_shaders/scale.csembed"
316  },
317  {
318  "arithmetic_add.cs",
319 #include "./cs_shaders/arithmetic_add.csembed"
320  },
321  {
322  "depthwise_convolution3x3.cs",
323 #include "./cs_shaders/depthwise_convolution3x3.csembed"
324  },
325 #endif /* EMBEDDED_KERNELS */
326 };
327 
329  : _display(EGL_NO_DISPLAY), _context(EGL_NO_CONTEXT), _frame_buffer(0), _tex_rt(0), _shader_path("./"), _programs_map(), _built_programs_map()
330 {
331 }
332 
334 {
335  static GCKernelLibrary _kernel_library;
336  return _kernel_library;
337 }
338 
339 void GCKernelLibrary::init(std::string shader_path, EGLDisplay dpy, EGLContext ctx)
340 {
341  //TODO: deal with old display and context.
342  _shader_path = std::move(shader_path);
343 
344  _display = dpy;
345  _context = ctx;
346 
347  eglMakeCurrent(_display, EGL_NO_SURFACE, EGL_NO_SURFACE, _context);
348  setup_dummy_fbo();
349 }
350 
351 void GCKernelLibrary::set_shader_path(const std::string &shader_path)
352 {
353  _shader_path = shader_path;
354 }
355 
356 void GCKernelLibrary::set_context(EGLDisplay dpy, EGLContext ctx)
357 {
358  //TODO: deal with old display and context.
359  _display = dpy;
360  _context = ctx;
361 
362  eglMakeCurrent(dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, ctx);
363  setup_dummy_fbo();
364 }
365 
366 GCKernel GCKernelLibrary::create_kernel(const std::string &shader_name, const StringSet &build_options_set) const
367 {
368  // Find which program contains the kernel
369  auto shader_program_it = _shader_program_map.find(shader_name);
370 
371  if(_shader_program_map.end() == shader_program_it)
372  {
373  ARM_COMPUTE_ERROR_VAR("Shader %s not found in the GCKernelLibrary", shader_name.c_str());
374  }
375 
376  // Check if the program has been built before with same build options.
377  const std::string program_name = shader_program_it->second;
378  const std::string build_options = stringify_set(build_options_set);
379  const std::string built_program_name = program_name + "_" + build_options;
380  auto built_program_it = _built_programs_map.find(built_program_name);
381 
382  GCKernel kernel;
383 
384  if(_built_programs_map.end() != built_program_it)
385  {
386  // If program has been built, retrieve to create kernel from it
387  kernel = built_program_it->second;
388  }
389  else
390  {
391  GCProgram program = load_program(program_name);
392 
393  std::string source_name = _shader_path + shader_program_it->second;
394 
395  // load shader
396  GLuint shader = program.compile_shader(build_options);
397 
398  // Build program
399  GLuint gles_program = program.link_program(shader);
400 
401  // Create GCKernel
402  kernel = GCKernel(shader_name, gles_program);
403 
404  // Add built program to internal map
405  _built_programs_map.emplace(built_program_name, kernel);
406  }
407 
408  kernel.use();
409  kernel.clear_arguments();
410  // set shader params binding point
412 
413  return kernel;
414 }
415 
416 std::string GCKernelLibrary::preprocess_shader(const std::string &shader_source) const
417 {
418  enum class ParserStage
419  {
420  FIRST,
421  SKIP_COMMENTS = FIRST,
422  RESOLVE_INCLUDES,
423  LAST
424  };
425 
426  // Define a GLES compute shader parser function
427  std::function<std::string(const std::string &, ParserStage, int)> cs_parser;
428  cs_parser = [&](const std::string & src, ParserStage stage, int) -> std::string
429  {
430  std::string dst;
431 
432  if(stage == ParserStage::LAST || std::regex_match(src, std::regex(R"(\s*)")))
433  {
434  return src;
435  }
436  auto next_stage = static_cast<ParserStage>(static_cast<int>(stage) + 1);
437 
438  std::string search_pattern;
439  switch(stage)
440  {
441  case ParserStage::SKIP_COMMENTS:
442  search_pattern = R"((/\*([^*]|\n|(\*+([^*/]|\n)))*\*+/)|(//.*))";
443  break;
444  case ParserStage::RESOLVE_INCLUDES:
445  search_pattern = R"rgx((?:^|\n)[ \t]*#include "(.*)")rgx";
446  break;
447  default:
448  break;
449  }
450 
451  std::regex search_regex(search_pattern);
452  std::smatch match;
453  ptrdiff_t parsed_pos = 0;
454  if(std::regex_search(src, match, search_regex))
455  {
456  // Pass the content before the match to the next stage
457  dst.append(cs_parser(src.substr(0, match.position()), next_stage, 0));
458  parsed_pos = match.position() + match.length();
459 
460  // Deal with the matched content
461  switch(stage)
462  {
463  case ParserStage::RESOLVE_INCLUDES:
464  {
465  // Replace with the included file contents
466  // And parse the content from the first stage
467  const std::string source_name = _shader_path + match.str(1);
468  dst.append(cs_parser(read_file(source_name, false), ParserStage::FIRST, 0));
469  break;
470  }
471  case ParserStage::SKIP_COMMENTS:
472  default:
473  dst.append(match.str());
474  break;
475  }
476  next_stage = stage;
477  }
478  dst.append(cs_parser(src.substr(parsed_pos, src.length() - parsed_pos), next_stage, 0));
479 
480  return dst;
481  };
482 
483  return cs_parser(shader_source, ParserStage::FIRST, 0);
484 }
485 
486 const GCProgram &GCKernelLibrary::load_program(const std::string &program_name) const
487 {
488  const auto program_it = _programs_map.find(program_name);
489 
490  if(program_it != _programs_map.end())
491  {
492  return program_it->second;
493  }
494 
495  GCProgram program;
496 
497 #ifdef EMBEDDED_KERNELS
498  const auto program_source_it = _program_source_map.find(program_name);
499 
500  if(_program_source_map.end() == program_source_it)
501  {
502  ARM_COMPUTE_ERROR_VAR("Embedded program for %s does not exist.", program_name.c_str());
503  }
504 
505  program = GCProgram(program_name, program_source_it->second);
506 #else /* EMBEDDED_KERNELS */
507  // Check for binary
508  std::string source_name = _shader_path + program_name;
509  if(std::ifstream(source_name).is_open())
510  {
511  program = GCProgram(program_name, preprocess_shader(read_file(source_name, false)));
512  }
513  else
514  {
515  ARM_COMPUTE_ERROR_VAR("Shader file %s does not exist.", source_name.c_str());
516  }
517 #endif /* EMBEDDED_KERNELS */
518 
519  // Insert program to program map
520  const auto new_program = _programs_map.emplace(program_name, std::move(program));
521 
522  return new_program.first->second;
523 }
524 
526 {
527  ARM_COMPUTE_GL_CHECK(glGenFramebuffers(1, &_frame_buffer));
528  ARM_COMPUTE_GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, _frame_buffer));
529  ARM_COMPUTE_GL_CHECK(glGenTextures(1, &_tex_rt));
530  ARM_COMPUTE_GL_CHECK(glBindTexture(GL_TEXTURE_2D, _tex_rt));
531  ARM_COMPUTE_GL_CHECK(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr));
532  ARM_COMPUTE_GL_CHECK(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, _tex_rt, 0));
533 }
534 
536 {
537  for(auto &program : _built_programs_map)
538  {
539  static_cast<GCKernel>(program.second).cleanup();
540  }
541 
542  ARM_COMPUTE_GL_CHECK(glBindTexture(GL_TEXTURE_2D, 0));
543  ARM_COMPUTE_GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, 0));
545  ARM_COMPUTE_GL_CHECK(glDeleteFramebuffers(1, &_frame_buffer));
546 }
547 
548 std::string GCKernelLibrary::stringify_set(const StringSet &s) const
549 {
550  std::string concat_set;
551 
552  // Concatenate set
553  for(const auto &el : s)
554  {
555  concat_set += el + "\n";
556  }
557 
558  return concat_set;
559 }
void GL_APIENTRY glGenTextures(GLsizei n, GLuint *textures)
Definition: OpenGLES.cpp:724
GCProgram()
Default constructor.
#define ARM_COMPUTE_GL_CHECK(x)
Definition: OpenGLES.h:45
EGLBoolean EGLAPIENTRY eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx)
Definition: OpenGLES.cpp:256
void GL_APIENTRY glBindTexture(GLenum target, GLuint texture)
Definition: OpenGLES.cpp:750
void GL_APIENTRY glDeleteTextures(GLsizei n, const GLuint *textures)
Definition: OpenGLES.cpp:737
void set_context(EGLDisplay dpy, EGLContext ctx)
Sets display and context to create kernel.
void GL_APIENTRY glBindFramebuffer(GLenum target, GLuint framebuffer)
Definition: OpenGLES.cpp:802
void GL_APIENTRY glDeleteBuffers(GLsizei n, const GLuint *buffers)
Definition: OpenGLES.cpp:529
void GL_APIENTRY glGetProgramInfoLog(GLuint program, GLsizei bufSize, GLsizei *length, GLchar *infoLog)
Definition: OpenGLES.cpp:399
GLuint compile_shader(const std::string &build_options)
Compile shader.
void GL_APIENTRY glCompileShader(GLuint shader)
Definition: OpenGLES.cpp:321
std::string name() const
Returns kernel name.
#define ARM_COMPUTE_ERROR_VAR(msg,...)
Print the given message then throw an std::runtime_error.
Definition: Error.h:346
void update_shader_params()
Update shader params.
std::stringstream ss(mlgo_str)
void GL_APIENTRY glGetShaderiv(GLuint shader, GLenum pname, GLint *params)
Definition: OpenGLES.cpp:438
#define ARM_COMPUTE_ERROR_ON_MSG_VAR(cond, msg,...)
Definition: Error.h:457
GCKernel class.
void use()
Use current program.
GCProgram class.
SimpleTensor< float > src
Definition: DFT.cpp:155
Copyright (c) 2017-2021 Arm Limited.
void GL_APIENTRY glUniformBlockBinding(GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding)
Definition: OpenGLES.cpp:698
void set_shader_params_binding_point(unsigned int binding)
Set shader params binding point.
void GL_APIENTRY glDeleteFramebuffers(GLsizei n, const GLuint *framebuffers)
Definition: OpenGLES.cpp:789
std::string name() const
Returns program name.
void cleanup()
Clean up program and ubo.
void GL_APIENTRY glBindBuffer(GLenum target, GLuint buffer)
Definition: OpenGLES.cpp:490
void GL_APIENTRY glDeleteProgram(GLuint program)
Definition: OpenGLES.cpp:360
void GL_APIENTRY glBindBufferBase(GLenum target, GLuint index, GLuint buffer)
Definition: OpenGLES.cpp:503
#define ARM_COMPUTE_LOG_INFO_MSG_WITH_FORMAT_CORE(fmt,...)
Log information level formatted message to the core system logger.
Definition: Log.h:99
GLuint GL_APIENTRY glGetUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
Definition: OpenGLES.cpp:711
std::string read_file(const std::string &filename, bool binary)
Load an entire file in memory.
Definition: Utils.cpp:38
void set_shader_path(const std::string &shader_path)
Sets the path that the shaders reside in.
void GL_APIENTRY glUseProgram(GLuint program)
Definition: OpenGLES.cpp:477
Manages all the GLES kernels compilation and caching, provides accessors for the GLES Context...
void GL_APIENTRY glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels)
Definition: OpenGLES.cpp:763
void GL_APIENTRY glShaderSource(GLuint shader, GLsizei count, const GLchar *const *string, const GLint *length)
Definition: OpenGLES.cpp:464
std::set< std::string > build_options
void GL_APIENTRY glGenBuffers(GLsizei n, GLuint *buffers)
Definition: OpenGLES.cpp:568
GCKernelLibrary()
Default Constructor.
GLuint GL_APIENTRY glCreateShader(GLenum type)
Definition: OpenGLES.cpp:347
~GCKernelLibrary()
Default Destructor.
#define ARM_COMPUTE_LOG_INFO_STREAM_CORE(ss)
Log information level stream to the core system logger.
Definition: Log.h:110
GLuint link_program(GLuint shader)
Link program.
void GL_APIENTRY glAttachShader(GLuint program, GLuint shader)
Definition: OpenGLES.cpp:308
void setup_dummy_fbo()
Setup a dummy fbo to workaround an issue on Galaxy S8.
void GL_APIENTRY glFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
Definition: OpenGLES.cpp:815
GLuint GL_APIENTRY glCreateProgram()
Definition: OpenGLES.cpp:334
void GL_APIENTRY glGetProgramiv(GLuint program, GLenum pname, GLint *params)
Definition: OpenGLES.cpp:412
void clear_arguments()
Clear shader arguments.
static GCKernelLibrary & get()
Get the static instance of GCKernelLibrary.
void GL_APIENTRY glGenFramebuffers(GLsizei n, GLuint *framebuffers)
Definition: OpenGLES.cpp:776
void init(std::string shader_path="./", EGLDisplay dpy=EGL_NO_DISPLAY, EGLContext ctx=EGL_NO_CONTEXT)
Initialises the kernel library.
void GL_APIENTRY glLinkProgram(GLuint program)
Definition: OpenGLES.cpp:451
void GL_APIENTRY glDetachShader(GLuint program, GLuint shader)
Definition: OpenGLES.cpp:386
void GL_APIENTRY glDeleteShader(GLuint shader)
Definition: OpenGLES.cpp:373
GCKernel create_kernel(const std::string &shader_name, const StringSet &build_options_set={}) const
Creates a kernel from the kernel library.
void GL_APIENTRY glGetActiveUniformBlockiv(GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint *params)
Definition: OpenGLES.cpp:685
GCKernel()
Default Constructor.
void unuse()
Unuse current program.
GCKernelLibrary class.
void GL_APIENTRY glBufferData(GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage)
Definition: OpenGLES.cpp:516
void GL_APIENTRY glGetShaderInfoLog(GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *infoLog)
Definition: OpenGLES.cpp:425