Skip to content

Commit 45f9846

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 <neil.r.spruit@intel.com>
1 parent 608603a commit 45f9846

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

@@ -1197,14 +1206,15 @@ ur_result_t waitForDependencies(ur_exp_command_buffer_handle_t CommandBuffer,
11971206
// when `EventWaitList` dependencies are complete.
11981207
ur_command_list_ptr_t WaitCommandList{};
11991208
UR_CALL(Queue->Context->getAvailableCommandList(
1200-
Queue, WaitCommandList, false, NumEventsInWaitList, EventWaitList,
1201-
false));
1209+
Queue, WaitCommandList, false /*UseCopyEngine*/, NumEventsInWaitList,
1210+
EventWaitList, false /*AllowBatching*/, nullptr /*ForcedCmdQueue*/));
12021211

12031212
ZE2UR_CALL(zeCommandListAppendBarrier,
12041213
(WaitCommandList->first, CommandBuffer->WaitEvent->ZeEvent,
12051214
CommandBuffer->WaitEvent->WaitList.Length,
12061215
CommandBuffer->WaitEvent->WaitList.ZeEventList));
1207-
Queue->executeCommandList(WaitCommandList, false, false);
1216+
Queue->executeCommandList(WaitCommandList, false /*IsBlocking*/,
1217+
false /*OKToBatchCommand*/);
12081218
MustSignalWaitEvent = false;
12091219
}
12101220
}
@@ -1316,9 +1326,9 @@ urCommandBufferEnqueueExp(ur_exp_command_buffer_handle_t CommandBuffer,
13161326

13171327
// Create a command-list to signal the Event on completion
13181328
ur_command_list_ptr_t SignalCommandList{};
1319-
UR_CALL(Queue->Context->getAvailableCommandList(Queue, SignalCommandList,
1320-
false, NumEventsInWaitList,
1321-
EventWaitList, false));
1329+
UR_CALL(Queue->Context->getAvailableCommandList(
1330+
Queue, SignalCommandList, false /*UseCopyEngine*/, NumEventsInWaitList,
1331+
EventWaitList, false /*AllowBatching*/, nullptr /*ForcedCmdQueue*/));
13221332

13231333
// Reset the wait-event for the UR command-buffer that is signaled when its
13241334
// submission dependencies have been satisfied.
@@ -1333,7 +1343,8 @@ urCommandBufferEnqueueExp(ur_exp_command_buffer_handle_t CommandBuffer,
13331343
// parameter with signal command-list completing.
13341344
UR_CALL(createUserEvent(CommandBuffer, Queue, SignalCommandList, Event));
13351345

1336-
UR_CALL(Queue->executeCommandList(SignalCommandList, false, false));
1346+
UR_CALL(Queue->executeCommandList(SignalCommandList, false /*IsBlocking*/,
1347+
false /*OKToBatchCommand*/));
13371348

13381349
return UR_RESULT_SUCCESS;
13391350
}

source/adapters/level_zero/context.cpp

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

source/adapters/level_zero/context.hpp

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

308308
// Checks if Device is covered by this context.
309309
// 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
{
@@ -279,13 +281,14 @@ ur_result_t urEnqueueEventsWaitWithBarrier(
279281
ur_command_list_ptr_t CmdList;
280282
UR_CALL(Queue->Context->getAvailableCommandList(
281283
Queue, CmdList, false /*UseCopyEngine=*/, NumEventsInWaitList,
282-
EventWaitList, OkToBatch));
284+
EventWaitList, OkToBatch, nullptr /*ForcedCmdQueue*/));
283285

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

288-
UR_CALL(Queue->executeCommandList(CmdList, false, OkToBatch));
290+
UR_CALL(
291+
Queue->executeCommandList(CmdList, false /*IsBlocking*/, OkToBatch));
289292

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

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

407-
UR_CALL(Queue->executeCommandList(CmdList, false, OkToBatch));
410+
UR_CALL(
411+
Queue->executeCommandList(CmdList, false /*IsBlocking*/, OkToBatch));
408412
}
409413

410414
UR_CALL(Queue->ActiveBarriers.clear());
@@ -716,7 +720,7 @@ ur_result_t urEnqueueTimestampRecordingExp(
716720
ur_command_list_ptr_t CommandList{};
717721
UR_CALL(Queue->Context->getAvailableCommandList(
718722
Queue, CommandList, UseCopyEngine, NumEventsInWaitList, EventWaitList,
719-
/* AllowBatching */ false));
723+
/* AllowBatching */ false, nullptr /*ForcedCmdQueue*/));
720724

721725
UR_CALL(createEventAndAssociateQueue(
722726
Queue, OutEvent, UR_COMMAND_TIMESTAMP_RECORDING_EXP, CommandList,
@@ -740,7 +744,7 @@ ur_result_t urEnqueueTimestampRecordingExp(
740744
(*OutEvent)->WaitList.ZeEventList));
741745

742746
UR_CALL(
743-
Queue->executeCommandList(CommandList, Blocking, /* OkToBatch */ false));
747+
Queue->executeCommandList(CommandList, Blocking, false /* OkToBatch */));
744748

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

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

908920
(*Event)->RefCountExternal++;
909921
if (!(*Event)->CounterBasedEventsEnabled)
@@ -983,7 +995,8 @@ ur_result_t ur_event_handle_t_::getOrCreateHostVisibleEvent(
983995

984996
ur_command_list_ptr_t CommandList{};
985997
UR_CALL(UrQueue->Context->getAvailableCommandList(
986-
UrQueue, CommandList, false /* UseCopyEngine */, 0, nullptr, OkToBatch))
998+
UrQueue, CommandList, false /* UseCopyEngine */, 0, nullptr, OkToBatch,
999+
nullptr /*ForcedCmdQueue*/))
9871000

9881001
// Create a "proxy" host-visible event.
9891002
UR_CALL(createEventAndAssociateQueue(
@@ -1529,7 +1542,8 @@ ur_result_t _ur_ze_event_list_t::createAndRetainUrZeEventList(
15291542
// This prevents a potential deadlock with recursive
15301543
// event locks.
15311544
UR_CALL(Queue->Context->getAvailableCommandList(
1532-
Queue, CommandList, false, 0, nullptr, true));
1545+
Queue, CommandList, false /*UseCopyEngine*/, 0, nullptr,
1546+
true /*AllowBatching*/, nullptr /*ForcedCmdQueue*/));
15331547
}
15341548

15351549
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
@@ -856,7 +856,7 @@ ur_result_t urBindlessImagesImageCopyExp(
856856
ur_command_list_ptr_t CommandList{};
857857
UR_CALL(hQueue->Context->getAvailableCommandList(
858858
hQueue, CommandList, UseCopyEngine, numEventsInWaitList, phEventWaitList,
859-
OkToBatch));
859+
OkToBatch, nullptr /*ForcedCmdQueue*/));
860860

861861
ze_event_handle_t ZeEvent = nullptr;
862862
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
@@ -133,7 +133,7 @@ ur_result_t urEnqueueKernelLaunch(
133133
ur_command_list_ptr_t CommandList{};
134134
UR_CALL(Queue->Context->getAvailableCommandList(
135135
Queue, CommandList, UseCopyEngine, NumEventsInWaitList, EventWaitList,
136-
true /* AllowBatching */));
136+
true /* AllowBatching */, nullptr /*ForcedCmdQueue*/));
137137

138138
ze_event_handle_t ZeEvent = nullptr;
139139
ur_event_handle_t InternalEvent{};
@@ -196,7 +196,8 @@ ur_result_t urEnqueueKernelLaunch(
196196

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

201202
return UR_RESULT_SUCCESS;
202203
}
@@ -392,7 +393,7 @@ ur_result_t urEnqueueCooperativeKernelLaunchExp(
392393
ur_command_list_ptr_t CommandList{};
393394
UR_CALL(Queue->Context->getAvailableCommandList(
394395
Queue, CommandList, UseCopyEngine, NumEventsInWaitList, EventWaitList,
395-
true /* AllowBatching */));
396+
true /* AllowBatching */, nullptr /*ForcedCmdQueue*/));
396397

397398
ze_event_handle_t ZeEvent = nullptr;
398399
ur_event_handle_t InternalEvent{};
@@ -455,7 +456,8 @@ ur_result_t urEnqueueCooperativeKernelLaunchExp(
455456

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

460462
return UR_RESULT_SUCCESS;
461463
}

0 commit comments

Comments
 (0)