@@ -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/*
262307This constructor initializes the `ur_adapter_handle_t_` object and
263308sets 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" );
0 commit comments