aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/GLES_COMPUTE
diff options
context:
space:
mode:
Diffstat (limited to 'src/runtime/GLES_COMPUTE')
-rw-r--r--src/runtime/GLES_COMPUTE/GCHelpers.cpp85
-rw-r--r--src/runtime/GLES_COMPUTE/GCRuntimeContext.cpp67
-rw-r--r--src/runtime/GLES_COMPUTE/GCScheduler.cpp8
-rw-r--r--src/runtime/GLES_COMPUTE/IGCSimpleFunction.cpp15
-rw-r--r--src/runtime/GLES_COMPUTE/functions/GCActivationLayer.cpp8
5 files changed, 174 insertions, 9 deletions
diff --git a/src/runtime/GLES_COMPUTE/GCHelpers.cpp b/src/runtime/GLES_COMPUTE/GCHelpers.cpp
new file mode 100644
index 0000000000..df2f4f5e6e
--- /dev/null
+++ b/src/runtime/GLES_COMPUTE/GCHelpers.cpp
@@ -0,0 +1,85 @@
+/*
+ * 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/runtime/GLES_COMPUTE/GCHelpers.h"
+
+#include "arm_compute/core/Error.h"
+
+namespace arm_compute
+{
+std::tuple<EGLDisplay, EGLContext, EGLBoolean> create_opengl_display_and_context()
+{
+ EGLBoolean res;
+ EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
+
+ ARM_COMPUTE_ERROR_ON_MSG_VAR(display == EGL_NO_DISPLAY, "Failed to get display: 0x%x.", eglGetError());
+
+ res = eglInitialize(display, nullptr, nullptr);
+
+ ARM_COMPUTE_ERROR_ON_MSG_VAR(res == EGL_FALSE, "Failed to initialize egl: 0x%x.", eglGetError());
+ ARM_COMPUTE_UNUSED(res);
+
+ const char *egl_extension_st = eglQueryString(display, EGL_EXTENSIONS);
+ ARM_COMPUTE_ERROR_ON_MSG((strstr(egl_extension_st, "EGL_KHR_create_context") == nullptr), "Failed to query EGL_KHR_create_context");
+ ARM_COMPUTE_ERROR_ON_MSG((strstr(egl_extension_st, "EGL_KHR_surfaceless_context") == nullptr), "Failed to query EGL_KHR_surfaceless_context");
+ ARM_COMPUTE_UNUSED(egl_extension_st);
+
+ const std::array<EGLint, 3> config_attribs =
+ {
+ EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT_KHR,
+ EGL_NONE
+ };
+ EGLConfig cfg;
+ EGLint count;
+
+ res = eglChooseConfig(display, config_attribs.data(), &cfg, 1, &count);
+
+ ARM_COMPUTE_ERROR_ON_MSG_VAR(res == EGL_FALSE, "Failed to choose config: 0x%x.", eglGetError());
+ ARM_COMPUTE_UNUSED(res);
+
+ res = eglBindAPI(EGL_OPENGL_ES_API);
+
+ ARM_COMPUTE_ERROR_ON_MSG_VAR(res == EGL_FALSE, "Failed to bind api: 0x%x.", eglGetError());
+
+ const std::array<EGLint, 3> attribs =
+ {
+ EGL_CONTEXT_CLIENT_VERSION, 3,
+ EGL_NONE
+ };
+ EGLContext context = eglCreateContext(display,
+ cfg,
+ EGL_NO_CONTEXT,
+ attribs.data());
+
+ ARM_COMPUTE_ERROR_ON_MSG_VAR(context == EGL_NO_CONTEXT, "Failed to create context: 0x%x.", eglGetError());
+ ARM_COMPUTE_UNUSED(res);
+
+ res = eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, context);
+
+ ARM_COMPUTE_ERROR_ON_MSG_VAR(res == EGL_FALSE, "Failed to make current: 0x%x.", eglGetError());
+ ARM_COMPUTE_UNUSED(res);
+
+ return std::make_tuple(display, context, res);
+}
+} // namespace arm_compute
diff --git a/src/runtime/GLES_COMPUTE/GCRuntimeContext.cpp b/src/runtime/GLES_COMPUTE/GCRuntimeContext.cpp
new file mode 100644
index 0000000000..1c30af1b71
--- /dev/null
+++ b/src/runtime/GLES_COMPUTE/GCRuntimeContext.cpp
@@ -0,0 +1,67 @@
+/*
+ * 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/runtime/GLES_COMPUTE/GCRuntimeContext.h"
+
+#include "arm_compute/core/Validate.h"
+#include "arm_compute/runtime/GLES_COMPUTE/GCHelpers.h"
+#include "arm_compute/runtime/GLES_COMPUTE/GCScheduler.h"
+
+namespace arm_compute
+{
+GCRuntimeContext::GCRuntimeContext()
+ : _gpu_owned_scheduler(support::cpp14::make_unique<GCScheduler>()),
+ _gpu_scheduler(_gpu_owned_scheduler.get()),
+ _core_context()
+{
+ auto attrs = create_opengl_display_and_context();
+ auto display = std::get<0>(attrs);
+ auto ctx = std::get<1>(attrs);
+
+ _gpu_owned_scheduler->default_init_with_context(display, ctx);
+ _kernel_lib.init("./cs_shaders/", display, ctx);
+
+ _core_context = GCCoreRuntimeContext(&_kernel_lib);
+}
+
+GCKernelLibrary &GCRuntimeContext::kernel_library()
+{
+ return _kernel_lib;
+}
+
+GCCoreRuntimeContext *GCRuntimeContext::core_runtime_context()
+{
+ return &_core_context;
+}
+
+void GCRuntimeContext::set_gpu_scheduler(GCScheduler *scheduler)
+{
+ ARM_COMPUTE_ERROR_ON_NULLPTR(scheduler);
+ _gpu_scheduler = scheduler;
+}
+
+GCScheduler *GCRuntimeContext::gpu_scheduler()
+{
+ return _gpu_scheduler;
+}
+} // namespace arm_compute
diff --git a/src/runtime/GLES_COMPUTE/GCScheduler.cpp b/src/runtime/GLES_COMPUTE/GCScheduler.cpp
index 0824af3ed4..a45d7931be 100644
--- a/src/runtime/GLES_COMPUTE/GCScheduler.cpp
+++ b/src/runtime/GLES_COMPUTE/GCScheduler.cpp
@@ -52,6 +52,14 @@ void GCScheduler::default_init()
init(_display, _context);
}
+void GCScheduler::default_init_with_context(EGLDisplay display, EGLContext ctx)
+{
+ _context = ctx;
+ _display = display;
+
+ _target = get_target_from_device();
+}
+
void GCScheduler::init(EGLDisplay dpy, EGLContext ctx)
{
_target = get_target_from_device();
diff --git a/src/runtime/GLES_COMPUTE/IGCSimpleFunction.cpp b/src/runtime/GLES_COMPUTE/IGCSimpleFunction.cpp
index f2926b0a3f..bb9239eabe 100644
--- a/src/runtime/GLES_COMPUTE/IGCSimpleFunction.cpp
+++ b/src/runtime/GLES_COMPUTE/IGCSimpleFunction.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017 ARM Limited.
+ * Copyright (c) 2017-2019 ARM Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -28,17 +28,20 @@
using namespace arm_compute;
-IGCSimpleFunction::IGCSimpleFunction() //NOLINT
+IGCSimpleFunction::IGCSimpleFunction(GCRuntimeContext *ctx) //NOLINT
: _kernel(),
- _border_handler()
+ _border_handler(),
+ _ctx(ctx)
{
}
void IGCSimpleFunction::run()
{
ARM_COMPUTE_ERROR_ON_MSG(!_kernel, "The child class didn't set the GLES kernel or function isn't configured");
+ GCScheduler *scheduler = (_ctx != nullptr) ? _ctx->gpu_scheduler() : &GCScheduler::get().get();
+ ARM_COMPUTE_ERROR_ON(scheduler == nullptr);
- GCScheduler::get().dispatch(_border_handler, false);
- GCScheduler::get().memory_barrier();
- GCScheduler::get().dispatch(*_kernel);
+ scheduler->dispatch(_border_handler, false);
+ scheduler->memory_barrier();
+ scheduler->dispatch(*_kernel);
}
diff --git a/src/runtime/GLES_COMPUTE/functions/GCActivationLayer.cpp b/src/runtime/GLES_COMPUTE/functions/GCActivationLayer.cpp
index 207e8cef56..0700b2b400 100644
--- a/src/runtime/GLES_COMPUTE/functions/GCActivationLayer.cpp
+++ b/src/runtime/GLES_COMPUTE/functions/GCActivationLayer.cpp
@@ -29,14 +29,16 @@
namespace arm_compute
{
-GCActivationLayer::GCActivationLayer(void *ctx)
+GCActivationLayer::GCActivationLayer(GCRuntimeContext *ctx)
+ : IGCSimpleFunction(ctx)
{
- ARM_COMPUTE_UNUSED(ctx);
}
void GCActivationLayer::configure(IGCTensor *input, IGCTensor *output, ActivationLayerInfo act_info)
{
- auto k = arm_compute::support::cpp14::make_unique<GCActivationLayerKernel>();
+ auto core_ctx = _ctx ? _ctx->core_runtime_context() : /* Legacy */ nullptr;
+
+ auto k = arm_compute::support::cpp14::make_unique<GCActivationLayerKernel>(core_ctx);
k->configure(input, output, act_info);
_kernel = std::move(k);
}