Skip to content

Commit ffe71b5

Browse files
committed
fmt
1 parent ef73d2e commit ffe71b5

1 file changed

Lines changed: 59 additions & 29 deletions

File tree

cuda_bindings/tests/test_cufile.py

Lines changed: 59 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
import tempfile
1111
from contextlib import suppress
1212
from functools import cache
13-
import pytest
13+
1414
import cuda.bindings.driver as cuda
15+
import pytest
1516

1617
# Configure logging to show INFO level and above
1718
logging.basicConfig(
@@ -117,6 +118,8 @@ def isSupportedFilesystem():
117118

118119
# Global skip condition for all tests if cuFile library is not available
119120
pytestmark = pytest.mark.skipif(not cufileLibraryAvailable(), reason="cuFile library not available on this system")
121+
122+
120123
def safe_decode_string(raw_value):
121124
"""Safely decode a string value from ctypes buffer."""
122125
# Find null terminator if present
@@ -1412,6 +1415,7 @@ def test_batch_io_cancel():
14121415
cufile.driver_close()
14131416
cuda.cuDevicePrimaryCtxRelease(device)
14141417

1418+
14151419
@pytest.mark.skipif(not isSupportedFilesystem(), reason="cuFile handle_register requires ext4 or xfs filesystem")
14161420
def test_batch_io_large_operations():
14171421
"""Test batch IO with large buffer operations."""
@@ -1515,15 +1519,16 @@ def test_batch_io_large_operations():
15151519
nr_completed_writes = ctypes.c_uint(num_operations)
15161520
timeout = ctypes.c_int(10000)
15171521
cufile.batch_io_get_status(
1518-
batch_handle, num_operations, ctypes.addressof(nr_completed_writes),
1519-
io_events.ptr, ctypes.addressof(timeout)
1522+
batch_handle,
1523+
num_operations,
1524+
ctypes.addressof(nr_completed_writes),
1525+
io_events.ptr,
1526+
ctypes.addressof(timeout),
15201527
)
15211528

15221529
# Verify writes succeeded
15231530
for i in range(nr_completed_writes.value):
1524-
assert io_events[i].status == cufile.Status.COMPLETE, (
1525-
f"Write {i} failed with status {io_events[i].status}"
1526-
)
1531+
assert io_events[i].status == cufile.Status.COMPLETE, f"Write {i} failed with status {io_events[i].status}"
15271532

15281533
# Force file sync
15291534
os.fsync(fd)
@@ -1553,14 +1558,15 @@ def test_batch_io_large_operations():
15531558
# Wait for reads
15541559
nr_completed = ctypes.c_uint(num_operations)
15551560
cufile.batch_io_get_status(
1556-
read_batch_handle, num_operations, ctypes.addressof(nr_completed),
1557-
read_io_events.ptr, ctypes.addressof(timeout)
1561+
read_batch_handle,
1562+
num_operations,
1563+
ctypes.addressof(nr_completed),
1564+
read_io_events.ptr,
1565+
ctypes.addressof(timeout),
15581566
)
15591567

15601568
# Verify all operations completed successfully
1561-
assert nr_completed.value == num_operations, (
1562-
f"Expected {num_operations} operations, got {nr_completed.value}"
1563-
)
1569+
assert nr_completed.value == num_operations, f"Expected {num_operations} operations, got {nr_completed.value}"
15641570

15651571
# Collect all returned cookies
15661572
returned_cookies = set()
@@ -1624,7 +1630,8 @@ def test_batch_io_large_operations():
16241630
# Close cuFile driver
16251631
cufile.driver_close()
16261632
cuda.cuDevicePrimaryCtxRelease(device)
1627-
1633+
1634+
16281635
@pytest.mark.skipif(
16291636
cufileVersionLessThan(1140), reason="cuFile parameter APIs require cuFile library version 1.14.0 or later"
16301637
)
@@ -1738,7 +1745,6 @@ def test_set_get_parameter_size_t():
17381745
@pytest.mark.skipif(
17391746
cufileVersionLessThan(1140), reason="cuFile parameter APIs require cuFile library version 1.14.0 or later"
17401747
)
1741-
17421748
def test_set_get_parameter_bool():
17431749
"""Test setting and getting boolean parameters with cuFile validation."""
17441750

@@ -1820,6 +1826,7 @@ def test_set_get_parameter_bool():
18201826
finally:
18211827
cuda.cuDevicePrimaryCtxRelease(device)
18221828

1829+
18231830
def test_set_get_parameter_string():
18241831
"""Test setting and getting string parameters with cuFile validation."""
18251832

@@ -1902,6 +1909,7 @@ def test_set_get_parameter_string():
19021909
finally:
19031910
cuda.cuDevicePrimaryCtxRelease(device)
19041911

1912+
19051913
@pytest.mark.skipif(
19061914
cufileVersionLessThan(1140), reason="cuFile parameter APIs require cuFile library version 13.0 or later"
19071915
)
@@ -1993,6 +2001,7 @@ def test_stats_start():
19932001
cufile.driver_close()
19942002
cuda.cuDevicePrimaryCtxRelease(device)
19952003

2004+
19962005
@pytest.mark.skipif(
19972006
cufileVersionLessThan(1150), reason="cuFile parameter APIs require cuFile library version 13.0 or later"
19982007
)
@@ -2030,6 +2039,7 @@ def test_stats_stop():
20302039
cufile.driver_close()
20312040
cuda.cuDevicePrimaryCtxRelease(device)
20322041

2042+
20332043
@pytest.mark.skipif(
20342044
cufileVersionLessThan(1150), reason="cuFile parameter APIs require cuFile library version 13.0 or later"
20352045
)
@@ -2071,6 +2081,7 @@ def test_stats_reset():
20712081
cufile.driver_close()
20722082
cuda.cuDevicePrimaryCtxRelease(device)
20732083

2084+
20742085
@pytest.mark.skipif(
20752086
cufileVersionLessThan(1150), reason="cuFile parameter APIs require cuFile library version 13.0 or later"
20762087
)
@@ -2140,7 +2151,9 @@ def test_get_stats_l1():
21402151
# Convert buffer to bytes and check that it's not all zeros
21412152
buffer_bytes = bytes(stats_buffer)
21422153
non_zero_bytes = sum(1 for b in buffer_bytes if b != 0)
2143-
assert non_zero_bytes > 0, f"Expected statistics data to be written to buffer, but got {non_zero_bytes} non-zero bytes"
2154+
assert non_zero_bytes > 0, (
2155+
f"Expected statistics data to be written to buffer, but got {non_zero_bytes} non-zero bytes"
2156+
)
21442157

21452158
# Verify statistics retrieval completed successfully
21462159
logging.info("cuFile L1 statistics retrieved successfully after file operations")
@@ -2160,6 +2173,7 @@ def test_get_stats_l1():
21602173
cufile.driver_close()
21612174
cuda.cuDevicePrimaryCtxRelease(device)
21622175

2176+
21632177
@pytest.mark.skipif(
21642178
cufileVersionLessThan(1150), reason="cuFile parameter APIs require cuFile library version 13.0 or later"
21652179
)
@@ -2231,7 +2245,9 @@ def test_get_stats_l2():
22312245
# Verify that statistics data was written to the buffer
22322246
buffer_bytes = bytes(stats_buffer)
22332247
non_zero_bytes = sum(1 for b in buffer_bytes if b != 0)
2234-
assert non_zero_bytes > 0, f"Expected statistics data to be written to buffer, but got {non_zero_bytes} non-zero bytes"
2248+
assert non_zero_bytes > 0, (
2249+
f"Expected statistics data to be written to buffer, but got {non_zero_bytes} non-zero bytes"
2250+
)
22352251

22362252
# Verify statistics retrieval completed successfully
22372253
logging.info("cuFile L2 statistics retrieved successfully after file operations")
@@ -2251,6 +2267,7 @@ def test_get_stats_l2():
22512267
cufile.driver_close()
22522268
cuda.cuDevicePrimaryCtxRelease(device)
22532269

2270+
22542271
@pytest.mark.skipif(
22552272
cufileVersionLessThan(1150), reason="cuFile parameter APIs require cuFile library version 13.0 or later"
22562273
)
@@ -2313,7 +2330,7 @@ def test_get_stats_l3():
23132330
cufile.write(handle, buf_ptr_int, buffer_size, buffer_size, 0) # Different offset
23142331
cufile.read(handle, buf_ptr_int, buffer_size, buffer_size, 0)
23152332
cufile.write(handle, buf_ptr_int, buffer_size // 2, buffer_size * 2, 0) # Partial write
2316-
cufile.read(handle, buf_ptr_int, buffer_size // 2, buffer_size * 2, 0) # Partial read
2333+
cufile.read(handle, buf_ptr_int, buffer_size // 2, buffer_size * 2, 0) # Partial read
23172334

23182335
# Allocate buffer for L3 statistics
23192336
stats_buffer = ctypes.create_string_buffer(4096) # Largest buffer for comprehensive stats
@@ -2325,7 +2342,9 @@ def test_get_stats_l3():
23252342
# Verify that statistics data was written to the buffer
23262343
buffer_bytes = bytes(stats_buffer)
23272344
non_zero_bytes = sum(1 for b in buffer_bytes if b != 0)
2328-
assert non_zero_bytes > 0, f"Expected statistics data to be written to buffer, but got {non_zero_bytes} non-zero bytes"
2345+
assert non_zero_bytes > 0, (
2346+
f"Expected statistics data to be written to buffer, but got {non_zero_bytes} non-zero bytes"
2347+
)
23292348

23302349
# Verify statistics retrieval completed successfully
23312350
logging.info("cuFile L3 statistics retrieved successfully after file operations")
@@ -2345,6 +2364,7 @@ def test_get_stats_l3():
23452364
cufile.driver_close()
23462365
cuda.cuDevicePrimaryCtxRelease(device)
23472366

2367+
23482368
@pytest.mark.skipif(
23492369
cufileVersionLessThan(1150), reason="cuFile parameter APIs require cuFile library version 13.0 or later"
23502370
)
@@ -2380,6 +2400,7 @@ def test_get_bar_size_in_kb():
23802400
cufile.driver_close()
23812401
cuda.cuDevicePrimaryCtxRelease(device)
23822402

2403+
23832404
@pytest.mark.skipif(
23842405
cufileVersionLessThan(1150), reason="cuFile parameter APIs require cuFile library version 13.0 or later"
23852406
)
@@ -2399,19 +2420,20 @@ def test_set_parameter_posix_pool_slab_array():
23992420

24002421
# Define slab sizes for POSIX I/O pool (common I/O buffer sizes) - BEFORE driver open
24012422
import ctypes
2423+
24022424
slab_sizes = [
2403-
4096, # 4KB - small files
2404-
65536, # 64KB - medium files
2405-
1048576, # 1MB - large files
2425+
4096, # 4KB - small files
2426+
65536, # 64KB - medium files
2427+
1048576, # 1MB - large files
24062428
16777216, # 16MB - very large files
24072429
]
24082430

24092431
# Define counts for each slab size (number of buffers)
24102432
slab_counts = [
2411-
10, # 10 buffers of 4KB
2412-
5, # 5 buffers of 64KB
2413-
3, # 3 buffers of 1MB
2414-
2, # 2 buffers of 16MB
2433+
10, # 10 buffers of 4KB
2434+
5, # 5 buffers of 64KB
2435+
3, # 3 buffers of 1MB
2436+
2, # 2 buffers of 16MB
24152437
]
24162438

24172439
# Convert to ctypes arrays
@@ -2421,7 +2443,9 @@ def test_set_parameter_posix_pool_slab_array():
24212443
count_array = count_array_type(*slab_counts)
24222444

24232445
# Set POSIX pool slab array configuration BEFORE opening driver
2424-
cufile.set_parameter_posix_pool_slab_array(ctypes.addressof(size_array), ctypes.addressof(count_array), len(slab_sizes))
2446+
cufile.set_parameter_posix_pool_slab_array(
2447+
ctypes.addressof(size_array), ctypes.addressof(count_array), len(slab_sizes)
2448+
)
24252449

24262450
# Open cuFile driver AFTER setting parameters
24272451
cufile.driver_open()
@@ -2431,16 +2455,22 @@ def test_set_parameter_posix_pool_slab_array():
24312455
retrieved_sizes = (ctypes.c_size_t * len(slab_sizes))()
24322456
retrieved_counts = (ctypes.c_size_t * len(slab_counts))()
24332457

2434-
cufile.get_parameter_posix_pool_slab_array(ctypes.addressof(retrieved_sizes), ctypes.addressof(retrieved_counts), len(slab_sizes))
2458+
cufile.get_parameter_posix_pool_slab_array(
2459+
ctypes.addressof(retrieved_sizes), ctypes.addressof(retrieved_counts), len(slab_sizes)
2460+
)
24352461

24362462
# Verify they match what we set
24372463
for i in range(len(slab_sizes)):
2438-
assert retrieved_sizes[i] == slab_sizes[i], f"Size mismatch at index {i}: expected {slab_sizes[i]}, got {retrieved_sizes[i]}"
2439-
assert retrieved_counts[i] == slab_counts[i], f"Count mismatch at index {i}: expected {slab_counts[i]}, got {retrieved_counts[i]}"
2464+
assert retrieved_sizes[i] == slab_sizes[i], (
2465+
f"Size mismatch at index {i}: expected {slab_sizes[i]}, got {retrieved_sizes[i]}"
2466+
)
2467+
assert retrieved_counts[i] == slab_counts[i], (
2468+
f"Count mismatch at index {i}: expected {slab_counts[i]}, got {retrieved_counts[i]}"
2469+
)
24402470

24412471
# Verify configuration was accepted successfully
24422472
logging.info(f"POSIX pool slab array configured with {len(slab_sizes)} slab sizes")
2443-
logging.info(f"Slab sizes: {[f'{size//1024}KB' for size in slab_sizes]}")
2473+
logging.info(f"Slab sizes: {[f'{size // 1024}KB' for size in slab_sizes]}")
24442474
logging.info("Round-trip verification successful: set and retrieved values match")
24452475

24462476
finally:

0 commit comments

Comments
 (0)