Skip to content

Commit 7170ae0

Browse files
committed
[SYCL][UR] Make v2 adapter default for BMG and newer
Whenever we detect ANY device newer than BMG on the platform we will use V2, otherwise we will use V1. The default behavior can still be overwritten by setting SYCL_UR_USE_LEVEL_ZERO_V2=1 to use V2 adapter or SYCL_UR_USE_LEVEL_ZERO_V2=0 to use V1 adapter.
1 parent 5f86594 commit 7170ae0

File tree

2 files changed

+61
-16
lines changed

2 files changed

+61
-16
lines changed

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

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,51 @@ ur_result_t adapterStateInit() {
258258
return UR_RESULT_SUCCESS;
259259
}
260260

261+
static bool isBMGorNewer() {
262+
auto urResult = checkDeviceIntelGPUIpVersionOrNewer(0x05004000);
263+
if (urResult != UR_RESULT_SUCCESS &&
264+
urResult != UR_RESULT_ERROR_UNSUPPORTED_VERSION) {
265+
UR_LOG(ERR, "Intel GPU IP Version check failed: {}\n", urResult);
266+
throw urResult;
267+
}
268+
269+
return urResult == UR_RESULT_SUCCESS;
270+
}
271+
272+
// returns a pair indicating whether to use the V1 adapter and a string
273+
// indicating the reason for the decision.
274+
static std::pair<bool, std::string> shouldUseV1Adapter() {
275+
auto specificAdapterVersionRequested =
276+
ur_getenv("UR_LOADER_USE_LEVEL_ZERO_V2").has_value() ||
277+
ur_getenv("SYCL_UR_USE_LEVEL_ZERO_V2").has_value();
278+
279+
auto v2Requested = getenv_tobool("UR_LOADER_USE_LEVEL_ZERO_V2", false);
280+
v2Requested |= getenv_tobool("SYCL_UR_USE_LEVEL_ZERO_V2", false);
281+
282+
std::string reason =
283+
specificAdapterVersionRequested
284+
? "Specific adapter version requested by UR_LOADER_USE_LEVEL_ZERO_V2 "
285+
"or SYCL_UR_USE_LEVEL_ZERO_V2"
286+
: "Using default adapter version based on device IP version";
287+
288+
if (v2Requested) {
289+
return {false, reason};
290+
}
291+
292+
if (!v2Requested && specificAdapterVersionRequested) {
293+
// v1 specifically requested
294+
return {true, reason};
295+
}
296+
297+
// default: only enable for devices older than BMG
298+
return {!isBMGorNewer(), reason};
299+
}
300+
301+
static std::pair<bool, std::string> shouldUseV2Adapter() {
302+
auto [useV1, reason] = shouldUseV1Adapter();
303+
return {!useV1, reason};
304+
}
305+
261306
/*
262307
This constructor initializes the `ur_adapter_handle_t_` object and
263308
sets up the environment for Level Zero (L0) initialization.
@@ -476,6 +521,22 @@ ur_adapter_handle_t_::ur_adapter_handle_t_()
476521
return;
477522
}
478523

524+
#ifdef UR_ADAPTER_LEVEL_ZERO_V2
525+
auto [useV2, reason] = shouldUseV2Adapter();
526+
if (!useV2) {
527+
UR_LOG(INFO, "Skipping L0 V2 adapter: {}", reason);
528+
result = std::move(platforms);
529+
return;
530+
}
531+
#else
532+
auto [useV1, reason] = shouldUseV1Adapter();
533+
if (!useV1) {
534+
UR_LOG(INFO, "Skipping L0 V1 adapter: {}", reason);
535+
result = std::move(platforms);
536+
return;
537+
}
538+
#endif
539+
479540
// Check if the user has enabled the default L0 SysMan initialization.
480541
const int UrSysmanZesinitEnable = [&UserForcedSysManInit] {
481542
const char *UrRet = std::getenv("UR_L0_ENABLE_ZESINIT_DEFAULT");

unified-runtime/source/loader/ur_adapter_registry.hpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -355,22 +355,6 @@ class AdapterRegistry {
355355
}
356356

357357
for (const auto &adapterName : adapterNames) {
358-
// Skip legacy L0 adapter if the v2 adapter is requested, and vice versa.
359-
if (std::string(adapterName).find("level_zero") != std::string::npos) {
360-
auto v2Requested = getenv_tobool("UR_LOADER_USE_LEVEL_ZERO_V2", false);
361-
v2Requested |= getenv_tobool("SYCL_UR_USE_LEVEL_ZERO_V2", false);
362-
auto v2Adapter =
363-
std::string(adapterName).find("v2") != std::string::npos;
364-
365-
if (v2Requested != v2Adapter) {
366-
UR_LOG(INFO, "The adapter '{}' is skipped because {} {}.",
367-
adapterName,
368-
"UR_LOADER_USE_LEVEL_ZERO_V2 or SYCL_UR_USE_LEVEL_ZERO_V2",
369-
v2Requested ? "is set" : "is not set");
370-
continue;
371-
}
372-
}
373-
374358
std::vector<fs::path> loadPaths;
375359

376360
// Adapter search order:

0 commit comments

Comments
 (0)