DLPrimitives
Public Member Functions | Friends | List of all members
dlprim::ExecutionContext Class Reference

This class is used to pass cl::Events that the kernel should wait for and/or signal event completion. More...

#include <include/dlprim/context.hpp>

Public Member Functions

 ExecutionContext ()
 default constructor - can be used for CPU context
 
 ExecutionContext (cl::CommandQueue const &q)
 Create context from cl::CommandQueue, note no events will be waited/signaled.
 
 ExecutionContext (cl::CommandQueue const &q, cl::Event *event)
 Create a context with a request to signal completion event.
 
 ExecutionContext (cl::CommandQueue const &q, std::vector< cl::Event > *events)
 Create a context with a request to wait for events.
 
 ExecutionContext (cl::CommandQueue const &q, std::vector< cl::Event > *events, cl::Event *event)
 Create a context with a request to signal completion event and wait for events.
 
bool is_cpu_context () const
 
 ExecutionContext (ExecutionContext const &)=default
 
ExecutionContextoperator= (ExecutionContext const &)=default
 
bool timing_enabled () const
 
void enable_timing (std::shared_ptr< TimingData > p)
 Add benchmarking/traceing object data.
 
ExecutionContext generate_series_context (size_t id, size_t total) const
 Create contexts for multiple enqueues. More...
 
void enter (char const *name) const
 Profiling scope enter called by ExecGuard::ExecGuard()
 
void leave () const
 Profiling scope leave, called by ExecGuard::~ExecGuard()
 
void finish ()
 
cl::CommandQueue & queue () const
 Get the command queue. Never call it in non-OpenCL context.
 
cl::Event * event (char const *name="unknown", int id=-1) const
 Get event to signal. Note: name is used for profiling. Such that profiling is enabled profiling conters will be written the TimingData with the name of the kernel you call. Optional id allows to distinguish between multiple similar calls.
 
std::vector< cl::Event > * events () const
 Get events to wait for.
 
ExecutionContext first_context () const
 Create context that waits for event if needed - use only if you know that more kernels are followed.
 
ExecutionContext middle_context () const
 Create context does not wait or signals use only if you know that more kernels run before and after.
 
ExecutionContext last_context () const
 Create context that signals for completion event if needed - use only if you know that more kernels run before.
 

Friends

class Context
 

Detailed Description

This class is used to pass cl::Events that the kernel should wait for and/or signal event completion.

It is also used to pass cl::CommandQueue over API

Use it as following:

void do_stuff(...,ExecutionContext const &e)
{
...
/ e.queue().enqueueNDRangeKernel(kernel,nd1,nd2,nd3,
e.events(), // <- events to wait, nullptr of none
e.event("do_stuff")); //<- event to signal,
// if profiling is used will be recorderd
// under this name
}

If you need to run several kernels use generate_series_context(#,total)

For example:

run_data_preparation(e.generate_series_context(0,3)); // waits for events if needed
run_processing(e.generate_series_context(1,3)); // no events waited,signaled
run_reduce(e.generate_series_context(2,3)); // signals completion event if needed

Member Function Documentation

ExecutionContext dlprim::ExecutionContext::generate_series_context ( size_t  id,
size_t  total 
) const
inline

Create contexts for multiple enqueues.

The idea is simple if we have events to signal and wait for and multiple kernels to execute, the first execution id == 0 should provide list of events to wait if id == total - 1, give event to signal


The documentation for this class was generated from the following file: