Skip to content

Commit 3bbaef5

Browse files
committed
fix affinity mask setting
Signed-off-by: Mateusz P. Nowak <[email protected]>
1 parent 08db888 commit 3bbaef5

File tree

5 files changed

+35
-14
lines changed

5 files changed

+35
-14
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,7 @@ 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 hasattr(config, 'ze_affinity_mask') and config.ze_affinity_mask is not None:
35+
config.environment["ZE_AFFINITY_MASK"] = config.ze_affinity_mask
36+
else:
37+
config.environment["ZE_AFFINITY_MASK"] = "0"

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,9 @@ 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+
# Set ZE_AFFINITY_MASK for single-GPU execution (required by device sanitizer).
43+
# Use the first Level Zero GPU device number if available, otherwise default to "0".
44+
if hasattr(config, 'ze_affinity_mask') and config.ze_affinity_mask is not None:
45+
config.environment["ZE_AFFINITY_MASK"] = config.ze_affinity_mask
46+
else:
47+
config.environment["ZE_AFFINITY_MASK"] = "0"

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,7 @@ 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 hasattr(config, 'ze_affinity_mask') and config.ze_affinity_mask is not None:
38+
config.environment["ZE_AFFINITY_MASK"] = config.ze_affinity_mask
39+
else:
40+
config.environment["ZE_AFFINITY_MASK"] = "0"

sycl/test-e2e/format.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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_d ev_name.split(":", 1)
354+
device_selector = f"{backend}:0"
355+
353356
expanded += " ONEAPI_DEVICE_SELECTOR={} {}".format(
354357
device_selector, test.config.run_launcher
355358
)

sycl/test-e2e/lit.cfg.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
import shlex
1010
import shutil
1111

12-
import lit.formats
13-
import lit.util
14-
1512
from lit.llvm import llvm_config
1613
from lit.llvm.subst import ToolSubst, FindTool
1714

@@ -950,6 +947,16 @@ def get_sycl_ls_verbose(sycl_device, env):
950947

951948
config.sycl_devices = filtered_sycl_devices
952949

950+
# Determine ZE_AFFINITY_MASK for Level Zero devices.
951+
# Sanitizer tests need to set ZE_AFFINITY_MASK to a single device index
952+
config.ze_affinity_mask = None
953+
for sycl_device in remove_level_zero_suffix(config.sycl_devices):
954+
be, dev = sycl_device.split(":")
955+
if be == "level_zero" and dev.isdigit():
956+
if config.ze_affinity_mask is None:
957+
config.ze_affinity_mask = dev
958+
break
959+
953960
for sycl_device in remove_level_zero_suffix(config.sycl_devices):
954961
be, dev = sycl_device.split(":")
955962
config.available_features.add("any-device-is-" + dev)

0 commit comments

Comments
 (0)