Compute Library
 19.08
GCKernelLibrary Class Reference

GCKernelLibrary class. More...

#include <GCKernelLibrary.h>

Public Member Functions

 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()

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 340 of file GCKernelLibrary.cpp.

341 {
342  // Find which program contains the kernel
343  auto shader_program_it = _shader_program_map.find(shader_name);
344 
345  if(_shader_program_map.end() == shader_program_it)
346  {
347  ARM_COMPUTE_ERROR("Shader %s not found in the GCKernelLibrary", shader_name.c_str());
348  }
349 
350  // Check if the program has been built before with same build options.
351  const std::string program_name = shader_program_it->second;
352  const std::string build_options = stringify_set(build_options_set);
353  const std::string built_program_name = program_name + "_" + build_options;
354  auto built_program_it = _built_programs_map.find(built_program_name);
355 
356  GCKernel kernel;
357 
358  if(_built_programs_map.end() != built_program_it)
359  {
360  // If program has been built, retrieve to create kernel from it
361  kernel = built_program_it->second;
362  }
363  else
364  {
365  GCProgram program = load_program(program_name);
366 
367  std::string source_name = _shader_path + shader_program_it->second;
368 
369  // load shader
370  GLuint shader = program.compile_shader(build_options);
371 
372  // Build program
373  GLuint gles_program = program.link_program(shader);
374 
375  // Create GCKernel
376  kernel = GCKernel(shader_name, gles_program);
377 
378  // Add built program to internal map
379  _built_programs_map.emplace(built_program_name, kernel);
380  }
381 
382  kernel.use();
383  kernel.clear_arguments();
384  // set shader params binding point
386 
387  return kernel;
388 }
#define ARM_COMPUTE_ERROR(...)
Print the given message then throw an std::runtime_error.
Definition: Error.h:261
GLuint compile_shader(const std::string &build_options)
Compile shader.
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, 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(), and GCGEMMMatrixMultiplyKernel::configure().

◆ get()

◆ init()

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

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 212 of file GCKernelLibrary.h.

213  {
214  //TODO: deal with old display and context.
215  _shader_path = std::move(shader_path);
216 
217  _display = dpy;
218  _context = ctx;
219 
220  eglMakeCurrent(_display, EGL_NO_SURFACE, EGL_NO_SURFACE, _context);
221  setup_dummy_fbo();
222  }
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 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 
)
inline

Sets display and context to create kernel.

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

Definition at line 237 of file GCKernelLibrary.h.

238  {
239  //TODO: deal with old display and context.
240  _display = dpy;
241  _context = ctx;
242 
243  eglMakeCurrent(dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, ctx);
244  setup_dummy_fbo();
245  };
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)
inline

Sets the path that the shaders reside in.

Parameters
[in]shader_pathPath of the shader.

Definition at line 228 of file GCKernelLibrary.h.

229  {
230  _shader_path = shader_path;
231  };

◆ setup_dummy_fbo()

void setup_dummy_fbo ( )

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

Definition at line 499 of file GCKernelLibrary.cpp.

500 {
501  ARM_COMPUTE_GL_CHECK(glGenFramebuffers(1, &_frame_buffer));
502  ARM_COMPUTE_GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, _frame_buffer));
503  ARM_COMPUTE_GL_CHECK(glGenTextures(1, &_tex_rt));
504  ARM_COMPUTE_GL_CHECK(glBindTexture(GL_TEXTURE_2D, _tex_rt));
505  ARM_COMPUTE_GL_CHECK(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr));
506  ARM_COMPUTE_GL_CHECK(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, _tex_rt, 0));
507 }
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: