You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
test(cuda.core): drain imported pool frees in IPC tests and share a thread runner - #3544
Makes the cuda.core IPC tests honor the free ordering of pool imports and fail cleanly when worker threads fail. Test-only.
Closing a buffer imported from a memory pool enqueues a stream-ordered cuMemFreeAsync, and the importer's free must complete before the exporter frees the allocation. Several IPC test children broke that order: some synchronized before closing, one drained the wrong device, one never closed its buffer, and many drained only on success. A new drain_on_exit(stack, synchronizable) helper in helpers/memory.py registers the sync on an ExitStack so it runs after the imported buffers close, also when an assertion fails. VMM imports are unaffected, since closing a VMM buffer synchronizes before it unmaps.
A new run_in_threads helper in helpers/misc.py replaces the hand-written thread start/join loops (follow-up from #3531). It re-raises the first worker failure, aborts a shared barrier so other workers do not hang, and with a timeout fails on a thread that does not finish. This fixes test_ipc_concurrent_import, which swallowed worker exceptions, test_ipc_import_release_race, which could hang and blame the race under test when a worker failed before its barrier, and two test_program_cache tests whose thread assertions were swallowed.
_enter_import from test_ipc_pool_duplicate_import moves to helpers/memory.py as enter_imported_pool, since test_ipc_pool_kind now uses it too.
Several tests started and joined worker threads by hand, each with its own
error handling, and some got it wrong: test_ipc_concurrent_import never
collected worker exceptions, so a failing import let the test pass, and
test_ipc_import_release_race could hang if a worker failed before reaching
its barrier, which the parent then reported as the very race under test.
Add run_in_threads to helpers/misc.py. It runs each callable on its own
thread, joins every started thread, and re-raises the first failure (not a
BrokenBarrierError). A failing thread, or a thread that fails to start,
aborts the shared barrier so the other workers do not block forever. With a
timeout, a thread still running after its join raises TimeoutError.
Use it in test_ipc_pool_duplicate_import (replacing _run_threads),
test_ipc_concurrent_import, test_ipc_import_release_race,
test_resource_live_count, and the two threaded tests in
test_program_cache, whose thread_b assertions were previously swallowed.
test_memory's concurrent VMM grow test keeps its own loop: on a timeout it
deliberately leaves buffers open that a stuck thread may still use.
Where a worker failure now raises, the drain that used to follow the join
moves into a finally block, and the release race closes each imported
buffer with a with block. Unit tests cover the helper, and tests/AGENTS.md
points to it.
Signed-off-by: Ralf Juengling <rjuengling@nvidia.com>
Closing a buffer imported from a memory pool enqueues a stream-ordered
cuMemFreeAsync, and the importer's free must complete before the exporter
frees the allocation. Several IPC test children broke that order:
- test_ipc_pool_kind synchronized before closing, so the free stayed
pending at exit.
- TestIpcImportedPinnedBufferOnSecondDevice synchronized device 1, but
unpickling had bound the buffer's free to device 0's default stream.
- TestImportOversizedBufferDescriptorSize's expected rejection enqueues
the free of what it mapped, and the harness never drained it.
- test_event_ipc never closed its imported buffer, and test_device_uuid
returned without a drain.
- Many children drained only on success, so a failed assertion between
the import and the close skipped both.
Add drain_on_exit(stack, synchronizable) to helpers/memory.py. Registered
on an ExitStack before the imported buffers, it synchronizes after they
close, also when the body raises. Also move _enter_import from
test_ipc_pool_duplicate_import to helpers/memory.py as enter_imported_pool,
now that test_ipc_pool_kind uses it too. The children enter their imported
buffers and pools on a stack with drain_on_exit;
TestBufferPeerAccessAfterImport, which switches devices, repeats its
close-and-drain tail in a finally block instead.
VMM imports are unaffected: closing a VMM buffer synchronizes before it
unmaps.
Signed-off-by: Ralf Juengling <rjuengling@nvidia.com>
No actionable comments were generated in the recent review.
Summary
Summary by CodeRabbit
Tests
Improved reliability checks for concurrent CUDA memory, IPC, compilation, and caching scenarios.
Expanded coverage for worker failures, timeouts, and cleanup when operations fail, including ensuring waiting workers are released.
Updated resource-lifetime checks across memory and IPC test scenarios, with cleanup handled consistently when work succeeds or encounters an error.
Added checks that failures in concurrent operations are reported after other workers finish.
The changes add shared helpers for threaded test execution and imported-memory cleanup. They update concurrency and CUDA IPC tests to use these helpers or to close and synchronize resources through scoped cleanup.
Changes: Test concurrency and IPC cleanup
Layer / File(s)
Summary
Shared test helpers cuda_core/tests/helpers/misc.py, cuda_core/tests/helpers/memory.py, cuda_core/tests/test_helpers.py, cuda_core/tests/AGENTS.md
Adds run_in_threads for worker execution and failure handling. Adds helpers to register stream synchronization and imported-pool cleanup with an ExitStack. Documents thread-runner guidance and tests failure, barrier, and timeout behavior.
Concurrent test execution cuda_core/tests/memory/test_resource_live_count.py, cuda_core/tests/test_memory.py, cuda_core/tests/test_program.py, cuda_core/tests/test_program_cache.py, cuda_core/tests/memory_ipc/test_ipc_concurrent_import.py, cuda_core/tests/memory_ipc/test_ipc_import_release_race.py, cuda_core/tests/memory_ipc/test_ipc_pool_duplicate_import.py
Replaces manual thread lifecycle and local exception collection with run_in_threads in concurrent tests. Retains existing barriers and adds timeout handling where described.
Adds scoped buffer and imported-pool cleanup, stream draining, and explicit synchronization in IPC child processes. Existing checks and buffer operations remain in place.
Suggested reviewers:mdboom, jpascucci-nv
Change: Other
Merge Risk: Minimal · up to 156a5
This is a test-only change that adds shared thread-runner and IPC cleanup helpers. It does not change production behavior. No actionable merge-blocking risk is identified.
Security architecture risk: Minimal · up to 156a5
The changes help tests report worker failures and complete imported-buffer frees in the correct order. They do not change the shipped API, resource ownership, or deployment behavior.
- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Reviewing files that changed from the base of the PR and between 77bfb2c and 156a572.
Files selected for processing: 1
cuda_core/tests/helpers/misc.py
Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 9 remain after this review.
Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 9 remain after this review.
A worker still waiting at the barrier after a timeout would block until interpreter shutdown, because the helper's threads are non-daemon. Abort the barrier before raising TimeoutError so such a worker raises BrokenBarrierError and exits without running the code after its wait.
…e in run_in_threads
When one worker failed and another outlived the join timeout, the helper raised only the failure. Raise TimeoutError first, chained to the failure, so callers still learn that a thread may be using their resources.
Reviewing files that changed from the base of the PR and between 3c63d1d and 77bfb2c.
Files selected for processing: 2
cuda_core/tests/helpers/misc.py
cuda_core/tests/test_helpers.py
Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 10 remain after this review.
…_in_threads
A worker that failed right after a timed-out join could be missed: the failure was read while the error list was still empty, and the worker was no longer alive by the time liveness was checked, so the helper returned normally. Check liveness first.
Adopt the test helpers from NVIDIA#3544 in the tests this branch adds: import
pools with enter_imported_pool, which replaces _enter_import, and run the
lookup race test's threads with run_in_threads, which replaces
_run_threads and the hand-written error collection.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
test_concurrent_set_current_keeps_one_primary_retain runs its workers
with run_in_threads (NVIDIA#3544), which aborts the barrier if a worker fails
and bounds the joins.
test_green_context_replaces_stale_plain_entry notes rollback failures
with BaseException.add_note() instead of the _attach_rollback_failure_for_testing
production hook, which NVIDIA#3555 moves out of _rt.
test_driver_calls_go_through_the_table: the primary-context table's mutex
is a second site of raw driver calls under a lock.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cuda.coreEverything related to the cuda.core moduletestImprovements or additions to tests
2 participants
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Makes the cuda.core IPC tests honor the free ordering of pool imports and fail cleanly when worker threads fail. Test-only.
Closing a buffer imported from a memory pool enqueues a stream-ordered
cuMemFreeAsync, and the importer's free must complete before the exporter frees the allocation. Several IPC test children broke that order: some synchronized before closing, one drained the wrong device, one never closed its buffer, and many drained only on success. A newdrain_on_exit(stack, synchronizable)helper inhelpers/memory.pyregisters the sync on anExitStackso it runs after the imported buffers close, also when an assertion fails. VMM imports are unaffected, since closing a VMM buffer synchronizes before it unmaps.A new
run_in_threadshelper inhelpers/misc.pyreplaces the hand-written thread start/join loops (follow-up from #3531). It re-raises the first worker failure, aborts a shared barrier so other workers do not hang, and with a timeout fails on a thread that does not finish. This fixestest_ipc_concurrent_import, which swallowed worker exceptions,test_ipc_import_release_race, which could hang and blame the race under test when a worker failed before its barrier, and twotest_program_cachetests whose thread assertions were swallowed._enter_importfromtest_ipc_pool_duplicate_importmoves tohelpers/memory.pyasenter_imported_pool, sincetest_ipc_pool_kindnow uses it too.Checklist