Compute Library
 19.11
GCKernelLibrary Class Referencefinal

GCKernelLibrary class. More...

#include <GCKernelLibrary.h>

Public Member Functions

 GCKernelLibrary ()
 Default Constructor. More...
 
 ~GCKernelLibrary ()
 Default Destructor. More...
 
 GCKernelLibrary (const GCKernelLibrary &)=delete
 Prevent instances of this class from being copied. More...
 
const GCKernelLibraryoperator= (const GCKernelLibrary &)=delete
 Prevent instances of this class from being copied. More...
 
void init (std::string shader_path="./", EGLDisplay dpy=EGL_NO_DISPLAY, EGLContext ctx=EGL_NO_CONTEXT)
 Initialises the kernel library. More...
 
void set_shader_path (const std::string &shader_path)
 Sets the path that the shaders reside in. More...
 
void set_context (EGLDisplay dpy, EGLContext ctx)
 Sets display and context to create kernel. More...
 
GCKernel create_kernel (const std::string &shader_name, const StringSet &build_options_set={}) const
 Creates a kernel from the kernel library. More...
 
void save_binary ()
 Serializes and saves programs to a binary. More...
 
void load_binary ()
 Load serialized binary with all the programs. More...
 
void setup_dummy_fbo ()
 Setup a dummy fbo to workaround an issue on Galaxy S8. More...
 

Static Public Member Functions

static GCKernelLibraryget ()
 Get the static instance of GCKernelLibrary. More...
 

Detailed Description

GCKernelLibrary class.

Definition at line 187 of file GCKernelLibrary.h.

Constructor & Destructor Documentation

◆ GCKernelLibrary() [1/2]

Default Constructor.

Definition at line 329 of file GCKernelLibrary.cpp.

330  : _display(EGL_NO_DISPLAY), _context(EGL_NO_CONTEXT), _frame_buffer(0), _tex_rt(0), _shader_path("./"), _programs_map(), _built_programs_map()
331 {
332 }

◆ ~GCKernelLibrary()

Default Destructor.

Definition at line 536 of file GCKernelLibrary.cpp.

537 {
538  for(auto &program : _built_programs_map)
539  {
540  static_cast<GCKernel>(program.second).cleanup();
541  }
542 
543  ARM_COMPUTE_GL_CHECK(glBindTexture(GL_TEXTURE_2D, 0));
544  ARM_COMPUTE_GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, 0));
546  ARM_COMPUTE_GL_CHECK(glDeleteFramebuffers(1, &_frame_buffer));
547 }
#define ARM_COMPUTE_GL_CHECK(x)
Definition: OpenGLES.h:45
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 GL_APIENTRY glBindFramebuffer(GLenum target, GLuint framebuffer)
Definition: OpenGLES.cpp:802
void GL_APIENTRY glDeleteFramebuffers(GLsizei n, const GLuint *framebuffers)
Definition: OpenGLES.cpp:789

References ARM_COMPUTE_GL_CHECK, glBindFramebuffer(), glBindTexture(), glDeleteFramebuffers(), and glDeleteTextures().

◆ GCKernelLibrary() [2/2]

GCKernelLibrary ( const GCKernelLibrary )
delete

Prevent instances of this class from being copied.

Member Function Documentation

◆ create_kernel()

GCKernel create_kernel ( const std::string &  shader_name,
const StringSet &  build_options_set = {} 
) const

Creates a kernel from the kernel library.

Parameters
[in]shader_nameShader name.
[in]build_options_setShader build options as a set.
Returns
The created kernel.

Definition at line 367 of file GCKernelLibrary.cpp.

368 {
369  // Find which program contains the kernel
370  auto shader_program_it = _shader_program_map.find(shader_name);
371 
372  if(_shader_program_map.end() == shader_program_it)
373  {
374  ARM_COMPUTE_ERROR_VAR("Shader %s not found in the GCKernelLibrary", shader_name.c_str());
375  }
376 
377  // Check if the program has been built before with same build options.
378  const std::string program_name = shader_program_it->second;
379  const std::string build_options = stringify_set(build_options_set);
380  const std::string built_program_name = program_name + "_" + build_options;
381  auto built_program_it = _built_programs_map.find(built_program_name);
382 
383  GCKernel kernel;
384 
385  if(_built_programs_map.end() != built_program_it)
386  {
387  // If program has been built, retrieve to create kernel from it
388  kernel = built_program_it->second;
389  }
390  else
391  {
392  GCProgram program = load_program(program_name);
393 
394  std::string source_name = _shader_path + shader_program_it->second;
395 
396  // load shader
397  GLuint shader = program.compile_shader(build_options);
398 
399  // Build program
400  GLuint gles_program = program.link_program(shader);
401 
402  // Create GCKernel
403  kernel = GCKernel(shader_name, gles_program);
404 
405  // Add built program to internal map
406  _built_programs_map.emplace(built_program_name, kernel);
407  }
408 
409  kernel.use();
410  kernel.clear_arguments();
411  // set shader params binding point
413 
414  return kernel;
415 }
GLuint compile_shader(const std::string &build_options)
Compile shader.
#define ARM_COMPUTE_ERROR_VAR(msg,...)
Print the given message then throw an std::runtime_error.
Definition: Error.h:346
void use()
Use current program.
GCProgram class.
void set_shader_params_binding_point(unsigned int binding)
Set shader params binding point.
GLuint link_program(GLuint shader)
Link program.
void clear_arguments()
Clear shader arguments.

References ARM_COMPUTE_ERROR_VAR, GCKernel::clear_arguments(), GCProgram::compile_shader(), GCProgram::link_program(), GCKernel::set_shader_params_binding_point(), and GCKernel::use().

Referenced by GCScaleKernel::configure(), GCGEMMMatrixAccumulateBiasesKernel::configure(), GCGEMMMatrixAdditionKernel::configure(), GCGEMMTranspose1xWKernel::configure(), GCGEMMMatrixMultiplyKernel::configure(), and arm_compute::create_opengl_kernel().

◆ get()

◆ init()

void init ( std::string  shader_path = "./",
EGLDisplay  dpy = EGL_NO_DISPLAY,
EGLContext  ctx = EGL_NO_CONTEXT 
)

Initialises the kernel library.

Parameters
[in]shader_path(Optional) Path of the directory from which shader sources are loaded.
[in]dpy(Optional) EGLdisplay set by external application.
[in]ctx(Optional) EGLContext set by external application.

Definition at line 340 of file GCKernelLibrary.cpp.

341 {
342  //TODO: deal with old display and context.
343  _shader_path = std::move(shader_path);
344 
345  _display = dpy;
346  _context = ctx;
347 
348  eglMakeCurrent(_display, EGL_NO_SURFACE, EGL_NO_SURFACE, _context);
349  setup_dummy_fbo();
350 }
EGLBoolean EGLAPIENTRY eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx)
Definition: OpenGLES.cpp:256
void setup_dummy_fbo()
Setup a dummy fbo to workaround an issue on Galaxy S8.

References eglMakeCurrent(), and GCKernelLibrary::setup_dummy_fbo().

Referenced by GCRuntimeContext::GCRuntimeContext(), and GCScheduler::init().

◆ load_binary()

void load_binary ( )

Load serialized binary with all the programs.

◆ operator=()

const GCKernelLibrary& operator= ( const GCKernelLibrary )
delete

Prevent instances of this class from being copied.

◆ save_binary()

void save_binary ( )

Serializes and saves programs to a binary.

◆ set_context()

void set_context ( EGLDisplay  dpy,
EGLContext  ctx 
)

Sets display and context to create kernel.

Parameters
[in]dpyEGLdisplay set by external application.
[in]ctxEGLContext set by external application.

Definition at line 357 of file GCKernelLibrary.cpp.

358 {
359  //TODO: deal with old display and context.
360  _display = dpy;
361  _context = ctx;
362 
363  eglMakeCurrent(dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, ctx);
364  setup_dummy_fbo();
365 }
EGLBoolean EGLAPIENTRY eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx)
Definition: OpenGLES.cpp:256
void setup_dummy_fbo()
Setup a dummy fbo to workaround an issue on Galaxy S8.

References eglMakeCurrent(), and GCKernelLibrary::setup_dummy_fbo().

◆ set_shader_path()

void set_shader_path ( const std::string &  shader_path)

Sets the path that the shaders reside in.

Parameters
[in]shader_pathPath of the shader.

Definition at line 352 of file GCKernelLibrary.cpp.

353 {
354  _shader_path = shader_path;
355 }

◆ setup_dummy_fbo()

void setup_dummy_fbo ( )

Setup a dummy fbo to workaround an issue on Galaxy S8.

Definition at line 526 of file GCKernelLibrary.cpp.

527 {
528  ARM_COMPUTE_GL_CHECK(glGenFramebuffers(1, &_frame_buffer));
529  ARM_COMPUTE_GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, _frame_buffer));
530  ARM_COMPUTE_GL_CHECK(glGenTextures(1, &_tex_rt));
531  ARM_COMPUTE_GL_CHECK(glBindTexture(GL_TEXTURE_2D, _tex_rt));
532  ARM_COMPUTE_GL_CHECK(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr));
533  ARM_COMPUTE_GL_CHECK(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, _tex_rt, 0));
534 }
void GL_APIENTRY glGenTextures(GLsizei n, GLuint *textures)
Definition: OpenGLES.cpp:724
#define ARM_COMPUTE_GL_CHECK(x)
Definition: OpenGLES.h:45
void GL_APIENTRY glBindTexture(GLenum target, GLuint texture)
Definition: OpenGLES.cpp:750
void GL_APIENTRY glBindFramebuffer(GLenum target, GLuint framebuffer)
Definition: OpenGLES.cpp:802
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 glFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
Definition: OpenGLES.cpp:815
void GL_APIENTRY glGenFramebuffers(GLsizei n, GLuint *framebuffers)
Definition: OpenGLES.cpp:776

References ARM_COMPUTE_GL_CHECK, glBindFramebuffer(), glBindTexture(), glFramebufferTexture2D(), glGenFramebuffers(), glGenTextures(), and glTexImage2D().

Referenced by GCKernelLibrary::init(), and GCKernelLibrary::set_context().


The documentation for this class was generated from the following files: