Skip to content

Commit 2beaf11

Browse files
committed
add field checks for stats
1 parent 902406b commit 2beaf11

1 file changed

Lines changed: 79 additions & 28 deletions

File tree

cuda_bindings/tests/test_cufile.py

Lines changed: 79 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2139,16 +2139,33 @@ def test_get_stats_l1():
21392139
# Get L1 statistics (basic operation counts)
21402140
cufile.get_stats_l1(stats_ptr)
21412141

2142-
# Verify that statistics data was written to the buffer
2143-
# Convert buffer to bytes and check that it's not all zeros
2144-
buffer_bytes = bytes(stats_buffer)
2145-
non_zero_bytes = sum(1 for b in buffer_bytes if b != 0)
2146-
assert non_zero_bytes > 0, (
2147-
f"Expected statistics data to be written to buffer, but got {non_zero_bytes} non-zero bytes"
2148-
)
2149-
2150-
# Verify statistics retrieval completed successfully
2151-
logging.info("cuFile L1 statistics retrieved successfully after file operations")
2142+
# Define ctypes structure matching CUfileStatsLevel1_t
2143+
class OpCounter(ctypes.Structure):
2144+
_fields_ = [("ok", ctypes.c_uint64), ("err", ctypes.c_uint64)]
2145+
2146+
class StatsL1(ctypes.Structure):
2147+
_fields_ = [
2148+
("read_ops", OpCounter), ("write_ops", OpCounter),
2149+
("hdl_register_ops", OpCounter), ("hdl_deregister_ops", OpCounter),
2150+
("buf_register_ops", OpCounter), ("buf_deregister_ops", OpCounter),
2151+
("read_bytes", ctypes.c_uint64), ("write_bytes", ctypes.c_uint64),
2152+
("read_bw_bytes_per_sec", ctypes.c_uint64), ("write_bw_bytes_per_sec", ctypes.c_uint64),
2153+
("read_lat_avg_us", ctypes.c_uint64), ("write_lat_avg_us", ctypes.c_uint64),
2154+
("read_ops_per_sec", ctypes.c_uint64), ("write_ops_per_sec", ctypes.c_uint64),
2155+
("read_lat_sum_us", ctypes.c_uint64), ("write_lat_sum_us", ctypes.c_uint64),
2156+
]
2157+
2158+
# Cast buffer to structure and examine fields
2159+
stats = ctypes.cast(stats_ptr, ctypes.POINTER(StatsL1)).contents
2160+
2161+
# Verify actual field values
2162+
assert stats.read_ops.ok > 0, f"Expected read operations, got {stats.read_ops.ok}"
2163+
assert stats.write_ops.ok > 0, f"Expected write operations, got {stats.write_ops.ok}"
2164+
assert stats.read_bytes > 0, f"Expected read bytes, got {stats.read_bytes}"
2165+
assert stats.write_bytes > 0, f"Expected write bytes, got {stats.write_bytes}"
2166+
2167+
logging.info(f"Stats: reads={stats.read_ops.ok}, writes={stats.write_ops.ok}, "
2168+
f"read_bytes={stats.read_bytes}, write_bytes={stats.write_bytes}")
21522169

21532170
# Stop statistics collection
21542171
cufile.stats_stop()
@@ -2165,7 +2182,6 @@ def test_get_stats_l1():
21652182
cufile.driver_close()
21662183
cuda.cuDevicePrimaryCtxRelease(device)
21672184

2168-
21692185
@pytest.mark.skipif(
21702186
cufileVersionLessThan(1150), reason="cuFile parameter APIs require cuFile library version 13.0 or later"
21712187
)
@@ -2234,15 +2250,23 @@ def test_get_stats_l2():
22342250
# Get L2 statistics (detailed performance metrics)
22352251
cufile.get_stats_l2(stats_ptr)
22362252

2237-
# Verify that statistics data was written to the buffer
2238-
buffer_bytes = bytes(stats_buffer)
2239-
non_zero_bytes = sum(1 for b in buffer_bytes if b != 0)
2240-
assert non_zero_bytes > 0, (
2241-
f"Expected statistics data to be written to buffer, but got {non_zero_bytes} non-zero bytes"
2242-
)
2253+
# Define ctypes structure matching CUfileStatsLevel2_t
2254+
class StatsL2(ctypes.Structure):
2255+
_fields_ = [
2256+
("basic", ctypes.c_byte * 512), # L1 data (simplified)
2257+
("read_size_kb_hist", ctypes.c_uint64 * 32),
2258+
("write_size_kb_hist", ctypes.c_uint64 * 32),
2259+
]
22432260

2244-
# Verify statistics retrieval completed successfully
2245-
logging.info("cuFile L2 statistics retrieved successfully after file operations")
2261+
# Cast buffer to structure and examine L2-specific fields
2262+
stats = ctypes.cast(stats_ptr, ctypes.POINTER(StatsL2)).contents
2263+
2264+
# Verify L2 histogram fields contain data
2265+
read_hist_total = sum(stats.read_size_kb_hist)
2266+
write_hist_total = sum(stats.write_size_kb_hist)
2267+
assert read_hist_total > 0 or write_hist_total > 0, "Expected L2 histogram data"
2268+
2269+
logging.info(f"L2 Stats: read_hist_total={read_hist_total}, write_hist_total={write_hist_total}")
22462270

22472271
# Stop statistics collection
22482272
cufile.stats_stop()
@@ -2331,15 +2355,42 @@ def test_get_stats_l3():
23312355
# Get L3 statistics (comprehensive diagnostic data)
23322356
cufile.get_stats_l3(stats_ptr)
23332357

2334-
# Verify that statistics data was written to the buffer
2335-
buffer_bytes = bytes(stats_buffer)
2336-
non_zero_bytes = sum(1 for b in buffer_bytes if b != 0)
2337-
assert non_zero_bytes > 0, (
2338-
f"Expected statistics data to be written to buffer, but got {non_zero_bytes} non-zero bytes"
2339-
)
2340-
2341-
# Verify statistics retrieval completed successfully
2342-
logging.info("cuFile L3 statistics retrieved successfully after file operations")
2358+
# Define ctypes structure matching CUfileStatsLevel3_t
2359+
class PerGpuStats(ctypes.Structure):
2360+
_fields_ = [
2361+
("uuid", ctypes.c_char * 16),
2362+
("read_bytes", ctypes.c_uint64),
2363+
("read_bw_bytes_per_sec", ctypes.c_uint64),
2364+
("read_utilization", ctypes.c_uint64),
2365+
("read_duration_us", ctypes.c_uint64),
2366+
("n_total_reads", ctypes.c_uint64),
2367+
("n_p2p_reads", ctypes.c_uint64),
2368+
("n_nvfs_reads", ctypes.c_uint64),
2369+
("n_posix_reads", ctypes.c_uint64),
2370+
]
2371+
2372+
class StatsL3(ctypes.Structure):
2373+
_fields_ = [
2374+
("detailed", ctypes.c_byte * 2048), # L2 data (simplified)
2375+
("num_gpus", ctypes.c_uint32),
2376+
("per_gpu_stats", PerGpuStats * 16),
2377+
]
2378+
2379+
# Cast buffer to structure and examine L3-specific fields
2380+
stats = ctypes.cast(stats_ptr, ctypes.POINTER(StatsL3)).contents
2381+
2382+
# Verify L3-specific fields
2383+
assert stats.num_gpus >= 0, f"Expected valid GPU count, got {stats.num_gpus}"
2384+
2385+
# Check if we have at least one GPU with stats
2386+
gpu_with_data = False
2387+
for i in range(min(stats.num_gpus, 16)):
2388+
gpu_stats = stats.per_gpu_stats[i]
2389+
if gpu_stats.n_total_reads > 0 or gpu_stats.read_bytes > 0:
2390+
gpu_with_data = True
2391+
break
2392+
2393+
logging.info(f"L3 Stats: num_gpus={stats.num_gpus}, gpu_with_data={gpu_with_data}")
23432394

23442395
# Stop statistics collection
23452396
cufile.stats_stop()

0 commit comments

Comments
 (0)