@@ -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.
@@ -471,6 +516,22 @@ ur_adapter_handle_t_::ur_adapter_handle_t_()
471516 return ;
472517 }
473518
519+ #ifdef UR_ADAPTER_LEVEL_ZERO_V2
520+ auto [useV2, reason] = shouldUseV2Adapter ();
521+ if (!useV2) {
522+ UR_LOG (INFO, " Skipping L0 V2 adapter: {}" , reason);
523+ result = std::move (platforms);
524+ return ;
525+ }
526+ #else
527+ auto [useV1, reason] = shouldUseV1Adapter ();
528+ if (!useV1) {
529+ UR_LOG (INFO, " Skipping L0 V1 adapter: {}" , reason);
530+ result = std::move (platforms);
531+ return ;
532+ }
533+ #endif
534+
474535 // Check if the user has enabled the default L0 SysMan initialization.
475536 const int UrSysmanZesinitEnable = [&UserForcedSysManInit] {
476537 const char *UrRet = std::getenv (" UR_L0_ENABLE_ZESINIT_DEFAULT" );
0 commit comments