diff --git a/sycl/test-e2e/AddressSanitizer/lit.local.cfg b/sycl/test-e2e/AddressSanitizer/lit.local.cfg index 2c460b824422d..46e3e7fe9bf1e 100644 --- a/sycl/test-e2e/AddressSanitizer/lit.local.cfg +++ b/sycl/test-e2e/AddressSanitizer/lit.local.cfg @@ -31,4 +31,7 @@ unsupported_san_flags = [ if any(flag in config.cxx_flags for flag in unsupported_san_flags): config.unsupported=True -config.environment["ZE_AFFINITY_MASK"] = "0" +if hasattr(config, 'ze_affinity_mask') and config.ze_affinity_mask is not None: + config.environment["ZE_AFFINITY_MASK"] = config.ze_affinity_mask +else: + config.environment["ZE_AFFINITY_MASK"] = "0" diff --git a/sycl/test-e2e/MemorySanitizer/lit.local.cfg b/sycl/test-e2e/MemorySanitizer/lit.local.cfg index 8b643a2c4abbc..0af20d640d932 100644 --- a/sycl/test-e2e/MemorySanitizer/lit.local.cfg +++ b/sycl/test-e2e/MemorySanitizer/lit.local.cfg @@ -39,4 +39,7 @@ unsupported_san_flags = [ if any(flag in config.cxx_flags for flag in unsupported_san_flags): config.unsupported=True -config.environment["ZE_AFFINITY_MASK"] = "0" +if hasattr(config, 'ze_affinity_mask') and config.ze_affinity_mask is not None: + config.environment["ZE_AFFINITY_MASK"] = config.ze_affinity_mask +else: + config.environment["ZE_AFFINITY_MASK"] = "0" diff --git a/sycl/test-e2e/ThreadSanitizer/lit.local.cfg b/sycl/test-e2e/ThreadSanitizer/lit.local.cfg index 63a387034a132..a4500c5d13153 100644 --- a/sycl/test-e2e/ThreadSanitizer/lit.local.cfg +++ b/sycl/test-e2e/ThreadSanitizer/lit.local.cfg @@ -34,4 +34,7 @@ unsupported_san_flags = [ if any(flag in config.cxx_flags for flag in unsupported_san_flags): config.unsupported=True -config.environment["ZE_AFFINITY_MASK"] = "0" +if hasattr(config, 'ze_affinity_mask') and config.ze_affinity_mask is not None: + config.environment["ZE_AFFINITY_MASK"] = config.ze_affinity_mask +else: + config.environment["ZE_AFFINITY_MASK"] = "0" diff --git a/sycl/test-e2e/format.py b/sycl/test-e2e/format.py index b503108f937b1..2cb52e6bd5469 100644 --- a/sycl/test-e2e/format.py +++ b/sycl/test-e2e/format.py @@ -283,6 +283,15 @@ def get_extra_env(sycl_devices): # so that device might still be accessible to some of the tests yet # we won't set the environment variable below for such scenario. extra_env = [] + + # Include ZE_AFFINITY_MASK if set by lit.local.cfg (e.g., for sanitizer tests) + if "ZE_AFFINITY_MASK" in test.config.environment: + extra_env.append( + "ZE_AFFINITY_MASK={}".format( + test.config.environment["ZE_AFFINITY_MASK"] + ) + ) + if "level_zero:gpu" in sycl_devices and litConfig.params.get("ur_l0_debug"): extra_env.append("UR_L0_DEBUG={}".format(test.config.ur_l0_debug)) @@ -342,8 +351,14 @@ def get_extra_env(sycl_devices): elif "level_zero_v1" in full_dev_name: expanded += " env UR_LOADER_USE_LEVEL_ZERO_V2=0" + # If ZE_AFFINITY_MASK is set, it filters devices so we should use :0 + device_selector = parsed_dev_name + if "ZE_AFFINITY_MASK" in test.config.environment: + backend, _ = parsed_dev_name.split(":", 1) + device_selector = f"{backend}:0" + expanded += " ONEAPI_DEVICE_SELECTOR={} {}".format( - parsed_dev_name, test.config.run_launcher + device_selector, test.config.run_launcher ) cmd = directive.command.replace("%{run}", expanded) # Expand device-specific condtions (%if ... %{ ... %}). diff --git a/sycl/test-e2e/lit.cfg.py b/sycl/test-e2e/lit.cfg.py index d39cd7134e603..9f271aae2d9cd 100644 --- a/sycl/test-e2e/lit.cfg.py +++ b/sycl/test-e2e/lit.cfg.py @@ -9,9 +9,6 @@ import shlex import shutil -import lit.formats -import lit.util - from lit.llvm import llvm_config from lit.llvm.subst import ToolSubst, FindTool @@ -917,12 +914,14 @@ def get_sycl_ls_verbose(sycl_device, env): env = copy.copy(llvm_config.config.environment) + backend_for_selector = backend.replace("_v2", "").replace("_v1", "") + # Find all available devices under the backend - env["ONEAPI_DEVICE_SELECTOR"] = backend + ":*" + env["ONEAPI_DEVICE_SELECTOR"] = backend_for_selector + ":*" detected_architectures = [] - platform_devices = remove_level_zero_suffix(backend + ":*") + platform_devices = backend_for_selector + ":*" for line in get_sycl_ls_verbose(platform_devices, env).stdout.splitlines(): if re.match(r" *Architecture:", line): @@ -948,6 +947,16 @@ def get_sycl_ls_verbose(sycl_device, env): config.sycl_devices = filtered_sycl_devices +# Determine ZE_AFFINITY_MASK for Level Zero devices. +# Sanitizer tests need to set ZE_AFFINITY_MASK to a single device index +config.ze_affinity_mask = None +for sycl_device in remove_level_zero_suffix(config.sycl_devices): + be, dev = sycl_device.split(":") + if be == "level_zero" and dev.isdigit(): + if config.ze_affinity_mask is None: + config.ze_affinity_mask = dev + break + for sycl_device in remove_level_zero_suffix(config.sycl_devices): be, dev = sycl_device.split(":") config.available_features.add("any-device-is-" + dev) @@ -1112,6 +1121,7 @@ def get_sycl_ls_verbose(sycl_device, env): features.update(sg_size_features) features.update(architecture_feature) features.update(device_family) + features.update(aspects) be, dev = sycl_device.split(":") features.add(dev.replace("fpga", "accelerator"))