aboutsummaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/CL/CLCoreRuntimeContext.cpp52
-rw-r--r--src/core/CL/CLHelpers.cpp16
-rw-r--r--src/core/CL/CLKernelLibrary.cpp65
-rw-r--r--src/core/CL/OpenCL.cpp5
-rw-r--r--src/core/CL/kernels/CLActivationLayerKernel.cpp8
5 files changed, 141 insertions, 5 deletions
diff --git a/src/core/CL/CLCoreRuntimeContext.cpp b/src/core/CL/CLCoreRuntimeContext.cpp
new file mode 100644
index 0000000000..f9efad2c0d
--- /dev/null
+++ b/src/core/CL/CLCoreRuntimeContext.cpp
@@ -0,0 +1,52 @@
+/*
+ * 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/CL/CLCoreRuntimeContext.h"
+
+namespace arm_compute
+{
+cl::Context CLCoreRuntimeContext::context()
+{
+ return _ctx;
+}
+
+cl::CommandQueue CLCoreRuntimeContext::queue()
+{
+ return _queue;
+}
+
+CLCoreRuntimeContext::CLCoreRuntimeContext()
+ : _kernel_lib(nullptr), _ctx(), _queue()
+{
+}
+
+CLCoreRuntimeContext::CLCoreRuntimeContext(CLKernelLibrary *kernel_lib, cl::Context ctx, cl::CommandQueue queue)
+ : _kernel_lib(kernel_lib), _ctx(ctx), _queue(queue)
+{
+}
+
+CLKernelLibrary *CLCoreRuntimeContext::kernel_library() const
+{
+ return _kernel_lib;
+}
+} // namespace arm_compute
diff --git a/src/core/CL/CLHelpers.cpp b/src/core/CL/CLHelpers.cpp
index d051810090..a3c73677c7 100644
--- a/src/core/CL/CLHelpers.cpp
+++ b/src/core/CL/CLHelpers.cpp
@@ -22,6 +22,8 @@
* SOFTWARE.
*/
#include "arm_compute/core/CL/CLHelpers.h"
+#include "arm_compute/core/CL/CLCoreRuntimeContext.h"
+#include "arm_compute/core/CL/CLKernelLibrary.h"
#include "arm_compute/core/CL/CLTypes.h"
#include "arm_compute/core/Error.h"
#include "arm_compute/core/Log.h"
@@ -283,4 +285,18 @@ bool preferred_dummy_work_items_support(const cl::Device &device)
// TODO (COMPMID-2044)
return true;
}
+
+cl::Kernel create_opencl_kernel(CLCoreRuntimeContext *ctx, const std::string &kernel_name, const CLBuildOptions &build_opts)
+{
+ if(ctx && ctx->kernel_library())
+ {
+ //New api going through the core context
+ return static_cast<cl::Kernel>(ctx->kernel_library()->create_kernel(kernel_name, build_opts.options()));
+ }
+ else
+ {
+ //Legacy code through the singleton
+ return static_cast<cl::Kernel>(CLKernelLibrary::get().create_kernel(kernel_name, build_opts.options()));
+ }
+}
} // namespace arm_compute
diff --git a/src/core/CL/CLKernelLibrary.cpp b/src/core/CL/CLKernelLibrary.cpp
index 7b7263fca7..c27f886129 100644
--- a/src/core/CL/CLKernelLibrary.cpp
+++ b/src/core/CL/CLKernelLibrary.cpp
@@ -1144,6 +1144,49 @@ Kernel CLKernelLibrary::create_kernel(const std::string &kernel_name, const Stri
return Kernel(kernel_name, cl_program);
}
+void CLKernelLibrary::init(std::string kernel_path, cl::Context context, cl::Device device)
+{
+ _kernel_path = std::move(kernel_path);
+ _context = std::move(context);
+ _device = std::move(device);
+}
+
+void CLKernelLibrary::set_kernel_path(const std::string &kernel_path)
+{
+ _kernel_path = kernel_path;
+}
+
+cl::Context &CLKernelLibrary::context()
+{
+ return _context;
+}
+
+cl::Device &CLKernelLibrary::get_device()
+{
+ return _device;
+}
+
+void CLKernelLibrary::set_device(cl::Device device)
+{
+ _device = std::move(device);
+}
+
+std::string CLKernelLibrary::get_kernel_path()
+{
+ return _kernel_path;
+}
+
+void CLKernelLibrary::clear_programs_cache()
+{
+ _programs_map.clear();
+ _built_programs_map.clear();
+}
+
+const std::map<std::string, cl::Program> &CLKernelLibrary::get_built_programs() const
+{
+ return _built_programs_map;
+}
+
void CLKernelLibrary::add_built_program(const std::string &built_program_name, const cl::Program &program)
{
_built_programs_map.emplace(built_program_name, program);
@@ -1205,6 +1248,28 @@ const Program &CLKernelLibrary::load_program(const std::string &program_name) co
return new_program.first->second;
}
+void CLKernelLibrary::set_context(cl::Context context)
+{
+ _context = std::move(context);
+ if(_context.get() == nullptr)
+ {
+ _device = cl::Device();
+ }
+ else
+ {
+ const auto cl_devices = _context.getInfo<CL_CONTEXT_DEVICES>();
+
+ if(cl_devices.empty())
+ {
+ _device = cl::Device();
+ }
+ else
+ {
+ _device = cl_devices[0];
+ }
+ }
+}
+
std::string CLKernelLibrary::stringify_set(const StringSet &s) const
{
std::string concat_set;
diff --git a/src/core/CL/OpenCL.cpp b/src/core/CL/OpenCL.cpp
index 1ce1b526d7..74c5b041d7 100644
--- a/src/core/CL/OpenCL.cpp
+++ b/src/core/CL/OpenCL.cpp
@@ -27,6 +27,8 @@
#include "arm_compute/core/CL/OpenCL.h"
#pragma GCC diagnostic pop
+#include "arm_compute/core/Error.h"
+
#include <dlfcn.h>
#include <iostream>
@@ -54,6 +56,7 @@ bool CLSymbols::load_default()
{
if(load(lib))
{
+ ARM_COMPUTE_ERROR_ON_MSG(this->clBuildProgram_ptr == nullptr, "Failed to load OpenCL symbols from shared library");
return true;
}
}
@@ -948,4 +951,4 @@ clImportMemoryARM(cl_context context,
}
return nullptr;
}
-} \ No newline at end of file
+}
diff --git a/src/core/CL/kernels/CLActivationLayerKernel.cpp b/src/core/CL/kernels/CLActivationLayerKernel.cpp
index 97a0ff6c6c..5062fd1801 100644
--- a/src/core/CL/kernels/CLActivationLayerKernel.cpp
+++ b/src/core/CL/kernels/CLActivationLayerKernel.cpp
@@ -23,8 +23,8 @@
*/
#include "arm_compute/core/CL/kernels/CLActivationLayerKernel.h"
+#include "arm_compute/core/CL/CLCoreRuntimeContext.h"
#include "arm_compute/core/CL/CLHelpers.h"
-#include "arm_compute/core/CL/CLKernelLibrary.h"
#include "arm_compute/core/CL/CLValidate.h"
#include "arm_compute/core/CL/ICLTensor.h"
#include "arm_compute/core/Helpers.h"
@@ -111,8 +111,8 @@ std::pair<Status, Window> validate_and_configure_window(ITensorInfo *input, ITen
}
} // namespace
-CLActivationLayerKernel::CLActivationLayerKernel()
- : _input(nullptr), _output(nullptr), _run_in_place(false)
+CLActivationLayerKernel::CLActivationLayerKernel(CLCoreRuntimeContext *ctx)
+ : _input(nullptr), _output(nullptr), _run_in_place(false), _ctx(ctx)
{
}
@@ -205,8 +205,8 @@ void CLActivationLayerKernel::configure(ICLTensor *input, ICLTensor *output, Act
{
kernel_name += perform_activation_in_float ? std::string("_quant_f32") : std::string("_quant");
}
- _kernel = static_cast<cl::Kernel>(CLKernelLibrary::get().create_kernel(kernel_name, build_opts.options()));
+ _kernel = create_opencl_kernel(_ctx, kernel_name, build_opts);
// Make sure _kernel is initialized before calling the parent's configure
_input = input;
_output = output;