Skip to content

Commit 685973d

Browse files
committed
[L0] Refactor to remove default constructor inits
- Remove all the default constructor inits to address error prone code changes and force setting of options and flags individually. Signed-off-by: Neil R. Spruit <[email protected]>
1 parent d50a59e commit 685973d

File tree

10 files changed

+130
-82
lines changed

10 files changed

+130
-82
lines changed

source/adapters/level_zero/command_buffer.cpp

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,10 @@ ur_result_t createSyncPointAndGetZeEvents(
146146
UR_CALL(getEventsFromSyncPoints(CommandBuffer, NumSyncPointsInWaitList,
147147
SyncPointWaitList, ZeEventList));
148148
ur_event_handle_t LaunchEvent;
149-
UR_CALL(EventCreate(CommandBuffer->Context, nullptr, false, HostVisible,
150-
&LaunchEvent, false, !CommandBuffer->IsProfilingEnabled));
149+
UR_CALL(EventCreate(CommandBuffer->Context, nullptr /*Queue*/,
150+
false /*IsMultiDevice*/, HostVisible, &LaunchEvent,
151+
false /*CounterBasedEventEnabled*/,
152+
!CommandBuffer->IsProfilingEnabled));
151153
LaunchEvent->CommandType = CommandType;
152154
ZeLaunchEvent = LaunchEvent->ZeEvent;
153155

@@ -325,22 +327,26 @@ void ur_exp_command_buffer_handle_t_::cleanupCommandBufferResources() {
325327

326328
// Release additional signal and wait events used by command_buffer
327329
if (SignalEvent) {
328-
CleanupCompletedEvent(SignalEvent, false);
330+
CleanupCompletedEvent(SignalEvent, false /*QueueLocked*/,
331+
false /*SetEventCompleted*/);
329332
urEventReleaseInternal(SignalEvent);
330333
}
331334
if (WaitEvent) {
332-
CleanupCompletedEvent(WaitEvent, false);
335+
CleanupCompletedEvent(WaitEvent, false /*QueueLocked*/,
336+
false /*SetEventCompleted*/);
333337
urEventReleaseInternal(WaitEvent);
334338
}
335339
if (AllResetEvent) {
336-
CleanupCompletedEvent(AllResetEvent, false);
340+
CleanupCompletedEvent(AllResetEvent, false /*QueueLocked*/,
341+
false /*SetEventCompleted*/);
337342
urEventReleaseInternal(AllResetEvent);
338343
}
339344

340345
// Release events added to the command_buffer
341346
for (auto &Sync : SyncPoints) {
342347
auto &Event = Sync.second;
343-
CleanupCompletedEvent(Event, false);
348+
CleanupCompletedEvent(Event, false /*QueueLocked*/,
349+
false /*SetEventCompleted*/);
344350
urEventReleaseInternal(Event);
345351
}
346352

@@ -514,12 +520,15 @@ urCommandBufferCreateExp(ur_context_handle_t Context, ur_device_handle_t Device,
514520
ur_event_handle_t WaitEvent;
515521
ur_event_handle_t AllResetEvent;
516522

517-
UR_CALL(EventCreate(Context, nullptr, false, false, &SignalEvent, false,
518-
!EnableProfiling));
519-
UR_CALL(EventCreate(Context, nullptr, false, false, &WaitEvent, false,
520-
!EnableProfiling));
521-
UR_CALL(EventCreate(Context, nullptr, false, false, &AllResetEvent, false,
522-
!EnableProfiling));
523+
UR_CALL(EventCreate(Context, nullptr /*Queue*/, false /*IsMultiDevice*/,
524+
false /*HostVisible*/, &SignalEvent,
525+
false /*CounterBasedEventEnabled*/, !EnableProfiling));
526+
UR_CALL(EventCreate(Context, nullptr /*Queue*/, false /*IsMultiDevice*/,
527+
false /*HostVisible*/, &WaitEvent,
528+
false /*CounterBasedEventEnabled*/, !EnableProfiling));
529+
UR_CALL(EventCreate(Context, nullptr /*Queue*/, false /*IsMultiDevice*/,
530+
false /*HostVisible*/, &AllResetEvent,
531+
false /*CounterBasedEventEnabled*/, !EnableProfiling));
523532
std::vector<ze_event_handle_t> PrecondEvents = {WaitEvent->ZeEvent,
524533
AllResetEvent->ZeEvent};
525534

@@ -1151,14 +1160,15 @@ ur_result_t waitForDependencies(ur_exp_command_buffer_handle_t CommandBuffer,
11511160
// when `EventWaitList` dependencies are complete.
11521161
ur_command_list_ptr_t WaitCommandList{};
11531162
UR_CALL(Queue->Context->getAvailableCommandList(
1154-
Queue, WaitCommandList, false, NumEventsInWaitList, EventWaitList,
1155-
false));
1163+
Queue, WaitCommandList, false /*UseCopyEngine*/, NumEventsInWaitList,
1164+
EventWaitList, false /*AllowBatching*/, nullptr /*ForcedCmdQueue*/));
11561165

11571166
ZE2UR_CALL(zeCommandListAppendBarrier,
11581167
(WaitCommandList->first, CommandBuffer->WaitEvent->ZeEvent,
11591168
CommandBuffer->WaitEvent->WaitList.Length,
11601169
CommandBuffer->WaitEvent->WaitList.ZeEventList));
1161-
Queue->executeCommandList(WaitCommandList, false, false);
1170+
Queue->executeCommandList(WaitCommandList, false /*IsBlocking*/,
1171+
false /*OKToBatchCommand*/);
11621172
MustSignalWaitEvent = false;
11631173
}
11641174
}
@@ -1270,9 +1280,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferEnqueueExp(
12701280

12711281
// Create a command-list to signal the Event on completion
12721282
ur_command_list_ptr_t SignalCommandList{};
1273-
UR_CALL(Queue->Context->getAvailableCommandList(Queue, SignalCommandList,
1274-
false, NumEventsInWaitList,
1275-
EventWaitList, false));
1283+
UR_CALL(Queue->Context->getAvailableCommandList(
1284+
Queue, SignalCommandList, false /*UseCopyEngine*/, NumEventsInWaitList,
1285+
EventWaitList, false /*AllowBatching*/, nullptr /*ForcedCmdQueue*/));
12761286

12771287
// Reset the wait-event for the UR command-buffer that is signaled when its
12781288
// submission dependencies have been satisfied.
@@ -1287,7 +1297,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferEnqueueExp(
12871297
// parameter with signal command-list completing.
12881298
UR_CALL(createUserEvent(CommandBuffer, Queue, SignalCommandList, Event));
12891299

1290-
UR_CALL(Queue->executeCommandList(SignalCommandList, false, false));
1300+
UR_CALL(Queue->executeCommandList(SignalCommandList, false /*IsBlocking*/,
1301+
false /*OKToBatchCommand*/));
12911302

12921303
return UR_RESULT_SUCCESS;
12931304
}

source/adapters/level_zero/context.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -767,9 +767,11 @@ ur_result_t ur_context_handle_t_::getAvailableCommandList(
767767
CommandList =
768768
Queue->CommandListMap
769769
.emplace(ZeCommandList,
770-
ur_command_list_info_t(ZeFence, true, false,
771-
ZeCommandQueue, ZeQueueDesc,
772-
Queue->useCompletionBatching()))
770+
ur_command_list_info_t(
771+
ZeFence, true, false, ZeCommandQueue, ZeQueueDesc,
772+
Queue->useCompletionBatching(), true /*CanReuse */,
773+
ZeCommandListIt->second.InOrderList,
774+
ZeCommandListIt->second.IsImmediate))
773775
.first;
774776
}
775777
ZeCommandListCache.erase(ZeCommandListIt);

source/adapters/level_zero/context.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,8 @@ struct ur_context_handle_t_ : _ur_object {
299299
ur_result_t getAvailableCommandList(
300300
ur_queue_handle_t Queue, ur_command_list_ptr_t &CommandList,
301301
bool UseCopyEngine, uint32_t NumEventsInWaitList,
302-
const ur_event_handle_t *EventWaitList, bool AllowBatching = false,
303-
ze_command_queue_handle_t *ForcedCmdQueue = nullptr);
302+
const ur_event_handle_t *EventWaitList, bool AllowBatching,
303+
ze_command_queue_handle_t *ForcedCmdQueue);
304304

305305
// Checks if Device is covered by this context.
306306
// For that the Device or its root devices need to be in the context.

source/adapters/level_zero/event.cpp

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueEventsWait(
8585
// Get a new command list to be used on this call
8686
ur_command_list_ptr_t CommandList{};
8787
UR_CALL(Queue->Context->getAvailableCommandList(
88-
Queue, CommandList, UseCopyEngine, NumEventsInWaitList, EventWaitList));
88+
Queue, CommandList, UseCopyEngine, NumEventsInWaitList, EventWaitList,
89+
false /*AllowBatching*/, nullptr /*ForceCmdQueue*/));
8990

9091
ze_event_handle_t ZeEvent = nullptr;
9192
ur_event_handle_t InternalEvent;
@@ -106,7 +107,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueEventsWait(
106107

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

112114
{
@@ -258,12 +260,13 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueEventsWaitWithBarrier(
258260
ur_command_list_ptr_t CmdList;
259261
UR_CALL(Queue->Context->getAvailableCommandList(
260262
Queue, CmdList, false /*UseCopyEngine=*/, NumEventsInWaitList,
261-
EventWaitList, OkToBatch));
263+
EventWaitList, OkToBatch, nullptr /*ForcedCmdQueue*/));
262264

263265
// Insert the barrier into the command-list and execute.
264266
UR_CALL(insertBarrierIntoCmdList(CmdList, TmpWaitList, *Event, IsInternal));
265267

266-
UR_CALL(Queue->executeCommandList(CmdList, false, OkToBatch));
268+
UR_CALL(
269+
Queue->executeCommandList(CmdList, false /*IsBlocking*/, OkToBatch));
267270

268271
// Because of the dependency between commands in the in-order queue we don't
269272
// need to keep track of any active barriers if we have in-order queue.
@@ -328,7 +331,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueEventsWaitWithBarrier(
328331
ur_command_list_ptr_t CmdList;
329332
UR_CALL(Queue->Context->getAvailableCommandList(
330333
Queue, CmdList, false /*UseCopyEngine=*/, NumEventsInWaitList,
331-
EventWaitList, OkToBatch));
334+
EventWaitList, OkToBatch, nullptr /*ForcedCmdQueue*/));
332335
CmdLists.push_back(CmdList);
333336
}
334337

@@ -377,7 +380,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueEventsWaitWithBarrier(
377380
// Only batch if the matching CmdList is already open.
378381
OkToBatch = CommandBatch.OpenCommandList == CmdList;
379382

380-
UR_CALL(Queue->executeCommandList(CmdList, false, OkToBatch));
383+
UR_CALL(
384+
Queue->executeCommandList(CmdList, false /*IsBlocking*/, OkToBatch));
381385
}
382386

383387
UR_CALL(Queue->ActiveBarriers.clear());
@@ -687,7 +691,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueTimestampRecordingExp(
687691
ur_command_list_ptr_t CommandList{};
688692
UR_CALL(Queue->Context->getAvailableCommandList(
689693
Queue, CommandList, UseCopyEngine, NumEventsInWaitList, EventWaitList,
690-
/* AllowBatching */ false));
694+
/* AllowBatching */ false, nullptr /*ForcedCmdQueue*/));
691695

692696
UR_CALL(createEventAndAssociateQueue(
693697
Queue, OutEvent, UR_COMMAND_TIMESTAMP_RECORDING_EXP, CommandList,
@@ -710,7 +714,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueTimestampRecordingExp(
710714
(*OutEvent)->WaitList.ZeEventList));
711715

712716
UR_CALL(
713-
Queue->executeCommandList(CommandList, Blocking, /* OkToBatch */ false));
717+
Queue->executeCommandList(CommandList, Blocking, false /* OkToBatch */));
714718

715719
return UR_RESULT_SUCCESS;
716720
}
@@ -738,7 +742,8 @@ ur_result_t ur_event_handle_t_::getOrCreateHostVisibleEvent(
738742

739743
ur_command_list_ptr_t CommandList{};
740744
UR_CALL(UrQueue->Context->getAvailableCommandList(
741-
UrQueue, CommandList, false /* UseCopyEngine */, 0, nullptr, OkToBatch))
745+
UrQueue, CommandList, false /* UseCopyEngine */, 0, nullptr, OkToBatch,
746+
nullptr /*ForcedCmdQueue*/))
742747

743748
// Create a "proxy" host-visible event.
744749
UR_CALL(createEventAndAssociateQueue(
@@ -756,7 +761,8 @@ ur_result_t ur_event_handle_t_::getOrCreateHostVisibleEvent(
756761
ZE2UR_CALL(zeCommandListAppendSignalEvent,
757762
(CommandList->first, HostVisibleEvent->ZeEvent));
758763

759-
UR_CALL(UrQueue->executeCommandList(CommandList, false, OkToBatch))
764+
UR_CALL(UrQueue->executeCommandList(CommandList, false /*IsBlocking*/,
765+
OkToBatch))
760766
this->IsCreatingHostProxyEvent = false;
761767
}
762768

@@ -835,7 +841,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urEventWait(
835841
else {
836842
// NOTE: we are cleaning up after the event here to free resources
837843
// sooner in case run-time is not calling urEventRelease soon enough.
838-
CleanupCompletedEvent(reinterpret_cast<ur_event_handle_t>(Event));
844+
CleanupCompletedEvent(reinterpret_cast<ur_event_handle_t>(Event),
845+
false /*QueueLocked*/,
846+
false /*SetEventCompleted*/);
839847
// For the case when we have out-of-order queue or regular command
840848
// lists its more efficient to check fences so put the queue in the
841849
// set to cleanup later.
@@ -903,7 +911,10 @@ UR_APIEXPORT ur_result_t UR_APICALL urExtEventCreate(
903911
ur_event_handle_t
904912
*Event ///< [out] pointer to the handle of the event object created.
905913
) {
906-
UR_CALL(EventCreate(Context, nullptr, false, true, Event));
914+
UR_CALL(EventCreate(Context, nullptr /*Queue*/, false /*IsMultiDevice*/,
915+
true /*HostVisible*/, Event,
916+
false /*CounterBasedEventEnabled*/,
917+
false /*ForceDisableProfiling*/));
907918

908919
(*Event)->RefCountExternal++;
909920
if (!(*Event)->CounterBasedEventsEnabled)
@@ -922,7 +933,10 @@ UR_APIEXPORT ur_result_t UR_APICALL urEventCreateWithNativeHandle(
922933
// we dont have urEventCreate, so use this check for now to know that
923934
// the call comes from urEventCreate()
924935
if (reinterpret_cast<ze_event_handle_t>(NativeEvent) == nullptr) {
925-
UR_CALL(EventCreate(Context, nullptr, false, true, Event));
936+
UR_CALL(EventCreate(Context, nullptr /*Queue*/, false /*IsMultiDevice*/,
937+
true /*HostVisible*/, Event,
938+
false /*CounterBasedEventEnabled*/,
939+
false /*ForceDisableProfiling*/));
926940

927941
(*Event)->RefCountExternal++;
928942
if (!(*Event)->CounterBasedEventsEnabled)
@@ -1497,7 +1511,8 @@ ur_result_t _ur_ze_event_list_t::createAndRetainUrZeEventList(
14971511
// This prevents a potential deadlock with recursive
14981512
// event locks.
14991513
UR_CALL(Queue->Context->getAvailableCommandList(
1500-
Queue, CommandList, false, 0, nullptr, true));
1514+
Queue, CommandList, false /*UseCopyEngine*/, 0, nullptr,
1515+
true /*AllowBatching*/, nullptr /*ForcedCmdQueue*/));
15011516
}
15021517

15031518
std::shared_lock<ur_shared_mutex> Lock(EventList[I]->Mutex);

source/adapters/level_zero/event.hpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ ur_result_t urEventReleaseInternal(ur_event_handle_t Event);
3232
ur_result_t EventCreate(ur_context_handle_t Context, ur_queue_handle_t Queue,
3333
bool IsMultiDevice, bool HostVisible,
3434
ur_event_handle_t *RetEvent,
35-
bool CounterBasedEventEnabled = false,
36-
bool ForceDisableProfiling = false);
35+
bool CounterBasedEventEnabled,
36+
bool ForceDisableProfiling);
3737
} // extern "C"
3838

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

280279
// Get value of device scope events env var setting or default setting
281280
static const EventsScope DeviceEventsSetting = [] {

source/adapters/level_zero/image.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urBindlessImagesImageCopyExp(
801801
ur_command_list_ptr_t CommandList{};
802802
UR_CALL(hQueue->Context->getAvailableCommandList(
803803
hQueue, CommandList, UseCopyEngine, numEventsInWaitList, phEventWaitList,
804-
OkToBatch));
804+
OkToBatch, nullptr /*ForcedCmdQueue*/));
805805

806806
ze_event_handle_t ZeEvent = nullptr;
807807
ur_event_handle_t InternalEvent;

source/adapters/level_zero/kernel.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueKernelLaunch(
136136
ur_command_list_ptr_t CommandList{};
137137
UR_CALL(Queue->Context->getAvailableCommandList(
138138
Queue, CommandList, UseCopyEngine, NumEventsInWaitList, EventWaitList,
139-
true /* AllowBatching */));
139+
true /* AllowBatching */, nullptr /*ForcedCmdQueue*/));
140140

141141
ze_event_handle_t ZeEvent = nullptr;
142142
ur_event_handle_t InternalEvent{};
@@ -199,7 +199,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueKernelLaunch(
199199

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

204205
return UR_RESULT_SUCCESS;
205206
}
@@ -400,7 +401,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueCooperativeKernelLaunchExp(
400401
ur_command_list_ptr_t CommandList{};
401402
UR_CALL(Queue->Context->getAvailableCommandList(
402403
Queue, CommandList, UseCopyEngine, NumEventsInWaitList, EventWaitList,
403-
true /* AllowBatching */));
404+
true /* AllowBatching */, nullptr /*ForcedCmdQueue*/));
404405

405406
ze_event_handle_t ZeEvent = nullptr;
406407
ur_event_handle_t InternalEvent{};
@@ -463,7 +464,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueCooperativeKernelLaunchExp(
463464

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

468470
return UR_RESULT_SUCCESS;
469471
}

0 commit comments

Comments
 (0)