Skip to content

Commit 9b43a4c

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 eb63d1a commit 9b43a4c

File tree

10 files changed

+124
-79
lines changed

10 files changed

+124
-79
lines changed

source/adapters/level_zero/command_buffer.cpp

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

@@ -326,22 +328,26 @@ void ur_exp_command_buffer_handle_t_::cleanupCommandBufferResources() {
326328

327329
// Release additional signal and wait events used by command_buffer
328330
if (SignalEvent) {
329-
CleanupCompletedEvent(SignalEvent, false);
331+
CleanupCompletedEvent(SignalEvent, false /*QueueLocked*/,
332+
false /*SetEventCompleted*/);
330333
urEventReleaseInternal(SignalEvent);
331334
}
332335
if (WaitEvent) {
333-
CleanupCompletedEvent(WaitEvent, false);
336+
CleanupCompletedEvent(WaitEvent, false /*QueueLocked*/,
337+
false /*SetEventCompleted*/);
334338
urEventReleaseInternal(WaitEvent);
335339
}
336340
if (AllResetEvent) {
337-
CleanupCompletedEvent(AllResetEvent, false);
341+
CleanupCompletedEvent(AllResetEvent, false /*QueueLocked*/,
342+
false /*SetEventCompleted*/);
338343
urEventReleaseInternal(AllResetEvent);
339344
}
340345

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

@@ -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

@@ -1146,14 +1155,15 @@ ur_result_t waitForDependencies(ur_exp_command_buffer_handle_t CommandBuffer,
11461155
// when `EventWaitList` dependencies are complete.
11471156
ur_command_list_ptr_t WaitCommandList{};
11481157
UR_CALL(Queue->Context->getAvailableCommandList(
1149-
Queue, WaitCommandList, false, NumEventsInWaitList, EventWaitList,
1150-
false));
1158+
Queue, WaitCommandList, false /*UseCopyEngine*/, NumEventsInWaitList,
1159+
EventWaitList, false /*AllowBatching*/, nullptr /*ForcedCmdQueue*/));
11511160

11521161
ZE2UR_CALL(zeCommandListAppendBarrier,
11531162
(WaitCommandList->first, CommandBuffer->WaitEvent->ZeEvent,
11541163
CommandBuffer->WaitEvent->WaitList.Length,
11551164
CommandBuffer->WaitEvent->WaitList.ZeEventList));
1156-
Queue->executeCommandList(WaitCommandList, false, false);
1165+
Queue->executeCommandList(WaitCommandList, false /*IsBlocking*/,
1166+
false /*OKToBatchCommand*/);
11571167
MustSignalWaitEvent = false;
11581168
}
11591169
}
@@ -1265,9 +1275,9 @@ urCommandBufferEnqueueExp(ur_exp_command_buffer_handle_t CommandBuffer,
12651275

12661276
// Create a command-list to signal the Event on completion
12671277
ur_command_list_ptr_t SignalCommandList{};
1268-
UR_CALL(Queue->Context->getAvailableCommandList(Queue, SignalCommandList,
1269-
false, NumEventsInWaitList,
1270-
EventWaitList, false));
1278+
UR_CALL(Queue->Context->getAvailableCommandList(
1279+
Queue, SignalCommandList, false /*UseCopyEngine*/, NumEventsInWaitList,
1280+
EventWaitList, false /*AllowBatching*/, nullptr /*ForcedCmdQueue*/));
12711281

12721282
// Reset the wait-event for the UR command-buffer that is signaled when its
12731283
// submission dependencies have been satisfied.
@@ -1282,7 +1292,8 @@ urCommandBufferEnqueueExp(ur_exp_command_buffer_handle_t CommandBuffer,
12821292
// parameter with signal command-list completing.
12831293
UR_CALL(createUserEvent(CommandBuffer, Queue, SignalCommandList, Event));
12841294

1285-
UR_CALL(Queue->executeCommandList(SignalCommandList, false, false));
1295+
UR_CALL(Queue->executeCommandList(SignalCommandList, false /*IsBlocking*/,
1296+
false /*OKToBatchCommand*/));
12861297

12871298
return UR_RESULT_SUCCESS;
12881299
}

source/adapters/level_zero/context.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,7 @@ ur_result_t ur_context_handle_t_::getAvailableCommandList(
772772
.emplace(ZeCommandList,
773773
ur_command_list_info_t(
774774
ZeFence, true, false, ZeCommandQueue, ZeQueueDesc,
775-
Queue->useCompletionBatching(), true,
775+
Queue->useCompletionBatching(), true /*CanReuse */,
776776
ZeCommandListIt->second.InOrderList,
777777
ZeCommandListIt->second.IsImmediate))
778778
.first;

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: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ ur_result_t urEnqueueEventsWait(
8888
// Get a new command list to be used on this call
8989
ur_command_list_ptr_t CommandList{};
9090
UR_CALL(Queue->Context->getAvailableCommandList(
91-
Queue, CommandList, UseCopyEngine, NumEventsInWaitList, EventWaitList));
91+
Queue, CommandList, UseCopyEngine, NumEventsInWaitList, EventWaitList,
92+
false /*AllowBatching*/, nullptr /*ForceCmdQueue*/));
9293

9394
ze_event_handle_t ZeEvent = nullptr;
9495
ur_event_handle_t InternalEvent;
@@ -109,7 +110,8 @@ ur_result_t urEnqueueEventsWait(
109110

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

115117
{
@@ -261,12 +263,13 @@ ur_result_t urEnqueueEventsWaitWithBarrier(
261263
ur_command_list_ptr_t CmdList;
262264
UR_CALL(Queue->Context->getAvailableCommandList(
263265
Queue, CmdList, false /*UseCopyEngine=*/, NumEventsInWaitList,
264-
EventWaitList, OkToBatch));
266+
EventWaitList, OkToBatch, nullptr /*ForcedCmdQueue*/));
265267

266268
// Insert the barrier into the command-list and execute.
267269
UR_CALL(insertBarrierIntoCmdList(CmdList, TmpWaitList, *Event, IsInternal));
268270

269-
UR_CALL(Queue->executeCommandList(CmdList, false, OkToBatch));
271+
UR_CALL(
272+
Queue->executeCommandList(CmdList, false /*IsBlocking*/, OkToBatch));
270273

271274
// Because of the dependency between commands in the in-order queue we don't
272275
// need to keep track of any active barriers if we have in-order queue.
@@ -331,7 +334,7 @@ ur_result_t urEnqueueEventsWaitWithBarrier(
331334
ur_command_list_ptr_t CmdList;
332335
UR_CALL(Queue->Context->getAvailableCommandList(
333336
Queue, CmdList, false /*UseCopyEngine=*/, NumEventsInWaitList,
334-
EventWaitList, OkToBatch));
337+
EventWaitList, OkToBatch, nullptr /*ForcedCmdQueue*/));
335338
CmdLists.push_back(CmdList);
336339
}
337340

@@ -380,7 +383,8 @@ ur_result_t urEnqueueEventsWaitWithBarrier(
380383
// Only batch if the matching CmdList is already open.
381384
OkToBatch = CommandBatch.OpenCommandList == CmdList;
382385

383-
UR_CALL(Queue->executeCommandList(CmdList, false, OkToBatch));
386+
UR_CALL(
387+
Queue->executeCommandList(CmdList, false /*IsBlocking*/, OkToBatch));
384388
}
385389

386390
UR_CALL(Queue->ActiveBarriers.clear());
@@ -690,7 +694,7 @@ ur_result_t urEnqueueTimestampRecordingExp(
690694
ur_command_list_ptr_t CommandList{};
691695
UR_CALL(Queue->Context->getAvailableCommandList(
692696
Queue, CommandList, UseCopyEngine, NumEventsInWaitList, EventWaitList,
693-
/* AllowBatching */ false));
697+
/* AllowBatching */ false, nullptr /*ForcedCmdQueue*/));
694698

695699
UR_CALL(createEventAndAssociateQueue(
696700
Queue, OutEvent, UR_COMMAND_TIMESTAMP_RECORDING_EXP, CommandList,
@@ -714,7 +718,7 @@ ur_result_t urEnqueueTimestampRecordingExp(
714718
(*OutEvent)->WaitList.ZeEventList));
715719

716720
UR_CALL(
717-
Queue->executeCommandList(CommandList, Blocking, /* OkToBatch */ false));
721+
Queue->executeCommandList(CommandList, Blocking, false /* OkToBatch */));
718722

719723
return UR_RESULT_SUCCESS;
720724
}
@@ -790,7 +794,9 @@ urEventWait(uint32_t NumEvents, ///< [in] number of events in the event list
790794
else {
791795
// NOTE: we are cleaning up after the event here to free resources
792796
// sooner in case run-time is not calling urEventRelease soon enough.
793-
CleanupCompletedEvent(reinterpret_cast<ur_event_handle_t>(Event));
797+
CleanupCompletedEvent(reinterpret_cast<ur_event_handle_t>(Event),
798+
false /*QueueLocked*/,
799+
false /*SetEventCompleted*/);
794800
// For the case when we have out-of-order queue or regular command
795801
// lists its more efficient to check fences so put the queue in the
796802
// set to cleanup later.
@@ -858,7 +864,10 @@ ur_result_t urExtEventCreate(
858864
ur_event_handle_t
859865
*Event ///< [out] pointer to the handle of the event object created.
860866
) {
861-
UR_CALL(EventCreate(Context, nullptr, false, true, Event));
867+
UR_CALL(EventCreate(Context, nullptr /*Queue*/, false /*IsMultiDevice*/,
868+
true /*HostVisible*/, Event,
869+
false /*CounterBasedEventEnabled*/,
870+
false /*ForceDisableProfiling*/));
862871

863872
(*Event)->RefCountExternal++;
864873
if (!(*Event)->CounterBasedEventsEnabled)
@@ -877,7 +886,10 @@ ur_result_t urEventCreateWithNativeHandle(
877886
// we dont have urEventCreate, so use this check for now to know that
878887
// the call comes from urEventCreate()
879888
if (reinterpret_cast<ze_event_handle_t>(NativeEvent) == nullptr) {
880-
UR_CALL(EventCreate(Context, nullptr, false, true, Event));
889+
UR_CALL(EventCreate(Context, nullptr /*Queue*/, false /*IsMultiDevice*/,
890+
true /*HostVisible*/, Event,
891+
false /*CounterBasedEventEnabled*/,
892+
false /*ForceDisableProfiling*/));
881893

882894
(*Event)->RefCountExternal++;
883895
if (!(*Event)->CounterBasedEventsEnabled)
@@ -957,7 +969,8 @@ ur_result_t ur_event_handle_t_::getOrCreateHostVisibleEvent(
957969

958970
ur_command_list_ptr_t CommandList{};
959971
UR_CALL(UrQueue->Context->getAvailableCommandList(
960-
UrQueue, CommandList, false /* UseCopyEngine */, 0, nullptr, OkToBatch))
972+
UrQueue, CommandList, false /* UseCopyEngine */, 0, nullptr, OkToBatch,
973+
nullptr /*ForcedCmdQueue*/))
961974

962975
// Create a "proxy" host-visible event.
963976
UR_CALL(createEventAndAssociateQueue(
@@ -1503,7 +1516,8 @@ ur_result_t _ur_ze_event_list_t::createAndRetainUrZeEventList(
15031516
// This prevents a potential deadlock with recursive
15041517
// event locks.
15051518
UR_CALL(Queue->Context->getAvailableCommandList(
1506-
Queue, CommandList, false, 0, nullptr, true));
1519+
Queue, CommandList, false /*UseCopyEngine*/, 0, nullptr,
1520+
true /*AllowBatching*/, nullptr /*ForcedCmdQueue*/));
15071521
}
15081522

15091523
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
@@ -806,7 +806,7 @@ ur_result_t urBindlessImagesImageCopyExp(
806806
ur_command_list_ptr_t CommandList{};
807807
UR_CALL(hQueue->Context->getAvailableCommandList(
808808
hQueue, CommandList, UseCopyEngine, numEventsInWaitList, phEventWaitList,
809-
OkToBatch));
809+
OkToBatch, nullptr /*ForcedCmdQueue*/));
810810

811811
ze_event_handle_t ZeEvent = nullptr;
812812
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
@@ -138,7 +138,7 @@ ur_result_t urEnqueueKernelLaunch(
138138
ur_command_list_ptr_t CommandList{};
139139
UR_CALL(Queue->Context->getAvailableCommandList(
140140
Queue, CommandList, UseCopyEngine, NumEventsInWaitList, EventWaitList,
141-
true /* AllowBatching */));
141+
true /* AllowBatching */, nullptr /*ForcedCmdQueue*/));
142142

143143
ze_event_handle_t ZeEvent = nullptr;
144144
ur_event_handle_t InternalEvent{};
@@ -201,7 +201,8 @@ ur_result_t urEnqueueKernelLaunch(
201201

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

206207
return UR_RESULT_SUCCESS;
207208
}
@@ -402,7 +403,7 @@ ur_result_t urEnqueueCooperativeKernelLaunchExp(
402403
ur_command_list_ptr_t CommandList{};
403404
UR_CALL(Queue->Context->getAvailableCommandList(
404405
Queue, CommandList, UseCopyEngine, NumEventsInWaitList, EventWaitList,
405-
true /* AllowBatching */));
406+
true /* AllowBatching */, nullptr /*ForcedCmdQueue*/));
406407

407408
ze_event_handle_t ZeEvent = nullptr;
408409
ur_event_handle_t InternalEvent{};
@@ -465,7 +466,8 @@ ur_result_t urEnqueueCooperativeKernelLaunchExp(
465466

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

470472
return UR_RESULT_SUCCESS;
471473
}

0 commit comments

Comments
 (0)