|
38 | 38 |
|
39 | 39 | There is also a WaitEvent used by the `ur_exp_command_buffer_handle_t` class
|
40 | 40 | in the prefix to wait on any dependencies passed in the enqueue wait-list.
|
| 41 | + This WaitEvent is reset at the end of the suffix, along with reset commands |
| 42 | + to reset the L0 events used to implement the UR sync-points. |
41 | 43 |
|
42 | 44 | ┌──────────┬────────────────────────────────────────────────┬─────────┐
|
43 | 45 | │ Prefix │ Commands added to UR command-buffer by UR user │ Suffix │
|
|
47 | 49 | Prefix │Reset signal event │ Barrier waiting on wait event│
|
48 | 50 | └───────────────────┴──────────────────────────────┘
|
49 | 51 |
|
50 |
| - ┌─────────────────────────────────────────┐ |
51 |
| - Suffix │Signal the UR command-buffer signal event│ |
52 |
| - └─────────────────────────────────────────┘ |
53 |
| -
|
| 52 | + ┌─────────────────────────────────────────────┐──────────────┐ |
| 53 | + Suffix │Barrier waiting on sync-point event, │ Reset events │ |
| 54 | + │signalling the UR command-buffer signal event│ │ |
| 55 | + └─────────────────────────────────────────────┘──────────────┘ |
54 | 56 |
|
55 | 57 | For a call to `urCommandBufferEnqueueExp` with an event_list `EL`,
|
56 | 58 | command-buffer `CB`, and return event `RE` our implementation has to create
|
@@ -293,7 +295,7 @@ static ur_result_t enqueueCommandBufferMemCopyHelper(
|
293 | 295 | SyncPointWaitList, ZeEventList));
|
294 | 296 |
|
295 | 297 | ur_event_handle_t LaunchEvent;
|
296 |
| - UR_CALL(EventCreate(CommandBuffer->Context, nullptr, true, &LaunchEvent)); |
| 298 | + UR_CALL(EventCreate(CommandBuffer->Context, nullptr, false, &LaunchEvent)); |
297 | 299 | LaunchEvent->CommandType = CommandType;
|
298 | 300 |
|
299 | 301 | // Get sync point and register the event with it.
|
@@ -358,7 +360,7 @@ static ur_result_t enqueueCommandBufferMemCopyRectHelper(
|
358 | 360 | SyncPointWaitList, ZeEventList));
|
359 | 361 |
|
360 | 362 | ur_event_handle_t LaunchEvent;
|
361 |
| - UR_CALL(EventCreate(CommandBuffer->Context, nullptr, true, &LaunchEvent)); |
| 363 | + UR_CALL(EventCreate(CommandBuffer->Context, nullptr, false, &LaunchEvent)); |
362 | 364 | LaunchEvent->CommandType = CommandType;
|
363 | 365 |
|
364 | 366 | // Get sync point and register the event with it.
|
@@ -407,7 +409,7 @@ urCommandBufferCreateExp(ur_context_handle_t Context, ur_device_handle_t Device,
|
407 | 409 | // Create signal & wait events to be used in the command-list for sync
|
408 | 410 | // on command-buffer enqueue.
|
409 | 411 | auto RetCommandBuffer = *CommandBuffer;
|
410 |
| - UR_CALL(EventCreate(Context, nullptr, true, &RetCommandBuffer->SignalEvent)); |
| 412 | + UR_CALL(EventCreate(Context, nullptr, false, &RetCommandBuffer->SignalEvent)); |
411 | 413 | UR_CALL(EventCreate(Context, nullptr, false, &RetCommandBuffer->WaitEvent));
|
412 | 414 |
|
413 | 415 | // Add prefix commands
|
@@ -437,11 +439,31 @@ urCommandBufferReleaseExp(ur_exp_command_buffer_handle_t CommandBuffer) {
|
437 | 439 |
|
438 | 440 | UR_APIEXPORT ur_result_t UR_APICALL
|
439 | 441 | urCommandBufferFinalizeExp(ur_exp_command_buffer_handle_t CommandBuffer) {
|
440 |
| - // We need to append signal that will indicate that command-buffer has |
441 |
| - // finished executing. |
442 |
| - ZE2UR_CALL( |
443 |
| - zeCommandListAppendSignalEvent, |
444 |
| - (CommandBuffer->ZeCommandList, CommandBuffer->SignalEvent->ZeEvent)); |
| 442 | + // Create a list of events for our signal event to wait on |
| 443 | + const size_t NumEvents = CommandBuffer->SyncPoints.size(); |
| 444 | + std::vector<ze_event_handle_t> WaitEventList{NumEvents}; |
| 445 | + for (size_t i = 0; i < NumEvents; i++) { |
| 446 | + WaitEventList[i] = CommandBuffer->SyncPoints[i]->ZeEvent; |
| 447 | + } |
| 448 | + |
| 449 | + // Wait for all the user added commands to complete, and signal the |
| 450 | + // command-buffer signal-event when they are done. |
| 451 | + ZE2UR_CALL(zeCommandListAppendBarrier, |
| 452 | + (CommandBuffer->ZeCommandList, CommandBuffer->SignalEvent->ZeEvent, |
| 453 | + NumEvents, WaitEventList.data())); |
| 454 | + |
| 455 | + // Reset the wait-event for the UR command-buffer that is signalled when its |
| 456 | + // submission dependencies have been satisfied. |
| 457 | + ZE2UR_CALL(zeCommandListAppendEventReset, |
| 458 | + (CommandBuffer->ZeCommandList, CommandBuffer->WaitEvent->ZeEvent)); |
| 459 | + |
| 460 | + // Reset the L0 events we use for command-buffer internal sync-points to the |
| 461 | + // non-signalled state |
| 462 | + for (auto Event : WaitEventList) { |
| 463 | + ZE2UR_CALL(zeCommandListAppendEventReset, |
| 464 | + (CommandBuffer->ZeCommandList, Event)); |
| 465 | + } |
| 466 | + |
445 | 467 | // Close the command list and have it ready for dispatch.
|
446 | 468 | ZE2UR_CALL(zeCommandListClose, (CommandBuffer->ZeCommandList));
|
447 | 469 | return UR_RESULT_SUCCESS;
|
@@ -497,7 +519,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferAppendKernelLaunchExp(
|
497 | 519 | UR_CALL(getEventsFromSyncPoints(CommandBuffer, NumSyncPointsInWaitList,
|
498 | 520 | SyncPointWaitList, ZeEventList));
|
499 | 521 | ur_event_handle_t LaunchEvent;
|
500 |
| - UR_CALL(EventCreate(CommandBuffer->Context, nullptr, true, &LaunchEvent)); |
| 522 | + UR_CALL(EventCreate(CommandBuffer->Context, nullptr, false, &LaunchEvent)); |
501 | 523 | LaunchEvent->CommandType = UR_COMMAND_KERNEL_LAUNCH;
|
502 | 524 |
|
503 | 525 | // Get sync point and register the event with it.
|
@@ -727,7 +749,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferEnqueueExp(
|
727 | 749 | (WaitCommandList->first, CommandBuffer->WaitEvent->ZeEvent));
|
728 | 750 | }
|
729 | 751 |
|
730 |
| - // Execution event for this enqueue of the PI command-buffer |
| 752 | + // Execution event for this enqueue of the UR command-buffer |
731 | 753 | ur_event_handle_t RetEvent{};
|
732 | 754 | // Create a command-list to signal RetEvent on completion
|
733 | 755 | ur_command_list_ptr_t SignalCommandList{};
|
|
0 commit comments