Skip to content

Commit b96c05a

Browse files
committed
Fix bug where appendingProfilingQueries was dereferencing nullptr
1 parent 64e8089 commit b96c05a

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

source/adapters/level_zero/command_buffer.cpp

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1535,15 +1535,17 @@ ur_result_t waitForDependencies(ur_exp_command_buffer_handle_t CommandBuffer,
15351535
* @param CommandList The command-list to append the QueryKernelTimestamps
15361536
* command to.
15371537
* @param SignalEvent The event that must be signaled after the profiling is
1538-
* finished. This event will contain the profiling information.
1538+
* finished.
15391539
* @param WaitEvent The event that must be waited on before starting the
15401540
* profiling.
1541+
* @param ProfilingEvent The event that will contain the profiling data.
15411542
* @return UR_RESULT_SUCCESS or an error code on failure.
15421543
*/
15431544
ur_result_t appendProfilingQueries(ur_exp_command_buffer_handle_t CommandBuffer,
15441545
ze_command_list_handle_t CommandList,
15451546
ur_event_handle_t SignalEvent,
1546-
ur_event_handle_t WaitEvent) {
1547+
ur_event_handle_t WaitEvent,
1548+
ur_event_handle_t ProfilingEvent) {
15471549
// Multiple submissions of a command buffer implies that we need to save
15481550
// the event timestamps before resubmiting the command buffer. We
15491551
// therefore copy these timestamps in a dedicated USM memory section
@@ -1556,12 +1558,17 @@ ur_result_t appendProfilingQueries(ur_exp_command_buffer_handle_t CommandBuffer,
15561558
Profiling->Timestamps =
15571559
new ze_kernel_timestamp_result_t[Profiling->NumEvents];
15581560

1561+
uint32_t NumWaitEvents = WaitEvent ? 1 : 0;
1562+
ze_event_handle_t *ZeWaitEventList =
1563+
WaitEvent ? &(WaitEvent->ZeEvent) : nullptr;
1564+
ze_event_handle_t ZeSignalEvent =
1565+
SignalEvent ? SignalEvent->ZeEvent : nullptr;
15591566
ZE2UR_CALL(zeCommandListAppendQueryKernelTimestamps,
15601567
(CommandList, CommandBuffer->ZeEventsList.size(),
15611568
CommandBuffer->ZeEventsList.data(), (void *)Profiling->Timestamps,
1562-
0, SignalEvent->ZeEvent, 1, &(WaitEvent->ZeEvent)));
1569+
0, ZeSignalEvent, NumWaitEvents, ZeWaitEventList));
15631570

1564-
SignalEvent->CommandData = static_cast<void *>(Profiling);
1571+
ProfilingEvent->CommandData = static_cast<void *>(Profiling);
15651572

15661573
return UR_RESULT_SUCCESS;
15671574
}
@@ -1615,7 +1622,7 @@ ur_result_t enqueueImmediateAppendPath(
16151622

16161623
if (DoProfiling) {
16171624
UR_CALL(appendProfilingQueries(CommandBuffer, CommandListHelper->first,
1618-
*Event,
1625+
*Event, CommandBuffer->ComputeFinishedEvent,
16191626
CommandBuffer->ComputeFinishedEvent));
16201627
}
16211628

@@ -1705,14 +1712,12 @@ ur_result_t enqueueWaitEventPath(ur_exp_command_buffer_handle_t CommandBuffer,
17051712

17061713
if (DoProfiling) {
17071714
UR_CALL(appendProfilingQueries(CommandBuffer, SignalCommandList->first,
1708-
*Event,
1709-
CommandBuffer->ExecutionFinishedEvent));
1710-
} else {
1711-
ZE2UR_CALL(zeCommandListAppendBarrier,
1712-
(SignalCommandList->first, (*Event)->ZeEvent, 1,
1713-
&(CommandBuffer->ExecutionFinishedEvent->ZeEvent)));
1715+
nullptr, nullptr, *Event));
17141716
}
17151717

1718+
ZE2UR_CALL(zeCommandListAppendBarrier,
1719+
(SignalCommandList->first, (*Event)->ZeEvent, 0, nullptr));
1720+
17161721
UR_CALL(Queue->executeCommandList(SignalCommandList, false /*IsBlocking*/,
17171722
false /*OKToBatchCommand*/));
17181723

0 commit comments

Comments
 (0)