Skip to content

Commit f2b7822

Browse files
committed
test: address Orin review feedback
1 parent 139fc14 commit f2b7822

3 files changed

Lines changed: 28 additions & 14 deletions

File tree

‎cuda_core/tests/system/test_system_device.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
unsupported_before,
1010
)
1111

12+
# Keep device-API gating on individual tests: system-level NVML queries in
13+
# this module remain supported on platforms with partial device API support.
1214
pytestmark = skip_if_nvml_unsupported
1315

1416
import array

‎cuda_core/tests/system/test_system_events.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
from cuda_python_test_helpers.arch_check import skip_if_nvml_device_apis_unsupported, skip_if_nvml_unsupported
77

8+
# Keep device-API gating on individual tests so the pure event conversion and
9+
# wrapping tests still run on platforms with partial device API support.
810
pytestmark = skip_if_nvml_unsupported
911

1012
import helpers

‎cuda_core/tests/test_memory.py‎

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44
import ctypes
5+
import functools
56
import multiprocessing as mp
67
import sys
78

@@ -1506,37 +1507,46 @@ def __init__(self, size):
15061507
assert ("release", NEW_HANDLE) in calls
15071508

15081509

1510+
def _vmm_allocate_and_close(mr, requested_size, grow):
1511+
buf = mr.allocate(requested_size)
1512+
if grow:
1513+
buf = mr.modify_allocation(buf, 2 * buf.size)
1514+
aligned_size = buf.size
1515+
buf.close()
1516+
return aligned_size
1517+
1518+
1519+
@functools.cache
1520+
def _warm_up_vmm_allocate_and_close(device_id, grow):
1521+
device = Device(device_id)
1522+
mr = VirtualMemoryResource(
1523+
device,
1524+
config=VirtualMemoryResourceOptions(handle_type="win32_kmt" if IS_WINDOWS else "posix_fd"),
1525+
)
1526+
return _vmm_allocate_and_close(mr, 8 * 1024 * 1024, grow)
1527+
1528+
15091529
@pytest.mark.thread_unsafe(reason="cuMemGetInfo measures process-wide free memory")
15101530
@pytest.mark.parametrize("grow", [False, True], ids=["allocate", "grow"])
15111531
def test_vmm_allocate_close_does_not_leak(init_cuda, grow):
15121532
device = Device()
15131533
if not device.properties.virtual_memory_management_supported:
15141534
pytest.skip("Virtual memory management is not supported on this device")
15151535

1536+
aligned_size = _warm_up_vmm_allocate_and_close(device.device_id, grow)
15161537
mr = VirtualMemoryResource(
15171538
device,
15181539
config=VirtualMemoryResourceOptions(handle_type="win32_kmt" if IS_WINDOWS else "posix_fd"),
15191540
)
15201541
requested_size = 8 * 1024 * 1024
15211542

1522-
def allocate_and_close():
1523-
buf = mr.allocate(requested_size)
1524-
if grow:
1525-
buf = mr.modify_allocation(buf, 2 * buf.size)
1526-
aligned_size = buf.size
1527-
buf.close()
1528-
return aligned_size
1529-
1530-
aligned_size = allocate_and_close() # Warm up and learn the aligned allocation size.
1531-
15321543
baseline = handle_return(driver.cuMemGetInfo())[0]
15331544
for _ in range(8):
1534-
allocate_and_close()
1545+
_vmm_allocate_and_close(mr, requested_size, grow)
15351546
free = handle_return(driver.cuMemGetInfo())[0]
15361547

1537-
# The broken path leaks aligned_size per iteration. Allow one allocation's
1538-
# worth of driver bookkeeping/caching while still detecting repeated leaks.
1539-
assert baseline - free < 2 * aligned_size
1548+
# A leak would cost at least one allocation per iteration.
1549+
assert baseline - free < aligned_size
15401550

15411551

15421552
def test_vmm_allocator_rdma_unsupported_exception():

0 commit comments

Comments
 (0)