dpctl.SyclTimer

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

Context to time execution of tasks submitted to dpctl.SyclQueue.

Example:
import dpctl

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

# create the timer
milliseconds_sc = 1e3
timer = dpctl.SyclTimer(time_scale = milliseconds_sc)

untimed_code_block_1
# use the timer
with timer(queue=q):
    timed_code_block1

untimed_code_block_2

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

untimed_code_block_3

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

Note

The timer submits tasks 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 tasks submitted by the timer complete their execution and thus effectively synchronizes the queue.

Execution of the above example results in the following task graph, where each group of tasks is ordered after the one preceding it, [tasks_of_untimed_block1], [timer_fence_start_task], [tasks_of_timed_block1], [timer_fence_finish_task], [tasks_of_untimed_block2], [timer_fence_start_task], [tasks_of_timed_block2], [timer_fence_finish_task], [tasks_of_untimed_block3].

device_timer keyword argument controls the type of tasks submitted. With "queue_barrier" value, queue barrier tasks are used. With "order_manager" value, a single empty body task is inserted and order manager (used by all dpctl.tensor operations) is used to order these tasks so that they fence operations performed within timer’s context.

Timing offloading operations that do not use the order manager with the timer that uses "order_manager" as device_timer value will be misleading becaused the tasks submitted by the timer will not be ordered with respect to tasks we intend to time.

Note, that host timer effectively measures the time of task submissions. To measure host timer wall-time that includes execution of submitted tasks, make sure to include synchronization point in the timed block.

Example:

with timer(q):

timed_block q.wait()

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

  • device_timer (Literal["queue_barrier", "order_manager"], optional) – Device timing method. Default: “queue_barrier”.

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

Methods

__init__([host_timer, device_timer, time_scale])

Create new instance of SyclTimer.

Attributes

dt

Returns a pair of elapsed times host_dt and device_dt.