Skip to content

Commit 9a9f422

Browse files
authored
Arm backend: Enable lifetime validation in VGF tests. (pytorch#23415)
- Explicitly enable VVL object-lifetime/core validation for VGF tests. - Add one intentional lifetime-VUID probe. - Keep using the existing validation wrapper. - Run it in the existing VGF GitHub CI. cc @digantdesai @freddan80 @per @zingo @oscarandersson8218 @mansnils @Sebastian-Larsson @robell @rascani Signed-off-by: Elena Zhelezina <elena.zhelezina@arm.com>
1 parent ab907e0 commit 9a9f422

5 files changed

Lines changed: 103 additions & 1 deletion

File tree

‎backends/arm/test/conftest.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ def enable_vulkan_validation_for_vgf_tests(request, monkeypatch) -> None:
184184
"VK_KHRONOS_VALIDATION_LOG_FILENAME",
185185
"VK_KHRONOS_VALIDATION_DEBUG_ACTION",
186186
runner_utils.VULKAN_VALIDATION_MESSAGE_FILTER_ENV,
187+
runner_utils.VULKAN_VALIDATION_OBJECT_LIFETIME_ENV,
188+
runner_utils.VULKAN_VALIDATION_CORE_ENV,
187189
):
188190
value = configured_env.get(variable)
189191
if value is not None:

‎backends/arm/test/misc/test_vulkan_validation_layer.py‎

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
_VALIDATION_LAYER = "VK_LAYER_KHRONOS_validation"
1818
_VALIDATION_ENV = "EXECUTORCH_VGF_VULKAN_VALIDATION"
1919
_EXPECTED_VUID = "VUID-VkApplicationInfo-sType-sType"
20-
2120
# We check that validation layer is enabled.
2221
# Run the actual Vulkan call in a child process so loading Vulkan/VVL does not
2322
# modify the pytest process.
@@ -339,6 +338,90 @@ def test_vgf_validation_wrapper_fails_on_validation_error():
339338
)
340339

341340

341+
def test_vgf_validation_wrapper_enables_object_lifetime_checks():
342+
"""Lifetime/core validation must be enabled without leaking Vulkan
343+
objects.
344+
"""
345+
346+
if not _env_flag_enabled(_VALIDATION_ENV):
347+
pytest.skip(f"{_VALIDATION_ENV} is not enabled for this test run")
348+
349+
expected_settings = {
350+
"VK_LAYER_OBJECT_LIFETIME": "1",
351+
"VK_LAYER_VALIDATE_CORE": "1",
352+
}
353+
354+
# Verify the pytest/runner configuration first. This checks that
355+
# runner_utils._enable_vulkan_validation() and the autouse fixture propagate
356+
# the settings into VGF tests.
357+
for name, expected in expected_settings.items():
358+
assert os.environ.get(name) == expected, (
359+
f"VGF Vulkan validation is enabled, but {name} is not explicitly "
360+
f"enabled. Expected {name}={expected}."
361+
)
362+
363+
validation_wrapper = (
364+
Path(__file__).resolve().parents[1] / "run_with_vulkan_validation.sh"
365+
)
366+
367+
if not validation_wrapper.is_file():
368+
pytest.skip(
369+
"Vulkan validation shell wrapper is not available in this "
370+
"test environment"
371+
)
372+
373+
env = os.environ.copy()
374+
env[_VALIDATION_ENV] = "1"
375+
376+
# Remove the inherited values so this child verifies that the wrapper
377+
# itself exports the settings. No Vulkan object is created by this probe.
378+
for name in expected_settings:
379+
env.pop(name, None)
380+
381+
settings_probe = """\
382+
import os
383+
384+
settings = (
385+
"VK_LAYER_OBJECT_LIFETIME",
386+
"VK_LAYER_VALIDATE_CORE",
387+
)
388+
389+
for name in settings:
390+
value = os.environ.get(name)
391+
print(f"{name}={value}")
392+
if value != "1":
393+
raise SystemExit(f"{name} must be 1, got {value!r}")
394+
"""
395+
396+
result = subprocess.run( # nosec B603
397+
[
398+
str(validation_wrapper),
399+
sys.executable,
400+
"-c",
401+
settings_probe,
402+
],
403+
env=env,
404+
check=False,
405+
capture_output=True,
406+
text=True,
407+
timeout=30,
408+
)
409+
410+
assert result.returncode == 0, (
411+
"The Vulkan validation wrapper did not propagate the explicit "
412+
"object-lifetime/core validation settings.\n\n"
413+
f"stdout:\n{result.stdout}\n\n"
414+
f"stderr:\n{result.stderr}"
415+
)
416+
417+
for name, expected in expected_settings.items():
418+
assert f"{name}={expected}" in result.stdout, (
419+
f"The wrapper child did not observe {name}={expected}.\n\n"
420+
f"stdout:\n{result.stdout}\n\n"
421+
f"stderr:\n{result.stderr}"
422+
)
423+
424+
342425
def test_vgf_validation_wrapper_preserves_error_from_earlier_vulkan_child():
343426
"""A later clean Vulkan child must not erase an earlier validation error."""
344427

‎backends/arm/test/run_with_vulkan_validation.sh‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ export VK_KHRONOS_VALIDATION_REPORT_FLAGS="error"
5555
export VK_KHRONOS_VALIDATION_DEBUG_ACTION="VK_DBG_LAYER_ACTION_LOG_MSG"
5656
export VK_KHRONOS_VALIDATION_LOG_FILENAME="stdout"
5757

58+
# Make the lifetime contract explicit for every command using this wrapper.
59+
export VK_LAYER_OBJECT_LIFETIME="1"
60+
export VK_LAYER_VALIDATE_CORE="1"
61+
5862

5963
# Keep normal command output visible in CI while retaining a copy that can be
6064
# inspected as a fallback. PIPESTATUS[0] is the status of the command, not tee.

‎backends/arm/test/runner_utils.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ def _get_qdq_memory_format_ops() -> tuple[object, ...]:
114114
VULKAN_VALIDATION_LAYER = "VK_LAYER_KHRONOS_validation"
115115
VULKAN_VALIDATION_ENV = "EXECUTORCH_VGF_VULKAN_VALIDATION"
116116
VULKAN_VALIDATION_MESSAGE_FILTER_ENV = "VK_LAYER_MESSAGE_ID_FILTER"
117+
VULKAN_VALIDATION_OBJECT_LIFETIME_ENV = "VK_LAYER_OBJECT_LIFETIME"
118+
VULKAN_VALIDATION_CORE_ENV = "VK_LAYER_VALIDATE_CORE"
117119

118120
# Temporary VKML workaround: BF16 shaders execute, but VKML currently
119121
# does not advertise VK_KHR_shader_bfloat16/shaderBFloat16Type.
@@ -862,6 +864,11 @@ def _enable_vulkan_validation(env: dict[str, str]) -> dict[str, str]:
862864
"stdout",
863865
)
864866

867+
# Keep VGF's lifetime-validation contract explicit rather than relying on
868+
# the current Validation Layer defaults.
869+
env[VULKAN_VALIDATION_OBJECT_LIFETIME_ENV] = "1"
870+
env[VULKAN_VALIDATION_CORE_ENV] = "1"
871+
865872
logger.info(
866873
"Vulkan validation enabled for VKML runtime: %s",
867874
env["VK_INSTANCE_LAYERS"],

‎backends/arm/test/test_arm_backend.sh‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ enable_vgf_vulkan_validation() {
7474
export VK_KHRONOS_VALIDATION_LOG_FILENAME="stdout"
7575
export VK_KHRONOS_VALIDATION_DEBUG_ACTION="VK_DBG_LAYER_ACTION_LOG_MSG"
7676

77+
# Keep object-lifetime and core validation explicit. They are enabled by
78+
# default by current VVL releases, but VGF lifetime coverage should not
79+
# depend on an implicit SDK default.
80+
export VK_LAYER_OBJECT_LIFETIME="1"
81+
export VK_LAYER_VALIDATE_CORE="1"
82+
7783
# Temporary workarounds for known VKML / Model Converter validation
7884
# defects. Keep validation enabled, but mute only these tracked VUIDs.
7985
#

0 commit comments

Comments
 (0)