From b262dc6f3ff15805b34e6120a51eba210a34bc05 Mon Sep 17 00:00:00 2001 From: "Mateusz P. Nowak" Date: Fri, 21 Nov 2025 15:25:38 +0000 Subject: [PATCH 1/5] fix lit for arch selection and l0v2 adapter --- sycl/test-e2e/format.py | 8 +++++++- sycl/test-e2e/lit.cfg.py | 9 ++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/sycl/test-e2e/format.py b/sycl/test-e2e/format.py index b503108f937b1..68d9fb1763020 100644 --- a/sycl/test-e2e/format.py +++ b/sycl/test-e2e/format.py @@ -334,6 +334,12 @@ def get_extra_env(sycl_devices): expanded = "env" extra_env = get_extra_env([parsed_dev_name]) + backend, device = parsed_dev_name.split(":", 1) + device_selector = parsed_dev_name + if backend == "level_zero" and device.isdigit(): + extra_env.append(f"ZE_AFFINITY_MASK={device}") + device_selector = f"{backend}:0" + if extra_env: expanded += " {}".format(" ".join(extra_env)) @@ -343,7 +349,7 @@ def get_extra_env(sycl_devices): expanded += " env UR_LOADER_USE_LEVEL_ZERO_V2=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..1efd0273d4ab8 100644 --- a/sycl/test-e2e/lit.cfg.py +++ b/sycl/test-e2e/lit.cfg.py @@ -706,7 +706,7 @@ def remove_level_zero_suffix(devices): available_devices = { "opencl": ("cpu", "gpu", "fpga"), "cuda": "gpu", - "level_zero": "gpu", + "level_zero": ("gpu", "0", "1"), "hip": "gpu", "native_cpu": "cpu", "offload": "gpu", @@ -917,12 +917,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): @@ -1112,6 +1114,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")) From 08db888c6c30ef32689aba42210bb368948310ed Mon Sep 17 00:00:00 2001 From: "Mateusz P. Nowak" Date: Mon, 24 Nov 2025 13:14:51 +0000 Subject: [PATCH 2/5] apply comments --- sycl/test-e2e/format.py | 2 ++ sycl/test-e2e/lit.cfg.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/sycl/test-e2e/format.py b/sycl/test-e2e/format.py index 68d9fb1763020..43b2491ce9782 100644 --- a/sycl/test-e2e/format.py +++ b/sycl/test-e2e/format.py @@ -337,6 +337,8 @@ def get_extra_env(sycl_devices): backend, device = parsed_dev_name.split(":", 1) device_selector = parsed_dev_name if backend == "level_zero" and device.isdigit(): + # level_zero:0 maps to a selector for the first GPU, so pin + # execution to the requested device via ZE_AFFINITY_MASK. extra_env.append(f"ZE_AFFINITY_MASK={device}") device_selector = f"{backend}:0" diff --git a/sycl/test-e2e/lit.cfg.py b/sycl/test-e2e/lit.cfg.py index 1efd0273d4ab8..2d15be37e0d2c 100644 --- a/sycl/test-e2e/lit.cfg.py +++ b/sycl/test-e2e/lit.cfg.py @@ -706,7 +706,7 @@ def remove_level_zero_suffix(devices): available_devices = { "opencl": ("cpu", "gpu", "fpga"), "cuda": "gpu", - "level_zero": ("gpu", "0", "1"), + "level_zero": "gpu", "hip": "gpu", "native_cpu": "cpu", "offload": "gpu", From c5fa7266ca7ecfc0a265ba06da9af99a40cfd557 Mon Sep 17 00:00:00 2001 From: "Mateusz P. Nowak" Date: Tue, 25 Nov 2025 12:32:55 +0000 Subject: [PATCH 3/5] fix affinity mask setting Signed-off-by: Mateusz P. Nowak --- sycl/test-e2e/AddressSanitizer/lit.local.cfg | 5 ++++- sycl/test-e2e/MemorySanitizer/lit.local.cfg | 5 ++++- sycl/test-e2e/ThreadSanitizer/lit.local.cfg | 5 ++++- sycl/test-e2e/format.py | 23 +++++++++++++------- sycl/test-e2e/lit.cfg.py | 13 ++++++++--- 5 files changed, 37 insertions(+), 14 deletions(-) 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 43b2491ce9782..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)) @@ -334,14 +343,6 @@ def get_extra_env(sycl_devices): expanded = "env" extra_env = get_extra_env([parsed_dev_name]) - backend, device = parsed_dev_name.split(":", 1) - device_selector = parsed_dev_name - if backend == "level_zero" and device.isdigit(): - # level_zero:0 maps to a selector for the first GPU, so pin - # execution to the requested device via ZE_AFFINITY_MASK. - extra_env.append(f"ZE_AFFINITY_MASK={device}") - device_selector = f"{backend}:0" - if extra_env: expanded += " {}".format(" ".join(extra_env)) @@ -350,6 +351,12 @@ 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( device_selector, test.config.run_launcher ) diff --git a/sycl/test-e2e/lit.cfg.py b/sycl/test-e2e/lit.cfg.py index 2d15be37e0d2c..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 @@ -950,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) From ed8add474236ede0410c80a0cc11227ee07ad498 Mon Sep 17 00:00:00 2001 From: "Mateusz P. Nowak" Date: Tue, 25 Nov 2025 13:51:01 +0000 Subject: [PATCH 4/5] some features were missing when using arch-based selection --- sycl/test-e2e/format.py | 5 +++++ sycl/test-e2e/lit.cfg.py | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/sycl/test-e2e/format.py b/sycl/test-e2e/format.py index 2cb52e6bd5469..f3c1b7118a34d 100644 --- a/sycl/test-e2e/format.py +++ b/sycl/test-e2e/format.py @@ -368,6 +368,11 @@ def get_extra_env(sycl_devices): "linux", "windows", "preview-breaking-changes-supported", + # the following entries are used by architecture-based filtering + # (:arch- device, not :gpu or :cpu) + "cpu", + "gpu", + "accelerator", ]: if cond_features in test.config.available_features: conditions[cond_features] = True diff --git a/sycl/test-e2e/lit.cfg.py b/sycl/test-e2e/lit.cfg.py index 9f271aae2d9cd..57bcea865448d 100644 --- a/sycl/test-e2e/lit.cfg.py +++ b/sycl/test-e2e/lit.cfg.py @@ -1156,6 +1156,13 @@ def get_sycl_ls_verbose(sycl_device, env): else: config.intel_driver_ver[full_name] = {} +# When running with a single device, merge device-specific features into global +# available_features so that %if conditionals work correctly, even if device is not :gpu or :cpu +if len(config.sycl_devices) == 1: + single_device = list(config.sycl_dev_features.keys())[0] + device_features = config.sycl_dev_features[single_device] + config.available_features.update(device_features) + if lit_config.params.get("compatibility_testing", "False") != "False": config.substitutions.append(("%clangxx", " true ")) config.substitutions.append(("%clang", " true ")) From 770fe63c360701d215809876cc73cebc3cd1362e Mon Sep 17 00:00:00 2001 From: "Mateusz P. Nowak" Date: Wed, 26 Nov 2025 14:44:56 +0000 Subject: [PATCH 5/5] apply comments Signed-off-by: Mateusz P. Nowak --- sycl/test-e2e/AddressSanitizer/lit.local.cfg | 4 +--- sycl/test-e2e/MemorySanitizer/lit.local.cfg | 4 +--- sycl/test-e2e/ThreadSanitizer/lit.local.cfg | 4 +--- sycl/test-e2e/format.py | 4 ++-- sycl/test-e2e/lit.cfg.py | 17 +++++++++++++---- 5 files changed, 18 insertions(+), 15 deletions(-) diff --git a/sycl/test-e2e/AddressSanitizer/lit.local.cfg b/sycl/test-e2e/AddressSanitizer/lit.local.cfg index 46e3e7fe9bf1e..fc485cd8672d1 100644 --- a/sycl/test-e2e/AddressSanitizer/lit.local.cfg +++ b/sycl/test-e2e/AddressSanitizer/lit.local.cfg @@ -31,7 +31,5 @@ unsupported_san_flags = [ if any(flag in config.cxx_flags for flag in unsupported_san_flags): config.unsupported=True -if hasattr(config, 'ze_affinity_mask') and config.ze_affinity_mask is not None: +if 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 0af20d640d932..3f0995818cefd 100644 --- a/sycl/test-e2e/MemorySanitizer/lit.local.cfg +++ b/sycl/test-e2e/MemorySanitizer/lit.local.cfg @@ -39,7 +39,5 @@ unsupported_san_flags = [ if any(flag in config.cxx_flags for flag in unsupported_san_flags): config.unsupported=True -if hasattr(config, 'ze_affinity_mask') and config.ze_affinity_mask is not None: +if 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 a4500c5d13153..c992b46250e98 100644 --- a/sycl/test-e2e/ThreadSanitizer/lit.local.cfg +++ b/sycl/test-e2e/ThreadSanitizer/lit.local.cfg @@ -34,7 +34,5 @@ unsupported_san_flags = [ if any(flag in config.cxx_flags for flag in unsupported_san_flags): config.unsupported=True -if hasattr(config, 'ze_affinity_mask') and config.ze_affinity_mask is not None: +if 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 f3c1b7118a34d..d6c390a7e4407 100644 --- a/sycl/test-e2e/format.py +++ b/sycl/test-e2e/format.py @@ -351,9 +351,9 @@ 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 + # If ZE_AFFINITY_MASK is set in local config, it filters devices so we should use :0 device_selector = parsed_dev_name - if "ZE_AFFINITY_MASK" in test.config.environment: + if test.config.ze_affinity_mask is not None: backend, _ = parsed_dev_name.split(":", 1) device_selector = f"{backend}:0" diff --git a/sycl/test-e2e/lit.cfg.py b/sycl/test-e2e/lit.cfg.py index 57bcea865448d..da4cc3465ca4e 100644 --- a/sycl/test-e2e/lit.cfg.py +++ b/sycl/test-e2e/lit.cfg.py @@ -9,6 +9,9 @@ import shlex import shutil +import lit.formats +import lit.util + from lit.llvm import llvm_config from lit.llvm.subst import ToolSubst, FindTool @@ -93,6 +96,7 @@ "LIBCLANG_NOTHREADS", "LIBCLANG_RESOURCE_USAGE", "LIBCLANG_CODE_COMPLETION_LOGGING", + "ZE_AFFINITY_MASK", ] # Names of the Release and Debug versions of the XPTIFW library @@ -953,9 +957,8 @@ def get_sycl_ls_verbose(sycl_device, env): 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 + config.ze_affinity_mask = dev + break for sycl_device in remove_level_zero_suffix(config.sycl_devices): be, dev = sycl_device.split(":") @@ -1121,9 +1124,15 @@ 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(":") + if dev.isdigit(): + backend_devices = available_devices.get(be, "gpu") + if isinstance(backend_devices, tuple): + # arch-selection is typically used to select gpu device + dev = "gpu" + else: + dev = backend_devices features.add(dev.replace("fpga", "accelerator")) if "level_zero_v2" in full_name: features.add("level_zero_v2_adapter")