Skip to content

Commit d6aa8c0

Browse files
Updated Driver In order lists check and required version (#17620)
@nrspruit's [patch ](#17106 and posted here as I work on fixing this patch. - Refactor's the check for driver in order lists into one place, but still disables driver in order lists by default. --------- Signed-off-by: Neil R. Spruit <[email protected]> Signed-off-by: Zhang, Winston <[email protected]> Co-authored-by: Wu, Yingcong <[email protected]>
1 parent 8ceaf1d commit d6aa8c0

File tree

9 files changed

+58
-57
lines changed

9 files changed

+58
-57
lines changed

unified-runtime/source/adapters/level_zero/command_buffer.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ bool checkCounterBasedEventsSupport(ur_device_handle_t Device) {
7676
return std::atoi(UrRet) != 0;
7777
}();
7878

79-
return Device->ImmCommandListUsed && Device->useDriverInOrderLists() &&
79+
return Device->ImmCommandListUsed &&
80+
Device->Platform->allowDriverInOrderLists(
81+
true /*Only Allow Driver In Order List if requested*/) &&
8082
useDriverCounterBasedEvents &&
8183
Device->Platform->ZeDriverEventPoolCountingEventsExtensionFound;
8284
}
@@ -647,12 +649,9 @@ ur_result_t createMainCommandList(ur_context_handle_t Context,
647649
*/
648650
bool canBeInOrder(ur_context_handle_t Context,
649651
const ur_exp_command_buffer_desc_t *CommandBufferDesc) {
650-
const char *UrRet = std::getenv("UR_L0_USE_DRIVER_INORDER_LISTS");
651-
// In-order command-lists are not available in old driver version.
652-
bool DriverInOrderRequested = UrRet ? std::atoi(UrRet) != 0 : false;
653-
bool CompatibleDriver = Context->getPlatform()->isDriverVersionNewerOrSimilar(
654-
1, 3, L0_DRIVER_INORDER_MIN_VERSION);
655-
bool CanUseDriverInOrderLists = CompatibleDriver && DriverInOrderRequested;
652+
bool CanUseDriverInOrderLists =
653+
Context->getPlatform()->allowDriverInOrderLists(
654+
true /*Only Allow Driver In Order List if requested*/);
656655
return CanUseDriverInOrderLists ? CommandBufferDesc->isInOrder : false;
657656
}
658657

unified-runtime/source/adapters/level_zero/common.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,4 @@ extern thread_local int32_t ErrorAdapterNativeCode;
432432
// Utility function for setting a message and warning
433433
[[maybe_unused]] void setErrorMessage(const char *pMessage,
434434
ur_result_t ErrorCode,
435-
int32_t AdapterErrorCode);
436-
437-
#define L0_DRIVER_INORDER_MIN_VERSION 29534
435+
int32_t AdapterErrorCode);

unified-runtime/source/adapters/level_zero/context.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,8 @@ ur_result_t ur_context_handle_t_::initialize() {
207207

208208
ZeCommandQueueDesc.index = 0;
209209
ZeCommandQueueDesc.mode = ZE_COMMAND_QUEUE_MODE_SYNCHRONOUS;
210-
if (Device->useDriverInOrderLists() &&
210+
if (Device->Platform->allowDriverInOrderLists(
211+
true /*Only Allow Driver In Order List if requested*/) &&
211212
Device->useDriverCounterBasedEvents()) {
212213
logger::debug(
213214
"L0 Synchronous Immediate Command List needed with In Order property.");
@@ -673,8 +674,9 @@ ur_result_t ur_context_handle_t_::getAvailableCommandList(
673674
for (auto ZeCommandListIt = ZeCommandListCache.begin();
674675
ZeCommandListIt != ZeCommandListCache.end(); ++ZeCommandListIt) {
675676
// If this is an InOrder Queue, then only allow lists which are in order.
676-
if (Queue->Device->useDriverInOrderLists() && Queue->isInOrderQueue() &&
677-
!(ZeCommandListIt->second.InOrderList)) {
677+
if (Queue->Device->Platform->allowDriverInOrderLists(
678+
true /*Only Allow Driver In Order List if requested*/) &&
679+
Queue->isInOrderQueue() && !(ZeCommandListIt->second.InOrderList)) {
678680
continue;
679681
}
680682
// Only allow to reuse Regular Command Lists
@@ -740,8 +742,9 @@ ur_result_t ur_context_handle_t_::getAvailableCommandList(
740742
continue;
741743

742744
// If this is an InOrder Queue, then only allow lists which are in order.
743-
if (Queue->Device->useDriverInOrderLists() && Queue->isInOrderQueue() &&
744-
!(it->second.IsInOrderList)) {
745+
if (Queue->Device->Platform->allowDriverInOrderLists(
746+
true /*Only Allow Driver In Order List if requested*/) &&
747+
Queue->isInOrderQueue() && !(it->second.IsInOrderList)) {
745748
continue;
746749
}
747750

unified-runtime/source/adapters/level_zero/device.cpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1676,22 +1676,6 @@ bool ur_device_handle_t_::useRelaxedAllocationLimits() {
16761676
return EnableRelaxedAllocationLimits;
16771677
}
16781678

1679-
bool ur_device_handle_t_::useDriverInOrderLists() {
1680-
// Use in-order lists implementation from L0 driver instead
1681-
// of adapter's implementation.
1682-
1683-
static const bool UseDriverInOrderLists = [&] {
1684-
const char *UrRet = std::getenv("UR_L0_USE_DRIVER_INORDER_LISTS");
1685-
// bool CompatibleDriver = this->Platform->isDriverVersionNewerOrSimilar(
1686-
// 1, 3, L0_DRIVER_INORDER_MIN_VERSION);
1687-
if (!UrRet)
1688-
return false;
1689-
return std::atoi(UrRet) != 0;
1690-
}();
1691-
1692-
return UseDriverInOrderLists;
1693-
}
1694-
16951679
bool ur_device_handle_t_::useDriverCounterBasedEvents() {
16961680
// Use counter-based events implementation from L0 driver.
16971681

unified-runtime/source/adapters/level_zero/device.hpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,6 @@ struct ur_device_handle_t_ : _ur_object {
155155
// Read env settings to select immediate commandlist mode.
156156
ImmCmdlistMode useImmediateCommandLists();
157157

158-
// Whether Adapter uses driver's implementation of in-order lists or not
159-
bool useDriverInOrderLists();
160-
161158
// Whether Adapter uses driver's implementation of counter-based events or not
162159
bool useDriverCounterBasedEvents();
163160

unified-runtime/source/adapters/level_zero/event.cpp

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -223,22 +223,6 @@ ur_result_t urEnqueueEventsWaitWithBarrierExt(
223223
if (Queue->isInOrderQueue() && InOrderBarrierBySignal &&
224224
!Queue->isProfilingEnabled()) {
225225
if (EventWaitList.Length) {
226-
if (CmdList->second.IsInOrderList) {
227-
for (unsigned i = EventWaitList.Length; i-- > 0;) {
228-
// If the event is a multidevice event, then given driver in
229-
// order lists, we cannot include this into the wait event list
230-
// due to driver limitations.
231-
if (EventWaitList.UrEventList[i]->IsMultiDevice) {
232-
EventWaitList.Length--;
233-
if (EventWaitList.Length != i) {
234-
std::swap(EventWaitList.UrEventList[i],
235-
EventWaitList.UrEventList[EventWaitList.Length]);
236-
std::swap(EventWaitList.ZeEventList[i],
237-
EventWaitList.ZeEventList[EventWaitList.Length]);
238-
}
239-
}
240-
}
241-
}
242226
ZE2UR_CALL(zeCommandListAppendWaitOnEvents,
243227
(CmdList->first, EventWaitList.Length,
244228
EventWaitList.ZeEventList));
@@ -1505,8 +1489,9 @@ ur_result_t _ur_ze_event_list_t::createAndRetainUrZeEventList(
15051489
// the native driver implementation will already ensure in-order semantics.
15061490
// The only exception is when a different immediate command was last used on
15071491
// the same UR Queue.
1508-
if (CurQueue->Device->useDriverInOrderLists() && CurQueue->isInOrderQueue() &&
1509-
CurQueue->UsingImmCmdLists) {
1492+
if (CurQueue->Device->Platform->allowDriverInOrderLists(
1493+
true /*Only Allow Driver In Order List if requested*/) &&
1494+
CurQueue->isInOrderQueue() && CurQueue->UsingImmCmdLists) {
15101495
auto QueueGroup = CurQueue->getQueueGroup(UseCopyEngine);
15111496
uint32_t QueueGroupOrdinal, QueueIndex;
15121497
auto NextIndex = QueueGroup.getQueueIndex(&QueueGroupOrdinal, &QueueIndex,
@@ -1535,7 +1520,8 @@ ur_result_t _ur_ze_event_list_t::createAndRetainUrZeEventList(
15351520

15361521
// For in-order queue and wait-list which is empty or has events only from
15371522
// the same queue then we don't need to wait on any other additional events
1538-
if (CurQueue->Device->useDriverInOrderLists() &&
1523+
if (CurQueue->Device->Platform->allowDriverInOrderLists(
1524+
true /*Only Allow Driver In Order List if requested*/) &&
15391525
CurQueue->isInOrderQueue() &&
15401526
WaitListEmptyOrAllEventsFromSameQueue(CurQueue, EventListLength,
15411527
EventList)) {

unified-runtime/source/adapters/level_zero/platform.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,28 @@ ur_result_t ur_platform_handle_t_::initialize() {
549549
return UR_RESULT_SUCCESS;
550550
}
551551

552+
bool ur_platform_handle_t_::allowDriverInOrderLists(bool OnlyIfRequested) {
553+
// Use in-order lists implementation from L0 driver instead
554+
// of adapter's implementation.
555+
556+
// The following driver version is known to be passing and only this or newer
557+
// drivers should be allowed by default for in order lists.
558+
#define L0_DRIVER_INORDER_MINOR_VERSION 6
559+
#define L0_DRIVER_INORDER_PATCH_VERSION 32149
560+
561+
static const bool UseEnvVarDriverInOrderLists = [&] {
562+
const char *UrRet = std::getenv("UR_L0_USE_DRIVER_INORDER_LISTS");
563+
return UrRet ? std::atoi(UrRet) != 0 : false;
564+
}();
565+
static const bool UseDriverInOrderLists = [this] {
566+
bool CompatibleDriver = this->isDriverVersionNewerOrSimilar(
567+
1, L0_DRIVER_INORDER_MINOR_VERSION, L0_DRIVER_INORDER_PATCH_VERSION);
568+
return CompatibleDriver || UseEnvVarDriverInOrderLists;
569+
}();
570+
571+
return OnlyIfRequested ? UseEnvVarDriverInOrderLists : UseDriverInOrderLists;
572+
}
573+
552574
/// Checks the version of the level-zero driver.
553575
/// @param VersionMajor Major verion number to compare to.
554576
/// @param VersionMinor Minor verion number to compare to.

unified-runtime/source/adapters/level_zero/platform.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ struct ur_platform_handle_t_ : public _ur_platform {
4848
// Zero.
4949
ZeDriverVersionStringExtension ZeDriverVersionString;
5050

51+
// Helper function to check if the driver supports Driver In Order Lists or
52+
// the User has Requested this support.
53+
bool allowDriverInOrderLists(bool OnlyIfRequested = false);
54+
5155
// Cache versions info from zeDriverGetProperties.
5256
std::string ZeDriverVersion;
5357
std::string ZeDriverApiVersion;

unified-runtime/source/adapters/level_zero/queue.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,11 +1198,15 @@ ur_queue_handle_t_::ur_queue_handle_t_(
11981198
CopyCommandBatch.QueueBatchSize = ZeCommandListBatchCopyConfig.startSize();
11991199

12001200
this->CounterBasedEventsEnabled =
1201-
UsingImmCmdLists && isInOrderQueue() && Device->useDriverInOrderLists() &&
1201+
UsingImmCmdLists && isInOrderQueue() &&
1202+
Device->Platform->allowDriverInOrderLists(
1203+
true /*Only Allow Driver In Order List if requested*/) &&
12021204
Device->useDriverCounterBasedEvents() &&
12031205
Device->Platform->ZeDriverEventPoolCountingEventsExtensionFound;
12041206
this->InterruptBasedEventsEnabled =
1205-
isLowPowerEvents() && isInOrderQueue() && Device->useDriverInOrderLists();
1207+
isLowPowerEvents() && isInOrderQueue() &&
1208+
Device->Platform->allowDriverInOrderLists(
1209+
true /*Only Allow Driver In Order List if requested*/);
12061210
}
12071211

12081212
void ur_queue_handle_t_::adjustBatchSizeForFullBatch(bool IsCopy) {
@@ -2297,7 +2301,9 @@ ur_result_t ur_queue_handle_t_::createCommandList(
22972301
ZeCommandListDesc.commandQueueGroupOrdinal = QueueGroupOrdinal;
22982302

22992303
bool IsInOrderList = false;
2300-
if (Device->useDriverInOrderLists() && isInOrderQueue()) {
2304+
if (Device->Platform->allowDriverInOrderLists(
2305+
true /*Only Allow Driver In Order List if requested*/) &&
2306+
isInOrderQueue()) {
23012307
ZeCommandListDesc.flags = ZE_COMMAND_LIST_FLAG_IN_ORDER;
23022308
IsInOrderList = true;
23032309
}
@@ -2434,7 +2440,9 @@ ur_command_list_ptr_t &ur_queue_handle_t_::ur_queue_group_t::getImmCmdList() {
24342440
ZeCommandQueueDesc.flags |= ZE_COMMAND_QUEUE_FLAG_EXPLICIT_ONLY;
24352441
}
24362442

2437-
if (Queue->Device->useDriverInOrderLists() && Queue->isInOrderQueue()) {
2443+
if (Queue->Device->Platform->allowDriverInOrderLists(
2444+
true /*Only Allow Driver In Order List if requested*/) &&
2445+
Queue->isInOrderQueue()) {
24382446
isInOrderList = true;
24392447
ZeCommandQueueDesc.flags |= ZE_COMMAND_QUEUE_FLAG_IN_ORDER;
24402448
}

0 commit comments

Comments
 (0)