From 7ae80a928564eba96c4fef0b91b1c50e1647fb8d Mon Sep 17 00:00:00 2001 From: Georgios Pinitas Date: Fri, 25 Oct 2019 18:25:17 +0100 Subject: COMPMID-2549: Add GLES Runtime Context interfaces. * Creates interfaces and concrete classes * Ports GCActivationalLayer * Adapts test framework and relevant tests Change-Id: Ide36cd65ebf185958db3c4a5bebd630fcb2f39b3 Signed-off-by: Georgios Pinitas Reviewed-on: https://review.mlplatform.org/c/2199 Reviewed-by: Pablo Marquez Tested-by: Arm Jenkins Comments-Addressed: Arm Jenkins --- src/core/CL/CLHelpers.cpp | 4 +-- src/core/GLES_COMPUTE/GCCoreRuntimeContext.cpp | 42 ++++++++++++++++++++++ src/core/GLES_COMPUTE/GCHelpers.cpp | 18 +++++++++- src/core/GLES_COMPUTE/GCKernelLibrary.cpp | 27 ++++++++++++++ .../kernels/GCActivationLayerKernel.cpp | 6 ++-- 5 files changed, 91 insertions(+), 6 deletions(-) create mode 100644 src/core/GLES_COMPUTE/GCCoreRuntimeContext.cpp (limited to 'src/core') diff --git a/src/core/CL/CLHelpers.cpp b/src/core/CL/CLHelpers.cpp index 1132aa4540..26660ce215 100644 --- a/src/core/CL/CLHelpers.cpp +++ b/src/core/CL/CLHelpers.cpp @@ -338,12 +338,12 @@ cl::Kernel create_opencl_kernel(CLCoreRuntimeContext *ctx, const std::string &ke { if(ctx && ctx->kernel_library()) { - //New api going through the core context + // New api going through the core context return static_cast(ctx->kernel_library()->create_kernel(kernel_name, build_opts.options())); } else { - //Legacy code through the singleton + // Legacy code through the singleton return static_cast(CLKernelLibrary::get().create_kernel(kernel_name, build_opts.options())); } } diff --git a/src/core/GLES_COMPUTE/GCCoreRuntimeContext.cpp b/src/core/GLES_COMPUTE/GCCoreRuntimeContext.cpp new file mode 100644 index 0000000000..311dfd2fa7 --- /dev/null +++ b/src/core/GLES_COMPUTE/GCCoreRuntimeContext.cpp @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2019 ARM Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#include "arm_compute/core/GLES_COMPUTE/GCCoreRuntimeContext.h" + +namespace arm_compute +{ +GCCoreRuntimeContext::GCCoreRuntimeContext() + : _kernel_lib(nullptr) +{ +} + +GCCoreRuntimeContext::GCCoreRuntimeContext(GCKernelLibrary *kernel_lib) + : _kernel_lib(kernel_lib) +{ +} + +GCKernelLibrary *GCCoreRuntimeContext::kernel_library() const +{ + return _kernel_lib; +} +} // namespace arm_compute diff --git a/src/core/GLES_COMPUTE/GCHelpers.cpp b/src/core/GLES_COMPUTE/GCHelpers.cpp index 8970688ca7..b9740071a5 100644 --- a/src/core/GLES_COMPUTE/GCHelpers.cpp +++ b/src/core/GLES_COMPUTE/GCHelpers.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018 ARM Limited. + * Copyright (c) 2018-2019 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -23,6 +23,8 @@ */ #include "arm_compute/core/GLES_COMPUTE/GCHelpers.h" +#include "arm_compute/core/GLES_COMPUTE/GCCoreRuntimeContext.h" + namespace arm_compute { GPUTarget get_target_from_device() @@ -31,4 +33,18 @@ GPUTarget get_target_from_device() return get_target_from_name(device_name); } + +GCKernel create_opengl_kernel(GCCoreRuntimeContext *ctx, const std::string &kernel_name, const std::set &build_opts) +{ + if(ctx && ctx->kernel_library()) + { + // New api going through the core context + return ctx->kernel_library()->create_kernel(kernel_name, build_opts); + } + else + { + // Legacy code through the singleton + return GCKernelLibrary::get().create_kernel(kernel_name, build_opts); + } +} } // namespace arm_compute diff --git a/src/core/GLES_COMPUTE/GCKernelLibrary.cpp b/src/core/GLES_COMPUTE/GCKernelLibrary.cpp index 015e085355..4b3c5aa869 100644 --- a/src/core/GLES_COMPUTE/GCKernelLibrary.cpp +++ b/src/core/GLES_COMPUTE/GCKernelLibrary.cpp @@ -337,6 +337,33 @@ GCKernelLibrary &GCKernelLibrary::get() return _kernel_library; } +void GCKernelLibrary::init(std::string shader_path, EGLDisplay dpy, EGLContext ctx) +{ + //TODO: deal with old display and context. + _shader_path = std::move(shader_path); + + _display = dpy; + _context = ctx; + + eglMakeCurrent(_display, EGL_NO_SURFACE, EGL_NO_SURFACE, _context); + setup_dummy_fbo(); +} + +void GCKernelLibrary::set_shader_path(const std::string &shader_path) +{ + _shader_path = shader_path; +} + +void GCKernelLibrary::set_context(EGLDisplay dpy, EGLContext ctx) +{ + //TODO: deal with old display and context. + _display = dpy; + _context = ctx; + + eglMakeCurrent(dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, ctx); + setup_dummy_fbo(); +} + GCKernel GCKernelLibrary::create_kernel(const std::string &shader_name, const StringSet &build_options_set) const { // Find which program contains the kernel diff --git a/src/core/GLES_COMPUTE/kernels/GCActivationLayerKernel.cpp b/src/core/GLES_COMPUTE/kernels/GCActivationLayerKernel.cpp index 174e04811a..ab3e179a14 100644 --- a/src/core/GLES_COMPUTE/kernels/GCActivationLayerKernel.cpp +++ b/src/core/GLES_COMPUTE/kernels/GCActivationLayerKernel.cpp @@ -39,8 +39,8 @@ using namespace arm_compute; -GCActivationLayerKernel::GCActivationLayerKernel() - : _input(nullptr), _output(nullptr) +GCActivationLayerKernel::GCActivationLayerKernel(GCCoreRuntimeContext *ctx) + : _input(nullptr), _output(nullptr), _ctx(ctx) { } @@ -77,7 +77,7 @@ void GCActivationLayerKernel::configure(IGCTensor *input, IGCTensor *output, Act build_opts.emplace(("#define LOCAL_SIZE_Z " + support::cpp11::to_string(1))); // Create kernel - _kernel = static_cast(GCKernelLibrary::get().create_kernel("activation_layer", build_opts)); + _kernel = create_opengl_kernel(_ctx, "activation_layer", build_opts); // Configure kernel window Window win = calculate_max_window(*input->info(), Steps(num_elems_processed_per_iteration)); -- cgit v1.2.1