Skip to content

Commit

Permalink
Merge pull request #2063 from nrspruit/refactor_l0_default_init
Browse files Browse the repository at this point in the history
[L0] Refactor to remove default constructor inits
  • Loading branch information
aarongreig authored Oct 17, 2024
2 parents 7739fc9 + 4854c2f commit cfada6f
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 79 deletions.
49 changes: 30 additions & 19 deletions source/adapters/level_zero/command_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,10 @@ ur_result_t createSyncPointAndGetZeEvents(
UR_CALL(getEventsFromSyncPoints(CommandBuffer, NumSyncPointsInWaitList,
SyncPointWaitList, ZeEventList));
ur_event_handle_t LaunchEvent;
UR_CALL(EventCreate(CommandBuffer->Context, nullptr, false, HostVisible,
&LaunchEvent, false, !CommandBuffer->IsProfilingEnabled));
UR_CALL(EventCreate(CommandBuffer->Context, nullptr /*Queue*/,
false /*IsMultiDevice*/, HostVisible, &LaunchEvent,
false /*CounterBasedEventEnabled*/,
!CommandBuffer->IsProfilingEnabled));
LaunchEvent->CommandType = CommandType;
ZeLaunchEvent = LaunchEvent->ZeEvent;

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

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

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

Expand Down Expand Up @@ -514,12 +520,15 @@ 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, 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));
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));
std::vector<ze_event_handle_t> PrecondEvents = {WaitEvent->ZeEvent,
AllResetEvent->ZeEvent};

Expand Down Expand Up @@ -1219,14 +1228,15 @@ 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, NumEventsInWaitList, EventWaitList,
false));
Queue, WaitCommandList, false /*UseCopyEngine*/, NumEventsInWaitList,
EventWaitList, false /*AllowBatching*/, nullptr /*ForcedCmdQueue*/));

ZE2UR_CALL(zeCommandListAppendBarrier,
(WaitCommandList->first, CommandBuffer->WaitEvent->ZeEvent,
CommandBuffer->WaitEvent->WaitList.Length,
CommandBuffer->WaitEvent->WaitList.ZeEventList));
Queue->executeCommandList(WaitCommandList, false, false);
Queue->executeCommandList(WaitCommandList, false /*IsBlocking*/,
false /*OKToBatchCommand*/);
MustSignalWaitEvent = false;
}
}
Expand Down Expand Up @@ -1338,9 +1348,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, NumEventsInWaitList,
EventWaitList, false));
UR_CALL(Queue->Context->getAvailableCommandList(
Queue, SignalCommandList, false /*UseCopyEngine*/, NumEventsInWaitList,
EventWaitList, false /*AllowBatching*/, nullptr /*ForcedCmdQueue*/));

// Reset the wait-event for the UR command-buffer that is signaled when its
// submission dependencies have been satisfied.
Expand All @@ -1355,7 +1365,8 @@ 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, false));
UR_CALL(Queue->executeCommandList(SignalCommandList, false /*IsBlocking*/,
false /*OKToBatchCommand*/));

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,
Queue->useCompletionBatching(), true /*CanReuse */,
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 = false,
ze_command_queue_handle_t *ForcedCmdQueue = nullptr);
const ur_event_handle_t *EventWaitList, bool AllowBatching,
ze_command_queue_handle_t *ForcedCmdQueue);

// 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: 27 additions & 13 deletions source/adapters/level_zero/event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ 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));
Queue, CommandList, UseCopyEngine, NumEventsInWaitList, EventWaitList,
false /*AllowBatching*/, nullptr /*ForceCmdQueue*/));

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

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

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

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

UR_CALL(Queue->executeCommandList(CmdList, false, OkToBatch));
UR_CALL(
Queue->executeCommandList(CmdList, false /*IsBlocking*/, 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 @@ -354,7 +357,7 @@ ur_result_t urEnqueueEventsWaitWithBarrier(
ur_command_list_ptr_t CmdList;
UR_CALL(Queue->Context->getAvailableCommandList(
Queue, CmdList, false /*UseCopyEngine=*/, NumEventsInWaitList,
EventWaitList, OkToBatch));
EventWaitList, OkToBatch, nullptr /*ForcedCmdQueue*/));
CmdLists.push_back(CmdList);
}

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

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

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

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

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

return UR_RESULT_SUCCESS;
}
Expand Down Expand Up @@ -816,7 +820,9 @@ 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));
CleanupCompletedEvent(reinterpret_cast<ur_event_handle_t>(Event),
false /*QueueLocked*/,
false /*SetEventCompleted*/);
// 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 @@ -884,7 +890,10 @@ ur_result_t urExtEventCreate(
ur_event_handle_t
*Event ///< [out] pointer to the handle of the event object created.
) {
UR_CALL(EventCreate(Context, nullptr, false, true, Event));
UR_CALL(EventCreate(Context, nullptr /*Queue*/, false /*IsMultiDevice*/,
true /*HostVisible*/, Event,
false /*CounterBasedEventEnabled*/,
false /*ForceDisableProfiling*/));

(*Event)->RefCountExternal++;
if (!(*Event)->CounterBasedEventsEnabled)
Expand All @@ -903,7 +912,10 @@ 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, false, true, Event));
UR_CALL(EventCreate(Context, nullptr /*Queue*/, false /*IsMultiDevice*/,
true /*HostVisible*/, Event,
false /*CounterBasedEventEnabled*/,
false /*ForceDisableProfiling*/));

(*Event)->RefCountExternal++;
if (!(*Event)->CounterBasedEventsEnabled)
Expand Down Expand Up @@ -983,7 +995,8 @@ 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))
UrQueue, CommandList, false /* UseCopyEngine */, 0, nullptr, OkToBatch,
nullptr /*ForcedCmdQueue*/))

// Create a "proxy" host-visible event.
UR_CALL(createEventAndAssociateQueue(
Expand Down Expand Up @@ -1529,7 +1542,8 @@ 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, 0, nullptr, true));
Queue, CommandList, false /*UseCopyEngine*/, 0, nullptr,
true /*AllowBatching*/, nullptr /*ForcedCmdQueue*/));
}

std::shared_lock<ur_shared_mutex> Lock(EventList[I]->Mutex);
Expand Down
9 changes: 4 additions & 5 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 = false,
bool ForceDisableProfiling = false);
bool CounterBasedEventEnabled,
bool ForceDisableProfiling);
} // extern "C"

// This is an experimental option that allows to disable caching of events in
Expand Down Expand Up @@ -273,9 +273,8 @@ 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 = false,
bool SetEventCompleted = false);
ur_result_t CleanupCompletedEvent(ur_event_handle_t Event, bool QueueLocked,
bool SetEventCompleted);

// 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));
OkToBatch, nullptr /*ForcedCmdQueue*/));

ze_event_handle_t ZeEvent = nullptr;
ur_event_handle_t InternalEvent;
Expand Down
10 changes: 6 additions & 4 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 */));
true /* AllowBatching */, nullptr /*ForcedCmdQueue*/));

ze_event_handle_t ZeEvent = nullptr;
ur_event_handle_t InternalEvent{};
Expand Down Expand Up @@ -202,7 +202,8 @@ 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, true));
UR_CALL(Queue->executeCommandList(CommandList, false /*IsBlocking*/,
true /*OKToBatchCommand*/));

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

ze_event_handle_t ZeEvent = nullptr;
ur_event_handle_t InternalEvent{};
Expand Down Expand Up @@ -467,7 +468,8 @@ 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, true));
UR_CALL(Queue->executeCommandList(CommandList, false /*IsBlocking*/,
true /*OKToBatchCommand*/));

return UR_RESULT_SUCCESS;
}
Expand Down
Loading

0 comments on commit cfada6f

Please sign in to comment.