aboutsummaryrefslogtreecommitdiff
path: root/arm_compute/core
diff options
context:
space:
mode:
Diffstat (limited to 'arm_compute/core')
-rw-r--r--arm_compute/core/CL/CLCoreRuntimeContext.h63
-rw-r--r--arm_compute/core/CL/CLHelpers.h13
-rw-r--r--arm_compute/core/CL/CLKernelLibrary.h78
-rw-r--r--arm_compute/core/CL/OpenCL.h3
-rw-r--r--arm_compute/core/CL/kernels/CLActivationLayerKernel.h11
5 files changed, 98 insertions, 70 deletions
diff --git a/arm_compute/core/CL/CLCoreRuntimeContext.h b/arm_compute/core/CL/CLCoreRuntimeContext.h
new file mode 100644
index 0000000000..6e2bd43d53
--- /dev/null
+++ b/arm_compute/core/CL/CLCoreRuntimeContext.h
@@ -0,0 +1,63 @@
+/*
+ * 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.
+ */
+#ifndef __ARM_COMPUTE_CLCORERUNTIME_CONTEXT_H__
+#define __ARM_COMPUTE_CLCORERUNTIME_CONTEXT_H__
+
+#include "arm_compute/core/CL/OpenCL.h"
+
+namespace arm_compute
+{
+class CLKernelLibrary;
+/** Core runtime context */
+class CLCoreRuntimeContext final
+{
+public:
+ /** Legacy constructor */
+ CLCoreRuntimeContext();
+
+ /** Constructor */
+ CLCoreRuntimeContext(CLKernelLibrary *kernel_lib, cl::Context ctx, cl::CommandQueue queue);
+ /** Destructor */
+ ~CLCoreRuntimeContext() = default;
+ /** Default copy constructor */
+ CLCoreRuntimeContext(const CLCoreRuntimeContext &) = default;
+ /** Default move constructor */
+ CLCoreRuntimeContext(CLCoreRuntimeContext &&) = default;
+ /** Default copy assignment */
+ CLCoreRuntimeContext &operator=(const CLCoreRuntimeContext &) = default;
+ /** Default move assignment operator */
+ CLCoreRuntimeContext &operator=(CLCoreRuntimeContext &&) = default;
+ /** CPU Scheduler setter */
+
+ CLKernelLibrary *kernel_library() const;
+ cl::Context context();
+ cl::CommandQueue queue();
+
+private:
+ CLKernelLibrary *_kernel_lib{ nullptr };
+ cl::Context _ctx{};
+ cl::CommandQueue _queue{};
+};
+} // namespace arm_compute
+#endif /*__ARM_COMPUTE_CLCORERUNTIME_CONTEXT_H__ */
diff --git a/arm_compute/core/CL/CLHelpers.h b/arm_compute/core/CL/CLHelpers.h
index 16fe09fb96..1d647a86b0 100644
--- a/arm_compute/core/CL/CLHelpers.h
+++ b/arm_compute/core/CL/CLHelpers.h
@@ -34,6 +34,9 @@
namespace arm_compute
{
+class CLCoreRuntimeContext;
+class CLBuildOptions;
+
enum class DataType;
/** Max vector width of an OpenCL vector */
@@ -153,5 +156,15 @@ size_t preferred_vector_width(const cl::Device &device, DataType dt);
* @return True if dummy work-items should be preferred to dispatch the NDRange
*/
bool preferred_dummy_work_items_support(const cl::Device &device);
+
+/** Creates an opencl kernel
+ *
+ * @param[in] ctx A context to be used to create the opencl kernel.
+ * @param[in] kernel_name The kernel name.
+ * @param[in] build_opts The build options to be used for the opencl kernel compilation.
+ *
+ * @return An opencl kernel
+ */
+cl::Kernel create_opencl_kernel(CLCoreRuntimeContext *ctx, const std::string &kernel_name, const CLBuildOptions &build_opts);
}
#endif /* __ARM_COMPUTE_CLHELPERS_H__ */
diff --git a/arm_compute/core/CL/CLKernelLibrary.h b/arm_compute/core/CL/CLKernelLibrary.h
index 9f183f1232..f2282692f9 100644
--- a/arm_compute/core/CL/CLKernelLibrary.h
+++ b/arm_compute/core/CL/CLKernelLibrary.h
@@ -34,7 +34,7 @@
namespace arm_compute
{
/** Build options */
-class CLBuildOptions
+class CLBuildOptions final
{
using StringSet = std::set<std::string>;
@@ -80,7 +80,7 @@ private:
StringSet _build_opts; /**< Build options set */
};
/** Program class */
-class Program
+class Program final
{
public:
/** Default constructor. */
@@ -147,7 +147,7 @@ private:
};
/** Kernel class */
-class Kernel
+class Kernel final
{
public:
/** Default Constructor. */
@@ -189,20 +189,19 @@ private:
};
/** CLKernelLibrary class */
-class CLKernelLibrary
+class CLKernelLibrary final
{
using StringSet = std::set<std::string>;
-private:
+public:
/** Default Constructor. */
CLKernelLibrary();
-
-public:
/** Prevent instances of this class from being copied */
CLKernelLibrary(const CLKernelLibrary &) = delete;
/** Prevent instances of this class from being copied */
const CLKernelLibrary &operator=(const CLKernelLibrary &) = delete;
/** Access the KernelLibrary singleton.
+ * This method has been deprecated and will be removed in the next release.
* @return The KernelLibrary instance.
*/
static CLKernelLibrary &get();
@@ -212,26 +211,15 @@ public:
* @param[in] context CL context used to create programs.
* @param[in] device CL device for which the programs are created.
*/
- void 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 init(std::string kernel_path, cl::Context context, cl::Device device);
/** Sets the path that the kernels reside in.
*
* @param[in] kernel_path Path of the kernel.
*/
- void set_kernel_path(const std::string &kernel_path)
- {
- _kernel_path = kernel_path;
- };
+ void set_kernel_path(const std::string &kernel_path);
/** Gets the path that the kernels reside in.
*/
- std::string get_kernel_path()
- {
- return _kernel_path;
- };
+ std::string get_kernel_path();
/** Gets the source of the selected program.
*
* @param[in] program_name Program name.
@@ -246,51 +234,22 @@ public:
*
* @param[in] context A CL context.
*/
- void 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];
- }
- }
- }
+ void set_context(cl::Context context);
/** Accessor for the associated CL context.
*
* @return A CL context.
*/
- cl::Context &context()
- {
- return _context;
- }
+ cl::Context &context();
/** Gets the CL device for which the programs are created. */
- cl::Device &get_device()
- {
- return _device;
- }
+ cl::Device &get_device();
/** Sets the CL device for which the programs are created.
*
* @param[in] device A CL device.
*/
- void set_device(cl::Device device)
- {
- _device = std::move(device);
- }
+ void set_device(cl::Device device);
/** Return the device version
*
@@ -321,17 +280,10 @@ public:
/** Clear the library's cache of binary programs
*/
- void clear_programs_cache()
- {
- _programs_map.clear();
- _built_programs_map.clear();
- }
+ void clear_programs_cache();
/** Access the cache of built OpenCL programs */
- const std::map<std::string, cl::Program> &get_built_programs() const
- {
- return _built_programs_map;
- }
+ const std::map<std::string, cl::Program> &get_built_programs() const;
/** Add a new built program to the cache
*
diff --git a/arm_compute/core/CL/OpenCL.h b/arm_compute/core/CL/OpenCL.h
index 912a53103a..b1d50e73b1 100644
--- a/arm_compute/core/CL/OpenCL.h
+++ b/arm_compute/core/CL/OpenCL.h
@@ -60,11 +60,10 @@ bool opencl_is_available();
/** Class for loading OpenCL symbols. */
class CLSymbols final
{
-private:
+public:
CLSymbols() = default;
void load_symbols(void *handle);
-public:
/** Get the static instance of CLSymbols.
*
* @return The static instance of CLSymbols.
diff --git a/arm_compute/core/CL/kernels/CLActivationLayerKernel.h b/arm_compute/core/CL/kernels/CLActivationLayerKernel.h
index f20d6c3362..c64f7c42ac 100644
--- a/arm_compute/core/CL/kernels/CLActivationLayerKernel.h
+++ b/arm_compute/core/CL/kernels/CLActivationLayerKernel.h
@@ -29,13 +29,13 @@
namespace arm_compute
{
class ICLTensor;
-
+class CLCoreRuntimeContext;
/** Interface for the activation layer kernel. */
class CLActivationLayerKernel : public ICLKernel
{
public:
/** Default constructor */
- CLActivationLayerKernel();
+ CLActivationLayerKernel(CLCoreRuntimeContext *ctx = nullptr);
/** Prevent instances of this class from being copied (As this class contains pointers) */
CLActivationLayerKernel(const CLActivationLayerKernel &) = delete;
/** Prevent instances of this class from being copied (As this class contains pointers) */
@@ -71,9 +71,10 @@ public:
void run(const Window &window, cl::CommandQueue &queue) override;
private:
- ICLTensor *_input;
- ICLTensor *_output;
- bool _run_in_place;
+ ICLTensor *_input;
+ ICLTensor *_output;
+ bool _run_in_place;
+ CLCoreRuntimeContext *_ctx;
};
} // namespace arm_compute
#endif /*__ARM_COMPUTE_CLACTIVATIONLAYERKERNEL_H__ */