Events

sycl::event

class event;

Events support the explicit control of scheduling of kernels, and querying status of a running kernel. Operations like submit that queue a kernel for execution may accept an event to wait on and return an event associated with the queued kernel.

See also

SYCL Specification Section 4.6.6

(constructors)

event();
event(cl_event clEvent, const sycl::context& syclContext);

Construct an event.

cl_event_get

cl_event get();

Returns OpenCL|trade| event associated with this event.

is_host

bool is_host() const;

Returns True if this a host event

get_wait_list

sycl::vector_class<sycl::event> get_wait_list();

Returns vector of events that this events waits on.

wait

void wait();

Wait for the associated command to complete.

wait

static void wait(const sycl::vector_class<sycl::event> &eventList);

Wait for vector of events to complete.

wait_and_throw

void wait_and_throw();

Wait for an event to complete, and pass asynchronous errors to handler associated with the command.

wait_and_throw

static void wait_and_throw(const sycl::vector_class<sycl::event> &eventList);

Wait for a vector of events to complete, and pass asynchronous errors to handlers associated with the commands.

get_info

template <sycl::info::event param>
typename sycl::info::param_traits<sycl::info::event, param>::return_type get_info() const;

Returns information about the queue as determined by param. See sycl::info::event for details.

get_profiling_info

template <sycl::info::event_profiling param>
typename sycl::info::param_traits<sycl::info::event_profiling, param>::return_type get_profiling_info() const;

Returns information about the queue as determined by param. See sycl::info::event_profiling for details.

Example

Measure the elapsed time of a memcpy executed on a device with event profiling info.

 1#include <CL/sycl.hpp>
 2
 3int main() {
 4  sycl::property_list properties{sycl::property::queue::enable_profiling()};
 5  auto q = sycl::queue(sycl::gpu_selector(), properties);
 6
 7  std::cout << "  Platform: "
 8	    << q.get_device().get_platform().get_info<sycl::info::platform::name>()
 9	    << std::endl;
10
11  const int num_ints = 1024 * 1024;
12  const size_t num_bytes = num_ints * sizeof(int);
13  const int alignment = 8;
14
15  // Alloc memory on host
16  auto src = aligned_alloc(alignment, num_bytes);
17  memset(src, 1, num_bytes);
18
19  // Alloc memory on device
20  auto dst = sycl::malloc_device<int>(num_ints, q);
21  q.memset(dst, 0, num_bytes).wait();
22
23  // Copy from host to device
24  auto event = q.memcpy(dst, src, num_bytes);
25  event.wait();
26
27  auto end = event.get_profiling_info<sycl::info::event_profiling::command_end>();
28  auto start = event.get_profiling_info<sycl::info::event_profiling::command_start>();
29
30  std::cout << "Elapsed time: " << (end-start)/1.0e9 << " seconds\n";
31
32  sycl::free(dst, q);
33}

Output:

  Platform: Intel(R) Level-Zero
Elapsed time: 7.6692e-05 seconds

sycl::info::event

enum class event: int {
  command_execution_status,
  reference_count
};

Used as a template parameter for get_info to determine the type of information.

Descriptor

Return type

Description

command_execution_status

sycl::info::event_command_status

See sycl::info::event_command_status

reference_count

cl_uint

Reference count of the event

sycl::info::event_command_status

enum class event_command_status : int {
  submitted,
  running,
  complete
};

sycl::info::event_profiling

enum class event_profiling : int {
  command_submit,
  command_start,
  command_end
};

Used as a template parameter for get_profiling_info to determine the type of information.

Descriptor

Return type

Description

command_submit

cl_ulong

Time in nanoseconds when sycl::command_group was submitted

command_start

cl_ulong

Time in nanoseconds when sycl::command_group started execution

command_end

cl_ulong

Time in nanoseconds when sycl::command_group finished execution