Skip to content

Commit

Permalink
Merge pull request #2221 from oneapi-src/revert-2063-refactor_l0_defa…
Browse files Browse the repository at this point in the history
…ult_init

Revert "[L0] Refactor to remove default constructor inits"
  • Loading branch information
kbenzie authored Oct 18, 2024
2 parents f9d0641 + 26835f7 commit 3a8bf2c
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 124 deletions.
49 changes: 19 additions & 30 deletions source/adapters/level_zero/command_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,8 @@ ur_result_t createSyncPointAndGetZeEvents(
UR_CALL(getEventsFromSyncPoints(CommandBuffer, NumSyncPointsInWaitList,
SyncPointWaitList, ZeEventList));
ur_event_handle_t LaunchEvent;
UR_CALL(EventCreate(CommandBuffer->Context, nullptr /*Queue*/,
false /*IsMultiDevice*/, HostVisible, &LaunchEvent,
false /*CounterBasedEventEnabled*/,
!CommandBuffer->IsProfilingEnabled));
UR_CALL(EventCreate(CommandBuffer->Context, nullptr, false, HostVisible,
&LaunchEvent, false, !CommandBuffer->IsProfilingEnabled));
LaunchEvent->CommandType = CommandType;
ZeLaunchEvent = LaunchEvent->ZeEvent;

Expand Down Expand Up @@ -328,26 +326,22 @@ void ur_exp_command_buffer_handle_t_::cleanupCommandBufferResources() {

// Release additional signal and wait events used by command_buffer
if (SignalEvent) {
CleanupCompletedEvent(SignalEvent, false /*QueueLocked*/,
false /*SetEventCompleted*/);
CleanupCompletedEvent(SignalEvent, false);
urEventReleaseInternal(SignalEvent);
}
if (WaitEvent) {
CleanupCompletedEvent(WaitEvent, false /*QueueLocked*/,
false /*SetEventCompleted*/);
CleanupCompletedEvent(WaitEvent, false);
urEventReleaseInternal(WaitEvent);
}
if (AllResetEvent) {
CleanupCompletedEvent(AllResetEvent, false /*QueueLocked*/,
false /*SetEventCompleted*/);
CleanupCompletedEvent(AllResetEvent, false);
urEventReleaseInternal(AllResetEvent);
}

// Release events added to the command_buffer
for (auto &Sync : SyncPoints) {
auto &Event = Sync.second;
CleanupCompletedEvent(Event, false /*QueueLocked*/,
false /*SetEventCompleted*/);
CleanupCompletedEvent(Event, false);
urEventReleaseInternal(Event);
}

Expand Down Expand Up @@ -520,15 +514,12 @@ urCommandBufferCreateExp(ur_context_handle_t Context, ur_device_handle_t Device,
ur_event_handle_t WaitEvent;
ur_event_handle_t AllResetEvent;

UR_CALL(EventCreate(Context, nullptr /*Queue*/, false /*IsMultiDevice*/,
false /*HostVisible*/, &SignalEvent,
false /*CounterBasedEventEnabled*/, !EnableProfiling));
UR_CALL(EventCreate(Context, nullptr /*Queue*/, false /*IsMultiDevice*/,
false /*HostVisible*/, &WaitEvent,
false /*CounterBasedEventEnabled*/, !EnableProfiling));
UR_CALL(EventCreate(Context, nullptr /*Queue*/, false /*IsMultiDevice*/,
false /*HostVisible*/, &AllResetEvent,
false /*CounterBasedEventEnabled*/, !EnableProfiling));
UR_CALL(EventCreate(Context, nullptr, false, false, &SignalEvent, false,
!EnableProfiling));
UR_CALL(EventCreate(Context, nullptr, false, false, &WaitEvent, false,
!EnableProfiling));
UR_CALL(EventCreate(Context, nullptr, false, false, &AllResetEvent, false,
!EnableProfiling));
std::vector<ze_event_handle_t> PrecondEvents = {WaitEvent->ZeEvent,
AllResetEvent->ZeEvent};

Expand Down Expand Up @@ -1228,15 +1219,14 @@ ur_result_t waitForDependencies(ur_exp_command_buffer_handle_t CommandBuffer,
// when `EventWaitList` dependencies are complete.
ur_command_list_ptr_t WaitCommandList{};
UR_CALL(Queue->Context->getAvailableCommandList(
Queue, WaitCommandList, false /*UseCopyEngine*/, NumEventsInWaitList,
EventWaitList, false /*AllowBatching*/, nullptr /*ForcedCmdQueue*/));
Queue, WaitCommandList, false, NumEventsInWaitList, EventWaitList,
false));

ZE2UR_CALL(zeCommandListAppendBarrier,
(WaitCommandList->first, CommandBuffer->WaitEvent->ZeEvent,
CommandBuffer->WaitEvent->WaitList.Length,
CommandBuffer->WaitEvent->WaitList.ZeEventList));
Queue->executeCommandList(WaitCommandList, false /*IsBlocking*/,
false /*OKToBatchCommand*/);
Queue->executeCommandList(WaitCommandList, false, false);
MustSignalWaitEvent = false;
}
}
Expand Down Expand Up @@ -1348,9 +1338,9 @@ urCommandBufferEnqueueExp(ur_exp_command_buffer_handle_t CommandBuffer,

// Create a command-list to signal the Event on completion
ur_command_list_ptr_t SignalCommandList{};
UR_CALL(Queue->Context->getAvailableCommandList(
Queue, SignalCommandList, false /*UseCopyEngine*/, NumEventsInWaitList,
EventWaitList, false /*AllowBatching*/, nullptr /*ForcedCmdQueue*/));
UR_CALL(Queue->Context->getAvailableCommandList(Queue, SignalCommandList,
false, NumEventsInWaitList,
EventWaitList, false));

// Reset the wait-event for the UR command-buffer that is signaled when its
// submission dependencies have been satisfied.
Expand All @@ -1365,8 +1355,7 @@ urCommandBufferEnqueueExp(ur_exp_command_buffer_handle_t CommandBuffer,
// parameter with signal command-list completing.
UR_CALL(createUserEvent(CommandBuffer, Queue, SignalCommandList, Event));

UR_CALL(Queue->executeCommandList(SignalCommandList, false /*IsBlocking*/,
false /*OKToBatchCommand*/));
UR_CALL(Queue->executeCommandList(SignalCommandList, false, false));

return UR_RESULT_SUCCESS;
}
Expand Down
2 changes: 1 addition & 1 deletion source/adapters/level_zero/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ ur_result_t ur_context_handle_t_::getAvailableCommandList(
.emplace(ZeCommandList,
ur_command_list_info_t(
ZeFence, true, false, ZeCommandQueue, ZeQueueDesc,
Queue->useCompletionBatching(), true /*CanReuse */,
Queue->useCompletionBatching(), true,
ZeCommandListIt->second.InOrderList,
ZeCommandListIt->second.IsImmediate))
.first;
Expand Down
4 changes: 2 additions & 2 deletions source/adapters/level_zero/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,8 @@ struct ur_context_handle_t_ : _ur_object {
ur_result_t getAvailableCommandList(
ur_queue_handle_t Queue, ur_command_list_ptr_t &CommandList,
bool UseCopyEngine, uint32_t NumEventsInWaitList,
const ur_event_handle_t *EventWaitList, bool AllowBatching,
ze_command_queue_handle_t *ForcedCmdQueue);
const ur_event_handle_t *EventWaitList, bool AllowBatching = false,
ze_command_queue_handle_t *ForcedCmdQueue = nullptr);

// Checks if Device is covered by this context.
// For that the Device or its root devices need to be in the context.
Expand Down
40 changes: 13 additions & 27 deletions source/adapters/level_zero/event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ ur_result_t urEnqueueEventsWait(
// Get a new command list to be used on this call
ur_command_list_ptr_t CommandList{};
UR_CALL(Queue->Context->getAvailableCommandList(
Queue, CommandList, UseCopyEngine, NumEventsInWaitList, EventWaitList,
false /*AllowBatching*/, nullptr /*ForceCmdQueue*/));
Queue, CommandList, UseCopyEngine, NumEventsInWaitList, EventWaitList));

ze_event_handle_t ZeEvent = nullptr;
ur_event_handle_t InternalEvent;
Expand All @@ -110,8 +109,7 @@ ur_result_t urEnqueueEventsWait(

// Execute command list asynchronously as the event will be used
// to track down its completion.
return Queue->executeCommandList(CommandList, false /*IsBlocking*/,
false /*OKToBatchCommand*/);
return Queue->executeCommandList(CommandList);
}

{
Expand Down Expand Up @@ -281,14 +279,13 @@ ur_result_t urEnqueueEventsWaitWithBarrier(
ur_command_list_ptr_t CmdList;
UR_CALL(Queue->Context->getAvailableCommandList(
Queue, CmdList, false /*UseCopyEngine=*/, NumEventsInWaitList,
EventWaitList, OkToBatch, nullptr /*ForcedCmdQueue*/));
EventWaitList, OkToBatch));

// Insert the barrier into the command-list and execute.
UR_CALL(insertBarrierIntoCmdList(CmdList, TmpWaitList, ResultEvent,
IsInternal));

UR_CALL(
Queue->executeCommandList(CmdList, false /*IsBlocking*/, OkToBatch));
UR_CALL(Queue->executeCommandList(CmdList, false, OkToBatch));

// Because of the dependency between commands in the in-order queue we don't
// need to keep track of any active barriers if we have in-order queue.
Expand Down Expand Up @@ -357,7 +354,7 @@ ur_result_t urEnqueueEventsWaitWithBarrier(
ur_command_list_ptr_t CmdList;
UR_CALL(Queue->Context->getAvailableCommandList(
Queue, CmdList, false /*UseCopyEngine=*/, NumEventsInWaitList,
EventWaitList, OkToBatch, nullptr /*ForcedCmdQueue*/));
EventWaitList, OkToBatch));
CmdLists.push_back(CmdList);
}

Expand Down Expand Up @@ -407,8 +404,7 @@ ur_result_t urEnqueueEventsWaitWithBarrier(
// Only batch if the matching CmdList is already open.
OkToBatch = CommandBatch.OpenCommandList == CmdList;

UR_CALL(
Queue->executeCommandList(CmdList, false /*IsBlocking*/, OkToBatch));
UR_CALL(Queue->executeCommandList(CmdList, false, OkToBatch));
}

UR_CALL(Queue->ActiveBarriers.clear());
Expand Down Expand Up @@ -720,7 +716,7 @@ ur_result_t urEnqueueTimestampRecordingExp(
ur_command_list_ptr_t CommandList{};
UR_CALL(Queue->Context->getAvailableCommandList(
Queue, CommandList, UseCopyEngine, NumEventsInWaitList, EventWaitList,
/* AllowBatching */ false, nullptr /*ForcedCmdQueue*/));
/* AllowBatching */ false));

UR_CALL(createEventAndAssociateQueue(
Queue, OutEvent, UR_COMMAND_TIMESTAMP_RECORDING_EXP, CommandList,
Expand All @@ -744,7 +740,7 @@ ur_result_t urEnqueueTimestampRecordingExp(
(*OutEvent)->WaitList.ZeEventList));

UR_CALL(
Queue->executeCommandList(CommandList, Blocking, false /* OkToBatch */));
Queue->executeCommandList(CommandList, Blocking, /* OkToBatch */ false));

return UR_RESULT_SUCCESS;
}
Expand Down Expand Up @@ -820,9 +816,7 @@ urEventWait(uint32_t NumEvents, ///< [in] number of events in the event list
else {
// NOTE: we are cleaning up after the event here to free resources
// sooner in case run-time is not calling urEventRelease soon enough.
CleanupCompletedEvent(reinterpret_cast<ur_event_handle_t>(Event),
false /*QueueLocked*/,
false /*SetEventCompleted*/);
CleanupCompletedEvent(reinterpret_cast<ur_event_handle_t>(Event));
// For the case when we have out-of-order queue or regular command
// lists its more efficient to check fences so put the queue in the
// set to cleanup later.
Expand Down Expand Up @@ -890,10 +884,7 @@ ur_result_t urExtEventCreate(
ur_event_handle_t
*Event ///< [out] pointer to the handle of the event object created.
) {
UR_CALL(EventCreate(Context, nullptr /*Queue*/, false /*IsMultiDevice*/,
true /*HostVisible*/, Event,
false /*CounterBasedEventEnabled*/,
false /*ForceDisableProfiling*/));
UR_CALL(EventCreate(Context, nullptr, false, true, Event));

(*Event)->RefCountExternal++;
if (!(*Event)->CounterBasedEventsEnabled)
Expand All @@ -912,10 +903,7 @@ ur_result_t urEventCreateWithNativeHandle(
// we dont have urEventCreate, so use this check for now to know that
// the call comes from urEventCreate()
if (reinterpret_cast<ze_event_handle_t>(NativeEvent) == nullptr) {
UR_CALL(EventCreate(Context, nullptr /*Queue*/, false /*IsMultiDevice*/,
true /*HostVisible*/, Event,
false /*CounterBasedEventEnabled*/,
false /*ForceDisableProfiling*/));
UR_CALL(EventCreate(Context, nullptr, false, true, Event));

(*Event)->RefCountExternal++;
if (!(*Event)->CounterBasedEventsEnabled)
Expand Down Expand Up @@ -995,8 +983,7 @@ ur_result_t ur_event_handle_t_::getOrCreateHostVisibleEvent(

ur_command_list_ptr_t CommandList{};
UR_CALL(UrQueue->Context->getAvailableCommandList(
UrQueue, CommandList, false /* UseCopyEngine */, 0, nullptr, OkToBatch,
nullptr /*ForcedCmdQueue*/))
UrQueue, CommandList, false /* UseCopyEngine */, 0, nullptr, OkToBatch))

// Create a "proxy" host-visible event.
UR_CALL(createEventAndAssociateQueue(
Expand Down Expand Up @@ -1542,8 +1529,7 @@ ur_result_t _ur_ze_event_list_t::createAndRetainUrZeEventList(
// This prevents a potential deadlock with recursive
// event locks.
UR_CALL(Queue->Context->getAvailableCommandList(
Queue, CommandList, false /*UseCopyEngine*/, 0, nullptr,
true /*AllowBatching*/, nullptr /*ForcedCmdQueue*/));
Queue, CommandList, false, 0, nullptr, true));
}

std::shared_lock<ur_shared_mutex> Lock(EventList[I]->Mutex);
Expand Down
9 changes: 5 additions & 4 deletions source/adapters/level_zero/event.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ ur_result_t urEventReleaseInternal(ur_event_handle_t Event);
ur_result_t EventCreate(ur_context_handle_t Context, ur_queue_handle_t Queue,
bool IsMultiDevice, bool HostVisible,
ur_event_handle_t *RetEvent,
bool CounterBasedEventEnabled,
bool ForceDisableProfiling);
bool CounterBasedEventEnabled = false,
bool ForceDisableProfiling = false);
} // extern "C"

// This is an experimental option that allows to disable caching of events in
Expand Down Expand Up @@ -273,8 +273,9 @@ template <> ze_result_t zeHostSynchronize(ze_command_queue_handle_t Handle);
// the event, updates the last command event in the queue and cleans up all dep
// events of the event.
// If the caller locks queue mutex then it must pass 'true' to QueueLocked.
ur_result_t CleanupCompletedEvent(ur_event_handle_t Event, bool QueueLocked,
bool SetEventCompleted);
ur_result_t CleanupCompletedEvent(ur_event_handle_t Event,
bool QueueLocked = false,
bool SetEventCompleted = false);

// Get value of device scope events env var setting or default setting
static const EventsScope DeviceEventsSetting = [] {
Expand Down
2 changes: 1 addition & 1 deletion source/adapters/level_zero/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,7 @@ ur_result_t urBindlessImagesImageCopyExp(
ur_command_list_ptr_t CommandList{};
UR_CALL(hQueue->Context->getAvailableCommandList(
hQueue, CommandList, UseCopyEngine, numEventsInWaitList, phEventWaitList,
OkToBatch, nullptr /*ForcedCmdQueue*/));
OkToBatch));

ze_event_handle_t ZeEvent = nullptr;
ur_event_handle_t InternalEvent;
Expand Down
10 changes: 4 additions & 6 deletions source/adapters/level_zero/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ ur_result_t urEnqueueKernelLaunch(
ur_command_list_ptr_t CommandList{};
UR_CALL(Queue->Context->getAvailableCommandList(
Queue, CommandList, UseCopyEngine, NumEventsInWaitList, EventWaitList,
true /* AllowBatching */, nullptr /*ForcedCmdQueue*/));
true /* AllowBatching */));

ze_event_handle_t ZeEvent = nullptr;
ur_event_handle_t InternalEvent{};
Expand Down Expand Up @@ -202,8 +202,7 @@ ur_result_t urEnqueueKernelLaunch(

// Execute command list asynchronously, as the event will be used
// to track down its completion.
UR_CALL(Queue->executeCommandList(CommandList, false /*IsBlocking*/,
true /*OKToBatchCommand*/));
UR_CALL(Queue->executeCommandList(CommandList, false, true));

return UR_RESULT_SUCCESS;
}
Expand Down Expand Up @@ -405,7 +404,7 @@ ur_result_t urEnqueueCooperativeKernelLaunchExp(
ur_command_list_ptr_t CommandList{};
UR_CALL(Queue->Context->getAvailableCommandList(
Queue, CommandList, UseCopyEngine, NumEventsInWaitList, EventWaitList,
true /* AllowBatching */, nullptr /*ForcedCmdQueue*/));
true /* AllowBatching */));

ze_event_handle_t ZeEvent = nullptr;
ur_event_handle_t InternalEvent{};
Expand Down Expand Up @@ -468,8 +467,7 @@ ur_result_t urEnqueueCooperativeKernelLaunchExp(

// Execute command list asynchronously, as the event will be used
// to track down its completion.
UR_CALL(Queue->executeCommandList(CommandList, false /*IsBlocking*/,
true /*OKToBatchCommand*/));
UR_CALL(Queue->executeCommandList(CommandList, false, true));

return UR_RESULT_SUCCESS;
}
Expand Down
Loading

0 comments on commit 3a8bf2c

Please sign in to comment.