From 39c9cad5719f6992af21c67d96a6d36419f1b110 Mon Sep 17 00:00:00 2001 From: Ranjan Sarpangala Venkatesh Date: Tue, 24 Mar 2026 15:17:15 -0700 Subject: [PATCH 1/4] Fix bug 5811173: update cufile tests and configuration test_cufile.py: skip compat bool params in set_get_parameter_bool Avoid setting allow_compat_mode/force_compat_mode before driver_open; pending values can be applied on first open and interact badly with cufile.json when nvidia-fs is not loaded (DRIVER_NOT_INITIALIZED). Compat behavior remains covered elsewhere. cufile.json: Set allow_compat_mode to true --- cuda_bindings/tests/cufile.json | 4 ++++ cuda_bindings/tests/test_cufile.py | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/cuda_bindings/tests/cufile.json b/cuda_bindings/tests/cufile.json index 36b3b9bd722..21ab1f3b6bb 100644 --- a/cuda_bindings/tests/cufile.json +++ b/cuda_bindings/tests/cufile.json @@ -3,6 +3,10 @@ // e.g : export CUFILE_ENV_PATH_JSON="/home//cufile.json" + "properties" : { + "allow_compat_mode" : true + }, + "execution" : { // max number of workitems in the queue; "max_io_queue_depth": 128, diff --git a/cuda_bindings/tests/test_cufile.py b/cuda_bindings/tests/test_cufile.py index a4400f637a3..787c59c178c 100644 --- a/cuda_bindings/tests/test_cufile.py +++ b/cuda_bindings/tests/test_cufile.py @@ -1412,6 +1412,14 @@ def test_param(param, val): @pytest.mark.usefixtures("ctx") def test_set_get_parameter_bool(): """Test setting and getting boolean parameters with cuFile validation.""" + # Do not exercise allow/force compat via set_parameter_bool before any driver_open: + # pending API values are applied after JSON load on first open and can overwrite + # cufile.json (e.g. allow_compat_mode: true), causing DRIVER_NOT_INITIALIZED when + # nvidia-fs is not loaded. Other tests cover compat behavior where appropriate. + _COMPAT_PARAMS = ( + cufile.BoolConfigParameter.PROPERTIES_ALLOW_COMPAT_MODE, + cufile.BoolConfigParameter.FORCE_COMPAT_MODE, + ) param_val_pairs = ( (cufile.BoolConfigParameter.PROPERTIES_USE_POLL_MODE, True), (cufile.BoolConfigParameter.PROPERTIES_ALLOW_COMPAT_MODE, False), @@ -1426,6 +1434,7 @@ def test_set_get_parameter_bool(): (cufile.BoolConfigParameter.SKIP_TOPOLOGY_DETECTION, False), (cufile.BoolConfigParameter.STREAM_MEMOPS_BYPASS, True), ) + param_val_pairs = tuple((p, v) for p, v in param_val_pairs if p not in _COMPAT_PARAMS) def test_param(param, val): orig_val = cufile.get_parameter_bool(param) From 1b513d5201cce619d1c8f8115a894b93a15a6fd1 Mon Sep 17 00:00:00 2001 From: Ranjan Sarpangala Venkatesh Date: Tue, 14 Apr 2026 12:04:53 -0700 Subject: [PATCH 2/4] cufile tests: snapshot parameter baselines after driver_open Open driver once to read size_t/bool/string originals, then close before set/get/restore round-trips so pending does not restore invalid pre-open values (e.g. per-buffer cache 0). Aligns with review feedback. --- cuda_bindings/tests/test_cufile.py | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/cuda_bindings/tests/test_cufile.py b/cuda_bindings/tests/test_cufile.py index 787c59c178c..64b4b8539a9 100644 --- a/cuda_bindings/tests/test_cufile.py +++ b/cuda_bindings/tests/test_cufile.py @@ -1394,8 +1394,16 @@ def test_set_get_parameter_size_t(): (cufile.SizeTConfigParameter.EXECUTION_MAX_REQUEST_PARALLELISM, 4), # Max 4 parallel requests ) + # Snapshot baselines after driver_open so getters reflect merged config (defaults + JSON), + # not pre-open pending state that could restore invalid values (e.g. 0 for per-buffer cache). + cufile.driver_open() + try: + originals = {param: cufile.get_parameter_size_t(param) for param, _ in param_val_pairs} + finally: + cufile.driver_close() + def test_param(param, val): - orig_val = cufile.get_parameter_size_t(param) + orig_val = originals[param] cufile.set_parameter_size_t(param, val) retrieved_val = cufile.get_parameter_size_t(param) assert retrieved_val == val @@ -1436,8 +1444,14 @@ def test_set_get_parameter_bool(): ) param_val_pairs = tuple((p, v) for p, v in param_val_pairs if p not in _COMPAT_PARAMS) + cufile.driver_open() + try: + originals = {param: cufile.get_parameter_bool(param) for param, _ in param_val_pairs} + finally: + cufile.driver_close() + def test_param(param, val): - orig_val = cufile.get_parameter_bool(param) + orig_val = originals[param] cufile.set_parameter_bool(param, val) retrieved_val = cufile.get_parameter_bool(param) assert retrieved_val is val @@ -1477,8 +1491,14 @@ def test_set_get_parameter_string(tmp_path): ), # Test log directory ) + cufile.driver_open() + try: + originals = {param: cufile.get_parameter_string(param, 256) for param, _, _ in param_val_pairs} + finally: + cufile.driver_close() + def test_param(param, val, default_val): - orig_val = cufile.get_parameter_string(param, 256) + orig_val = originals[param] val_b = val.encode("utf-8") val_buf = ctypes.create_string_buffer(val_b) From c4619455b83d383321c7cd1798b6b2f5c8da3923 Mon Sep 17 00:00:00 2001 From: Ranjan Sarpangala Venkatesh Date: Tue, 5 May 2026 15:17:26 -0700 Subject: [PATCH 3/4] test(cufile): skip PROFILE_NVTX in bool param snapshot on cuFile >= 1.16 --- cuda_bindings/tests/test_cufile.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/cuda_bindings/tests/test_cufile.py b/cuda_bindings/tests/test_cufile.py index 64b4b8539a9..fa3f4b02d2d 100644 --- a/cuda_bindings/tests/test_cufile.py +++ b/cuda_bindings/tests/test_cufile.py @@ -1443,6 +1443,11 @@ def test_set_get_parameter_bool(): (cufile.BoolConfigParameter.STREAM_MEMOPS_BYPASS, True), ) param_val_pairs = tuple((p, v) for p, v in param_val_pairs if p not in _COMPAT_PARAMS) + # PROFILE_NVTX is deprecated (CTK 13.1.0+); cuFile >= 1.16 rejects bool getters for it. + if cufile.get_version() >= 1160: + param_val_pairs = tuple( + (p, v) for p, v in param_val_pairs if p is not cufile.BoolConfigParameter.PROFILE_NVTX + ) cufile.driver_open() try: @@ -1457,14 +1462,9 @@ def test_param(param, val): assert retrieved_val is val cufile.set_parameter_bool(param, orig_val) - try: - # Test setting and getting various boolean parameters - for param, val in param_val_pairs: - test_param(param, val) - except cufile.cuFileError: - if cufile.get_version() < 1160: - raise - assert param is cufile.BoolConfigParameter.PROFILE_NVTX # Deprecated in CTK 13.1.0 + # Test setting and getting various boolean parameters + for param, val in param_val_pairs: + test_param(param, val) @pytest.mark.skipif( From 7c9913a3c885894a5fc6b70ba7949f4161b77812 Mon Sep 17 00:00:00 2001 From: Ranjan Sarpangala Venkatesh Date: Tue, 5 May 2026 16:28:35 -0700 Subject: [PATCH 4/4] test(cufile): factor driver open/close into _cufile_driver_session context manager --- cuda_bindings/tests/test_cufile.py | 32 ++++++++++++++---------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/cuda_bindings/tests/test_cufile.py b/cuda_bindings/tests/test_cufile.py index fa3f4b02d2d..70a7bc80c87 100644 --- a/cuda_bindings/tests/test_cufile.py +++ b/cuda_bindings/tests/test_cufile.py @@ -9,7 +9,7 @@ import platform import subprocess import tempfile -from contextlib import suppress +from contextlib import contextmanager, suppress from functools import cache import pytest @@ -28,6 +28,16 @@ cufile = pytest.importorskip("cuda.bindings.cufile", reason="skipping tests on Windows") +@contextmanager +def _cufile_driver_session(): + """Open the cuFile driver for a block; always close in a finally (mirrors try/finally).""" + cufile.driver_open() + try: + yield + finally: + cufile.driver_close() + + @pytest.fixture def cufile_env_json(monkeypatch): """Set CUFILE_ENV_PATH_JSON environment variable for async tests.""" @@ -1396,11 +1406,8 @@ def test_set_get_parameter_size_t(): # Snapshot baselines after driver_open so getters reflect merged config (defaults + JSON), # not pre-open pending state that could restore invalid values (e.g. 0 for per-buffer cache). - cufile.driver_open() - try: + with _cufile_driver_session(): originals = {param: cufile.get_parameter_size_t(param) for param, _ in param_val_pairs} - finally: - cufile.driver_close() def test_param(param, val): orig_val = originals[param] @@ -1449,11 +1456,8 @@ def test_set_get_parameter_bool(): (p, v) for p, v in param_val_pairs if p is not cufile.BoolConfigParameter.PROFILE_NVTX ) - cufile.driver_open() - try: + with _cufile_driver_session(): originals = {param: cufile.get_parameter_bool(param) for param, _ in param_val_pairs} - finally: - cufile.driver_close() def test_param(param, val): orig_val = originals[param] @@ -1491,11 +1495,8 @@ def test_set_get_parameter_string(tmp_path): ), # Test log directory ) - cufile.driver_open() - try: + with _cufile_driver_session(): originals = {param: cufile.get_parameter_string(param, 256) for param, _, _ in param_val_pairs} - finally: - cufile.driver_close() def test_param(param, val, default_val): orig_val = originals[param] @@ -1937,11 +1938,8 @@ def test_set_parameter_posix_pool_slab_array(slab_sizes, slab_counts, driver_con retrieved_counts_addr = ctypes.addressof(retrieved_counts) # Open cuFile driver AFTER setting parameters - cufile.driver_open() - try: + with _cufile_driver_session(): cufile.get_parameter_posix_pool_slab_array(retrieved_sizes_addr, retrieved_counts_addr, n_slab_sizes) - finally: - cufile.driver_close() # Verify they match what we set assert list(retrieved_sizes) == slab_sizes