Skip to content

Commit 35d8e82

Browse files
documentation: CB events with overlapping dependencies
Signed-off-by: Bartosz Dunajski <[email protected]>
1 parent c1ac3a7 commit 35d8e82

File tree

1 file changed

+48
-1
lines changed

1 file changed

+48
-1
lines changed

level_zero/doc/experimental_extensions/COUNTER_BASED_EVENTS.md

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ SPDX-License-Identifier: MIT
1414
* [Obtaining counter memory and value](#Obtaining-counter-memory-and-value)
1515
* [IPC sharing](#IPC-sharing)
1616
* [Regular command list](#Regular-command-list)
17+
* [Multi directional dependencies on Regular command lists](#Multi-directional-dependencies-on-Regular-command-lists)
1718

1819
# Overview
1920

@@ -159,7 +160,10 @@ ze_result_t zexCounterBasedEventCloseIpcHandle(ze_event_handle_t hEvent);
159160
# Regular command list
160161
Regular command list is a special use case for CB Events. Its state is additionally updated on every `zeCommandQueueExecuteCommandLists` call.
161162
Any API call that relies on explicit counter memory/value (eg. `zexEventGetDeviceAddress`) needs to be called again to obtain new data. This includes IPC.
162-
Other API calls that don't specify counter explicitly, are managed by the Driver.
163+
Other API calls that don't specify counter explicitly, are managed by the Driver.
164+
165+
**Each regular command list execution updates state of the events that will be signaled in that command list to "not ready".**
166+
**This rule applies to `zeCommandQueueExecuteCommandLists` and `zeCommandListImmediateAppendCommandListsExp` API calls.**
163167

164168
```cpp
165169
// in-order operations
@@ -182,3 +186,46 @@ zeCommandQueueExecuteCommandLists(cmdQueue, 1, &regularCmdList1, nullptr); // Co
182186
// execute regularCmdList2 2nd time
183187
zeCommandQueueExecuteCommandLists(cmdQueue, 1, &regularCmdList2, nullptr); // wait for counter=8
184188
```
189+
190+
# Multi directional dependencies on Regular command lists
191+
Regular command list with overlapping dependencies may be executed multiple times. For example, two command lists are executed in parallel with bi-directional dependencies.
192+
Its important to understand counter (Event) state transition, to correctly reflect Users intention.
193+
194+
```
195+
regularCmdList1: (A) -------------> (wait for B) -----> (C)
196+
| ^
197+
| |
198+
V |
199+
regularCmdList2: (wait for A) -------------> (B) -----> (D)
200+
```
201+
202+
In this example, all Events are synchronized to "ready" state after the first execution.
203+
It means that second execution of `regularCmdList1` waits again for "ready" `{1->2->3}` state of `regularCmdList2` (first execution) instead of `{4->5->6}`.
204+
This is because `regularCmdList2` was not yet executed for the second time. And their counters were not updated.
205+
206+
**First execution:**
207+
```cpp
208+
// All Events are in "not ready" state
209+
zeCommandQueueExecuteCommandLists(cmdQueue1, 1, &regularCmdList1, nullptr); // Counter updated to {1->2->3}
210+
zeCommandQueueExecuteCommandLists(cmdQueue2, 1, &regularCmdList2, nullptr); // Counter updated to {1->2->3}
211+
212+
// All Events are "ready" now
213+
zeCommandQueueSynchronize(cmdQueue1, timeout); // wait for counter=3
214+
zeCommandQueueSynchronize(cmdQueue2, timeout); // wait for counter=3
215+
```
216+
217+
**Second execution:**
218+
```cpp
219+
// regularCmdList1 waits for "ready" {1->2->3} Events from first execution of regularCmdList2
220+
// regularCmdList1 changes Events state to "not ready"
221+
zeCommandQueueExecuteCommandLists(cmdQueue1, 1, &regularCmdList1, nullptr); // Counter updated to {4->5->6}
222+
223+
// regularCmdList2 waits for "not ready" {4->5->6} Events from second execution of regularCmdList1
224+
zeCommandQueueExecuteCommandLists(cmdQueue2, 1, &regularCmdList2, nullptr); // Counter updated to {4->5->6}
225+
```
226+
227+
**Different approach:**
228+
229+
To avoid above situation, User must remove all bi-directional dependencies. By using single command list (if possible) or split the workload into different command lists with single-directional dependencies.
230+
231+
Using Counter Based Events for such scenarios is not always the most optimal usage mode. It may be better to use Regular Events with explicit Reset calls.

0 commit comments

Comments
 (0)