Skip to content

Commit 046f67d

Browse files
authored
[SYCL][E2E] Fix lit for arch selection and l0v2 adapter (#20728)
Fix llvm-lit to enable the simultaneous use of _v1 and _v2 to select the l0 adapter and the use of arch to select the GPU, eg.: `llvm-lit --param "sycl_devices=level_zero_v2:arch-intel_gpu_mtl_u" sycl/test-e2e` Necessary to run tests on integrated GPU on system with another GPU Includes fixed setting of ZE_AFFINITY_MASK in multi-gpu systems --------- Signed-off-by: Mateusz P. Nowak <mateusz.p.nowak@intel.com>
1 parent 303ff44 commit 046f67d

File tree

5 files changed

+55
-6
lines changed

5 files changed

+55
-6
lines changed

sycl/test-e2e/AddressSanitizer/lit.local.cfg

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,5 @@ unsupported_san_flags = [
3131
if any(flag in config.cxx_flags for flag in unsupported_san_flags):
3232
config.unsupported=True
3333

34-
config.environment["ZE_AFFINITY_MASK"] = "0"
34+
if config.ze_affinity_mask is not None:
35+
config.environment["ZE_AFFINITY_MASK"] = config.ze_affinity_mask

sycl/test-e2e/MemorySanitizer/lit.local.cfg

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,5 @@ unsupported_san_flags = [
3939
if any(flag in config.cxx_flags for flag in unsupported_san_flags):
4040
config.unsupported=True
4141

42-
config.environment["ZE_AFFINITY_MASK"] = "0"
42+
if config.ze_affinity_mask is not None:
43+
config.environment["ZE_AFFINITY_MASK"] = config.ze_affinity_mask

sycl/test-e2e/ThreadSanitizer/lit.local.cfg

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,5 @@ unsupported_san_flags = [
3434
if any(flag in config.cxx_flags for flag in unsupported_san_flags):
3535
config.unsupported=True
3636

37-
config.environment["ZE_AFFINITY_MASK"] = "0"
37+
if config.ze_affinity_mask is not None:
38+
config.environment["ZE_AFFINITY_MASK"] = config.ze_affinity_mask

sycl/test-e2e/format.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,15 @@ 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(
290+
"ZE_AFFINITY_MASK={}".format(
291+
test.config.environment["ZE_AFFINITY_MASK"]
292+
)
293+
)
294+
286295
if "level_zero:gpu" in sycl_devices and litConfig.params.get("ur_l0_debug"):
287296
extra_env.append("UR_L0_DEBUG={}".format(test.config.ur_l0_debug))
288297

@@ -342,8 +351,14 @@ def get_extra_env(sycl_devices):
342351
elif "level_zero_v1" in full_dev_name:
343352
expanded += " env UR_LOADER_USE_LEVEL_ZERO_V2=0"
344353

354+
# If ZE_AFFINITY_MASK is set in local config, it filters devices so we should use :0
355+
device_selector = parsed_dev_name
356+
if test.config.ze_affinity_mask is not None:
357+
backend, _ = parsed_dev_name.split(":", 1)
358+
device_selector = f"{backend}:0"
359+
345360
expanded += " ONEAPI_DEVICE_SELECTOR={} {}".format(
346-
parsed_dev_name, test.config.run_launcher
361+
device_selector, test.config.run_launcher
347362
)
348363
cmd = directive.command.replace("%{run}", expanded)
349364
# Expand device-specific condtions (%if ... %{ ... %}).
@@ -353,6 +368,11 @@ def get_extra_env(sycl_devices):
353368
"linux",
354369
"windows",
355370
"preview-breaking-changes-supported",
371+
# the following entries are used by architecture-based filtering
372+
# (:arch- device, not :gpu or :cpu)
373+
"cpu",
374+
"gpu",
375+
"accelerator",
356376
]:
357377
if cond_features in test.config.available_features:
358378
conditions[cond_features] = True

sycl/test-e2e/lit.cfg.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
"LIBCLANG_NOTHREADS",
9797
"LIBCLANG_RESOURCE_USAGE",
9898
"LIBCLANG_CODE_COMPLETION_LOGGING",
99+
"ZE_AFFINITY_MASK",
99100
]
100101

101102
# Names of the Release and Debug versions of the XPTIFW library
@@ -917,12 +918,14 @@ def get_sycl_ls_verbose(sycl_device, env):
917918

918919
env = copy.copy(llvm_config.config.environment)
919920

921+
backend_for_selector = backend.replace("_v2", "").replace("_v1", "")
922+
920923
# Find all available devices under the backend
921-
env["ONEAPI_DEVICE_SELECTOR"] = backend + ":*"
924+
env["ONEAPI_DEVICE_SELECTOR"] = backend_for_selector + ":*"
922925

923926
detected_architectures = []
924927

925-
platform_devices = remove_level_zero_suffix(backend + ":*")
928+
platform_devices = backend_for_selector + ":*"
926929

927930
for line in get_sycl_ls_verbose(platform_devices, env).stdout.splitlines():
928931
if re.match(r" *Architecture:", line):
@@ -948,6 +951,15 @@ def get_sycl_ls_verbose(sycl_device, env):
948951

949952
config.sycl_devices = filtered_sycl_devices
950953

954+
# Determine ZE_AFFINITY_MASK for Level Zero devices.
955+
# Sanitizer tests need to set ZE_AFFINITY_MASK to a single device index
956+
config.ze_affinity_mask = None
957+
for sycl_device in remove_level_zero_suffix(config.sycl_devices):
958+
be, dev = sycl_device.split(":")
959+
if be == "level_zero" and dev.isdigit():
960+
config.ze_affinity_mask = dev
961+
break
962+
951963
for sycl_device in remove_level_zero_suffix(config.sycl_devices):
952964
be, dev = sycl_device.split(":")
953965
config.available_features.add("any-device-is-" + dev)
@@ -1114,6 +1126,13 @@ def get_sycl_ls_verbose(sycl_device, env):
11141126
features.update(device_family)
11151127

11161128
be, dev = sycl_device.split(":")
1129+
if dev.isdigit():
1130+
backend_devices = available_devices.get(be, "gpu")
1131+
if isinstance(backend_devices, tuple):
1132+
# arch-selection is typically used to select gpu device
1133+
dev = "gpu"
1134+
else:
1135+
dev = backend_devices
11171136
features.add(dev.replace("fpga", "accelerator"))
11181137
if "level_zero_v2" in full_name:
11191138
features.add("level_zero_v2_adapter")
@@ -1146,6 +1165,13 @@ def get_sycl_ls_verbose(sycl_device, env):
11461165
else:
11471166
config.intel_driver_ver[full_name] = {}
11481167

1168+
# When running with a single device, merge device-specific features into global
1169+
# available_features so that %if conditionals work correctly, even if device is not :gpu or :cpu
1170+
if len(config.sycl_devices) == 1:
1171+
single_device = list(config.sycl_dev_features.keys())[0]
1172+
device_features = config.sycl_dev_features[single_device]
1173+
config.available_features.update(device_features)
1174+
11491175
if lit_config.params.get("compatibility_testing", "False") != "False":
11501176
config.substitutions.append(("%clangxx", " true "))
11511177
config.substitutions.append(("%clang", " true "))

0 commit comments

Comments
 (0)