Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ bool checkCounterBasedEventsSupport(ur_device_handle_t Device) {
return std::atoi(UrRet) != 0;
}();

return Device->ImmCommandListUsed && Device->useDriverInOrderLists() &&
useDriverCounterBasedEvents &&
return Device->ImmCommandListUsed && useDriverCounterBasedEvents &&
Device->Platform->ZeDriverEventPoolCountingEventsExtensionFound;
}

Expand Down
2 changes: 1 addition & 1 deletion unified-runtime/source/adapters/level_zero/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -609,4 +609,4 @@ extern thread_local int32_t ErrorAdapterNativeCode;
ur_result_t ErrorCode,
int32_t AdapterErrorCode);

#define L0_DRIVER_INORDER_MIN_VERSION 29534
#define L0_DRIVER_INORDER_MIN_VERSION 29534
10 changes: 5 additions & 5 deletions unified-runtime/source/adapters/level_zero/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ ur_result_t ur_context_handle_t_::initialize() {

ZeCommandQueueDesc.index = 0;
ZeCommandQueueDesc.mode = ZE_COMMAND_QUEUE_MODE_SYNCHRONOUS;
if (Device->useDriverInOrderLists() &&
if (Device->Platform->allowDriverInOrderLists() &&
Device->useDriverCounterBasedEvents()) {
logger::debug(
"L0 Synchronous Immediate Command List needed with In Order property.");
Expand Down Expand Up @@ -673,8 +673,8 @@ ur_result_t ur_context_handle_t_::getAvailableCommandList(
for (auto ZeCommandListIt = ZeCommandListCache.begin();
ZeCommandListIt != ZeCommandListCache.end(); ++ZeCommandListIt) {
// If this is an InOrder Queue, then only allow lists which are in order.
if (Queue->Device->useDriverInOrderLists() && Queue->isInOrderQueue() &&
!(ZeCommandListIt->second.InOrderList)) {
if (Queue->Device->Platform->allowDriverInOrderLists() &&
Queue->isInOrderQueue() && !(ZeCommandListIt->second.InOrderList)) {
continue;
}
// Only allow to reuse Regular Command Lists
Expand Down Expand Up @@ -740,8 +740,8 @@ ur_result_t ur_context_handle_t_::getAvailableCommandList(
continue;

// If this is an InOrder Queue, then only allow lists which are in order.
if (Queue->Device->useDriverInOrderLists() && Queue->isInOrderQueue() &&
!(it->second.IsInOrderList)) {
if (Queue->Device->Platform->allowDriverInOrderLists() &&
Queue->isInOrderQueue() && !(it->second.IsInOrderList)) {
continue;
}

Expand Down
16 changes: 0 additions & 16 deletions unified-runtime/source/adapters/level_zero/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1668,22 +1668,6 @@ bool ur_device_handle_t_::useRelaxedAllocationLimits() {
return EnableRelaxedAllocationLimits;
}

bool ur_device_handle_t_::useDriverInOrderLists() {
// Use in-order lists implementation from L0 driver instead
// of adapter's implementation.

static const bool UseDriverInOrderLists = [&] {
const char *UrRet = std::getenv("UR_L0_USE_DRIVER_INORDER_LISTS");
// bool CompatibleDriver = this->Platform->isDriverVersionNewerOrSimilar(
// 1, 3, L0_DRIVER_INORDER_MIN_VERSION);
if (!UrRet)
return false;
return std::atoi(UrRet) != 0;
}();

return UseDriverInOrderLists;
}

bool ur_device_handle_t_::useDriverCounterBasedEvents() {
// Use counter-based events implementation from L0 driver.

Expand Down
3 changes: 0 additions & 3 deletions unified-runtime/source/adapters/level_zero/device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,6 @@ struct ur_device_handle_t_ : _ur_object {
// Read env settings to select immediate commandlist mode.
ImmCmdlistMode useImmediateCommandLists();

// Whether Adapter uses driver's implementation of in-order lists or not
bool useDriverInOrderLists();

// Whether Adapter uses driver's implementation of counter-based events or not
bool useDriverCounterBasedEvents();

Expand Down
22 changes: 3 additions & 19 deletions unified-runtime/source/adapters/level_zero/event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,22 +223,6 @@ ur_result_t urEnqueueEventsWaitWithBarrierExt(
if (Queue->isInOrderQueue() && InOrderBarrierBySignal &&
!Queue->isProfilingEnabled()) {
if (EventWaitList.Length) {
if (CmdList->second.IsInOrderList) {
for (unsigned i = EventWaitList.Length; i-- > 0;) {
// If the event is a multidevice event, then given driver in
// order lists, we cannot include this into the wait event list
// due to driver limitations.
if (EventWaitList.UrEventList[i]->IsMultiDevice) {
EventWaitList.Length--;
if (EventWaitList.Length != i) {
std::swap(EventWaitList.UrEventList[i],
EventWaitList.UrEventList[EventWaitList.Length]);
std::swap(EventWaitList.ZeEventList[i],
EventWaitList.ZeEventList[EventWaitList.Length]);
}
}
}
}
ZE2UR_CALL(zeCommandListAppendWaitOnEvents,
(CmdList->first, EventWaitList.Length,
EventWaitList.ZeEventList));
Expand Down Expand Up @@ -1505,8 +1489,8 @@ ur_result_t _ur_ze_event_list_t::createAndRetainUrZeEventList(
// the native driver implementation will already ensure in-order semantics.
// The only exception is when a different immediate command was last used on
// the same UR Queue.
if (CurQueue->Device->useDriverInOrderLists() && CurQueue->isInOrderQueue() &&
CurQueue->UsingImmCmdLists) {
if (CurQueue->Device->Platform->allowDriverInOrderLists() &&
CurQueue->isInOrderQueue() && CurQueue->UsingImmCmdLists) {
auto QueueGroup = CurQueue->getQueueGroup(UseCopyEngine);
uint32_t QueueGroupOrdinal, QueueIndex;
auto NextIndex = QueueGroup.getQueueIndex(&QueueGroupOrdinal, &QueueIndex,
Expand Down Expand Up @@ -1535,7 +1519,7 @@ ur_result_t _ur_ze_event_list_t::createAndRetainUrZeEventList(

// For in-order queue and wait-list which is empty or has events only from
// the same queue then we don't need to wait on any other additional events
if (CurQueue->Device->useDriverInOrderLists() &&
if (CurQueue->Device->Platform->allowDriverInOrderLists() &&
CurQueue->isInOrderQueue() &&
WaitListEmptyOrAllEventsFromSameQueue(CurQueue, EventListLength,
EventList)) {
Expand Down
24 changes: 24 additions & 0 deletions unified-runtime/source/adapters/level_zero/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,30 @@ ur_result_t ur_platform_handle_t_::initialize() {
return UR_RESULT_SUCCESS;
}

bool ur_platform_handle_t_::allowDriverInOrderLists(bool OnlyIfRequested) {
// Use in-order lists implementation from L0 driver instead
// of adapter's implementation.

// The following driver version is known to be passing and only this or newer
// drivers should be allowed by default for in order lists.
#define L0_DRIVER_INORDER_MINOR_VERSION 6
#define L0_DRIVER_INORDER_PATCH_VERSION 32149

static const bool UseDriverInOrderLists = [&] {
const char *UrRet = std::getenv("UR_L0_USE_DRIVER_INORDER_LISTS");
bool CompatibleDriver = this->isDriverVersionNewerOrSimilar(
1, L0_DRIVER_INORDER_MINOR_VERSION, L0_DRIVER_INORDER_PATCH_VERSION);
bool DriverInOrderRequested = UrRet ? std::atoi(UrRet) != 0 : false;
if (OnlyIfRequested) {
return DriverInOrderRequested;
}
bool CanUseDriverInOrderLists = CompatibleDriver || DriverInOrderRequested;
return CanUseDriverInOrderLists;
}();

return UseDriverInOrderLists;
}

/// Checks the version of the level-zero driver.
/// @param VersionMajor Major verion number to compare to.
/// @param VersionMinor Minor verion number to compare to.
Expand Down
4 changes: 4 additions & 0 deletions unified-runtime/source/adapters/level_zero/platform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ struct ur_platform_handle_t_ : public _ur_platform {
// Zero.
ZeDriverVersionStringExtension ZeDriverVersionString;

// Helper function to check if the driver supports Driver In Order Lists or
// the User has Requested this support.
bool allowDriverInOrderLists(bool OnlyIfRequested = false);

// Cache versions info from zeDriverGetProperties.
std::string ZeDriverVersion;
std::string ZeDriverApiVersion;
Expand Down
11 changes: 7 additions & 4 deletions unified-runtime/source/adapters/level_zero/queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1198,11 +1198,13 @@ ur_queue_handle_t_::ur_queue_handle_t_(
CopyCommandBatch.QueueBatchSize = ZeCommandListBatchCopyConfig.startSize();

this->CounterBasedEventsEnabled =
UsingImmCmdLists && isInOrderQueue() && Device->useDriverInOrderLists() &&
UsingImmCmdLists && isInOrderQueue() &&
Device->Platform->allowDriverInOrderLists() &&
Device->useDriverCounterBasedEvents() &&
Device->Platform->ZeDriverEventPoolCountingEventsExtensionFound;
this->InterruptBasedEventsEnabled =
isLowPowerEvents() && isInOrderQueue() && Device->useDriverInOrderLists();
isLowPowerEvents() && isInOrderQueue() &&
Device->Platform->allowDriverInOrderLists();
}

void ur_queue_handle_t_::adjustBatchSizeForFullBatch(bool IsCopy) {
Expand Down Expand Up @@ -2297,7 +2299,7 @@ ur_result_t ur_queue_handle_t_::createCommandList(
ZeCommandListDesc.commandQueueGroupOrdinal = QueueGroupOrdinal;

bool IsInOrderList = false;
if (Device->useDriverInOrderLists() && isInOrderQueue()) {
if (Device->Platform->allowDriverInOrderLists() && isInOrderQueue()) {
ZeCommandListDesc.flags = ZE_COMMAND_LIST_FLAG_IN_ORDER;
IsInOrderList = true;
}
Expand Down Expand Up @@ -2434,7 +2436,8 @@ ur_command_list_ptr_t &ur_queue_handle_t_::ur_queue_group_t::getImmCmdList() {
ZeCommandQueueDesc.flags |= ZE_COMMAND_QUEUE_FLAG_EXPLICIT_ONLY;
}

if (Queue->Device->useDriverInOrderLists() && Queue->isInOrderQueue()) {
if (Queue->Device->Platform->allowDriverInOrderLists() &&
Queue->isInOrderQueue()) {
isInOrderList = true;
ZeCommandQueueDesc.flags |= ZE_COMMAND_QUEUE_FLAG_IN_ORDER;
}
Expand Down