dpctl.SyclTimer

class dpctl.SyclTimer(host_timer=<built-in function perf_counter>, time_scale=1)[source]

Context to measure device time and host wall-time of execution of commands submitted to dpctl.SyclQueue.

Example:
import dpctl

# Create a default SyclQueue
q = dpctl.SyclQueue(property="enable_profiling")

# create the timer
milliseconds_sc = 1e-3
timer = dpctl.SyclTimer(time_scale = milliseconds_sc)

# use the timer
with timer(queue=q):
    code_block1

# use the timer
with timer(queue=q):
    code_block2

# retrieve elapsed times in milliseconds
wall_dt, device_dt = timer.dt

Note

The timer submits barriers to the queue at the entrance and the exit of the context and uses profiling information from events associated with these submissions to perform the timing. Thus dpctl.SyclTimer requires the queue with "enable_profiling" property. In order to be able to collect the profiling information, the dt property ensures that both submitted barriers complete their execution and thus effectively synchronizes the queue.

Parameters:
  • host_timer (callable, optional) – A callable such that host_timer() returns current host time in seconds. Default: timeit.default_timer().

  • time_scale (Union[int, float], optional) – Ratio of the unit of time of interest and one second. Default: 1.

Methods

__init__([host_timer, time_scale])

Create new instance of SyclTimer.

Attributes

dt

Returns a pair of elapsed times host_dt and device_dt.