Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cuda_bindings/tests/cufile.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
// e.g : export CUFILE_ENV_PATH_JSON="/home/<xxx>/cufile.json"


"properties" : {
"allow_compat_mode" : true
},

"execution" : {
// max number of workitems in the queue;
"max_io_queue_depth": 128,
Expand Down
59 changes: 43 additions & 16 deletions cuda_bindings/tests/test_cufile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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."""
Expand Down Expand Up @@ -1394,8 +1404,13 @@ 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).
with _cufile_driver_session():
originals = {param: cufile.get_parameter_size_t(param) for param, _ in param_val_pairs}

Comment thread
rsarpangalav marked this conversation as resolved.
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
Expand All @@ -1412,6 +1427,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),
Expand All @@ -1426,22 +1449,26 @@ 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)
# 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
)

with _cufile_driver_session():
originals = {param: cufile.get_parameter_bool(param) for param, _ in param_val_pairs}

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
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(
Expand All @@ -1468,8 +1495,11 @@ def test_set_get_parameter_string(tmp_path):
), # Test log directory
)

with _cufile_driver_session():
originals = {param: cufile.get_parameter_string(param, 256) for param, _, _ in param_val_pairs}

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)
Expand Down Expand Up @@ -1908,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
Expand Down