@@ -283,6 +283,11 @@ def get_extra_env(sycl_devices):
283283 # so that device might still be accessible to some of the tests yet
284284 # we won't set the environment variable below for such scenario.
285285 extra_env = []
286+
287+ # Include ZE_AFFINITY_MASK if set by lit.local.cfg (e.g., for sanitizer tests)
288+ if "ZE_AFFINITY_MASK" in test .config .environment :
289+ extra_env .append ("ZE_AFFINITY_MASK={}" .format (test .config .environment ["ZE_AFFINITY_MASK" ]))
290+
286291 if "level_zero:gpu" in sycl_devices and litConfig .params .get ("ur_l0_debug" ):
287292 extra_env .append ("UR_L0_DEBUG={}" .format (test .config .ur_l0_debug ))
288293
@@ -334,14 +339,6 @@ def get_extra_env(sycl_devices):
334339 expanded = "env"
335340
336341 extra_env = get_extra_env ([parsed_dev_name ])
337- backend , device = parsed_dev_name .split (":" , 1 )
338- device_selector = parsed_dev_name
339- if backend == "level_zero" and device .isdigit ():
340- # level_zero:0 maps to a selector for the first GPU, so pin
341- # execution to the requested device via ZE_AFFINITY_MASK.
342- extra_env .append (f"ZE_AFFINITY_MASK={ device } " )
343- device_selector = f"{ backend } :0"
344-
345342 if extra_env :
346343 expanded += " {}" .format (" " .join (extra_env ))
347344
@@ -350,6 +347,12 @@ def get_extra_env(sycl_devices):
350347 elif "level_zero_v1" in full_dev_name :
351348 expanded += " env UR_LOADER_USE_LEVEL_ZERO_V2=0"
352349
350+ # If ZE_AFFINITY_MASK is set, it filters devices so we should use :0
351+ device_selector = parsed_dev_name
352+ if "ZE_AFFINITY_MASK" in test .config .environment :
353+ backend , _ = parsed_dev_name .split (":" , 1 )
354+ device_selector = f"{ backend } :0"
355+
353356 expanded += " ONEAPI_DEVICE_SELECTOR={} {}" .format (
354357 device_selector , test .config .run_launcher
355358 )
0 commit comments