54 return _gemm_heuristics;
59 _queue = std::move(queue);
80 _queue.enqueueMarker(&event);
86 if(_cl_tuner !=
nullptr)
94 return _is_initialised;
97 std::once_flag CLScheduler::_initialize_symbols;
100 : _context(), _queue(), _target(
GPUTarget::
MIDGARD), _is_initialised(false), _cl_tuner(nullptr), _cl_default_static_tuner(nullptr), _gemm_heuristics(nullptr)
115 const std::string cl_kernels_folder(
"./cl_kernels/");
116 cl::CommandQueue
queue = cl::CommandQueue(ctx, device);
118 init(ctx, queue, device, cl_tuner, gemm_h);
120 _cl_tuner = (cl_tuner ==
nullptr) ? _cl_default_static_tuner.get() : cl_tuner;
133 cl::CommandQueue
queue = cl::CommandQueue(ctx, dev);
135 init(ctx, queue, dev, cl_tuner, gemm_h);
141 _cl_tuner = (cl_tuner ==
nullptr) ? _cl_default_static_tuner.get() : cl_tuner;
146 _context = std::move(context);
153 _queue = std::move(queue);
155 _is_initialised =
true;
156 _cl_tuner = cl_tuner;
157 _gemm_heuristics = gemm_h;
163 "The CLScheduler is not initialised yet! Please call the CLScheduler::get().default_init(), \ 164 or CLScheduler::get()::init() and CLKernelLibrary::get()::init() function before running functions!");
166 const bool inject_memory = !tensors.
empty();
169 if(_cl_tuner !=
nullptr)
175 inject_memory ? kernel.
run_op(tensors, kernel.
window(), _queue) : kernel.
run(kernel.
window(), _queue);
186 enqueue_common(kernel, pack, flush);
191 enqueue_common(kernel, tensors, flush);
void set_target(GPUTarget target)
Accessor to set target GPU to be used by the scheduler.
const Window & window() const
The maximum window the kernel can be executed on.
virtual void run(const Window &window, cl::CommandQueue &queue)
Enqueue the OpenCL kernel to process the given window on the passed OpenCL command queue...
static CLScheduler & get()
Access the scheduler singleton.
bool empty() const
Checks if pack is empty.
GPUTarget target() const
Get the target GPU.
void set_context(cl::Context context)
Accessor to set the CL context to be used by the scheduler.
void default_init_with_context(cl::Device &device, cl::Context &ctx, ICLTuner *cl_tuner=nullptr, CLGEMMHeuristicsHandle *gemm_h=nullptr)
Initialises the scheduler with context and device provided by the user.
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
virtual void tune_kernel_dynamic(ICLKernel &kernel)=0
Tune OpenCL kernel dynamically.
static CLKernelLibrary & get()
Access the KernelLibrary singleton.
bool is_initialised() const
std::tuple< cl::Context, cl::Device, cl_int > create_opencl_context_and_device()
This function creates an OpenCL context and a device.
void set_context(cl::Context context)
Sets the CL context used to create programs.
Common interface for all the OpenCL kernels.
CLGEMMHeuristicsHandle * gemm_heuristics() const
Accessor for the associated CLGEMMHeuristicsHandle.
Copyright (c) 2017-2021 Arm Limited.
Interface to enqueue OpenCL kernels and get/set the OpenCL CommandQueue and ICLTuner.
cl::Context & context()
Accessor for the associated CL context.
cl::Event enqueue_sync_event()
Enqueues a marker into the associated command queue and return the event.
#define ARM_COMPUTE_ERROR_ON_MSG(cond, msg)
void enqueue_op(ICLKernel &kernel, ITensorPack &tensors, bool flush=true)
Schedule the execution of the passed kernel if possible.
void init(cl::Context context, cl::CommandQueue queue, const cl::Device &device, ICLTuner *cl_tuner=nullptr, CLGEMMHeuristicsHandle *gemm_h=nullptr)
Initialises the context and command queue to be used by the scheduler.
GPUTarget get_target_from_device(const cl::Device &device)
Helper function to get the GPU target from CL device.
void init(std::string kernel_path, cl::Context context, cl::Device device)
Initialises the kernel library.
void set_tuner(ICLTuner *tuner)
Accessor to set the CL tuner to be used by the scheduler.
cl::CommandQueue & queue()
Accessor for the associated CL command queue.
void enqueue(ICLKernel &kernel, bool flush=true)
Schedule the execution of the passed kernel if possible.
void set_queue(cl::CommandQueue queue)
Accessor to set the CL command queue to be used by the scheduler.
CLScheduler()
Constructor.
void sync()
Blocks until all commands in the associated command queue have finished.
Handle for loading and retrieving GEMM heuristics.
GPUTarget
Available GPU Targets.
Manages all the OpenCL kernels compilation and caching, provides accessors for the OpenCL Context...
virtual void tune_kernel_static(ICLKernel &kernel)=0
Tune OpenCL kernel statically.
Provides global access to a CL context and command queue.
Basic interface for tuning the OpenCL kernels.
void default_init(ICLTuner *cl_tuner=nullptr, CLGEMMHeuristicsHandle *gemm_h=nullptr)
Initialises the context and command queue used by the scheduler to default values and sets a default ...
static std::unique_ptr< ICLTuner > create_tuner(GPUTarget target)
void tune_kernel_static(ICLKernel &kernel)
Tunes OpenCL kernel.
virtual void run_op(ITensorPack &tensors, const Window &window, cl::CommandQueue &queue)
Enqueue the OpenCL kernel to process the given window on the passed OpenCL command queue...
bool opencl_is_available()
Check if OpenCL is available.
cl::Context & context()
Accessor for the associated CL context.