Skip to content

Commit e0c782a

Browse files
rparolinclaude
andcommitted
test(cuda.core): query all buffers before closing in test_batched_same_advice
On CUDA 12, freeing one managed allocation appears to clear the read-mostly advice on neighboring ranges. The original test interleaved query-then-close inside one loop, so the second iteration would query bufs[1] *after* bufs[0] had been freed and observe a cleared advice flag — causing assert 0 == 1. Move the queries into a list comprehension that runs before any close, then close all buffers, then assert. Decouples the verification from the deallocation order. CUDA 13 was unaffected because its managed-memory bookkeeping does not exhibit the cross-range invalidation on free. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 0789bf6 commit e0c782a

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

cuda_core/tests/test_memory.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2245,15 +2245,21 @@ def test_batched_same_advice(self, init_cuda):
22452245
mr = DummyUnifiedMemoryResource(device)
22462246
bufs = [mr.allocate(_MANAGED_TEST_ALLOCATION_SIZE) for _ in range(2)]
22472247
advise(bufs, "set_read_mostly")
2248-
for buf in bufs:
2249-
assert (
2250-
_get_int_mem_range_attr(
2251-
buf,
2252-
driver.CUmem_range_attribute.CU_MEM_RANGE_ATTRIBUTE_READ_MOSTLY,
2253-
)
2254-
== _READ_MOSTLY_ENABLED
2248+
# Query all attributes BEFORE closing any buffer. On CUDA 12, freeing
2249+
# a managed allocation can clear read-mostly advice on neighboring
2250+
# ranges; close-then-query in a single loop falsely flags the later
2251+
# iterations as having lost the advice.
2252+
results = [
2253+
_get_int_mem_range_attr(
2254+
buf,
2255+
driver.CUmem_range_attribute.CU_MEM_RANGE_ATTRIBUTE_READ_MOSTLY,
22552256
)
2257+
for buf in bufs
2258+
]
2259+
for buf in bufs:
22562260
buf.close()
2261+
for r in results:
2262+
assert r == _READ_MOSTLY_ENABLED
22572263

22582264
def test_batched_per_buffer_location(self, init_cuda):
22592265
from cuda.core.utils import Location, advise

0 commit comments

Comments
 (0)