Skip to content

fix(cuda.core): report the exporter's NUMA node on imported pinned pools - #3530

Open
juenglin wants to merge 9 commits into
NVIDIA:mainfrom
juenglin:fix-3508-pinned-ipc-numa-id
Open

juenglin wants to merge 9 commits into
NVIDIA:mainfrom
juenglin:fix-3508-pinned-ipc-numa-id

Conversation

@juenglin

@juenglin juenglin commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Description

closes #3508

An imported PinnedMemoryResource reported numa_id == 0 when the driver cannot report the pool's location (a CUDA 12 build or a driver before 13.2); #3516 fixed the case where it can. Now the exporter's node travels with the pickle, and PinnedMemoryResource.from_allocation_handle takes an optional numa_id for raw handles. If the handle's resource is already registered in the process with an unknown node, the argument becomes its node. A negative numa_id, or one that differs from the pool's known node (reported by the driver or by a resource already registered for the handle), raises ValueError.

If the node comes from neither the driver nor the argument, the import still succeeds, but the numa_id property raises RuntimeError instead of returning 0, and pickling the resource sends no node. This is a behavior change called out in the release note.

Tested with a CUDA 13.5 build; the no-location-query paths are covered by patching driver_version in the child process. A CUDA 12 build and a multi-node NUMA host were not tested.

Checklist

  • I have read the Contributing Guidelines.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

@juenglin juenglin added this to the cuda.core 1.4.0 milestone Nov 21, 2026
@juenglin juenglin added bug Something isn't working cuda.core Everything related to the cuda.core module labels Nov 21, 2026
@copy-pr-bot

copy-pr-bot Bot commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

An imported PinnedMemoryResource reported numa_id 0 whenever the driver
could not report the pool's location (a CUDA 12 build or a driver before
13.2). Unpickling a resource now carries the exporter's node, and
PinnedMemoryResource.from_allocation_handle accepts an optional numa_id
for a raw allocation handle. An import whose node is unknown still reports
0 and does not pass it on when pickled.

from_allocation_handle raises ValueError for a negative numa_id, and for
one that differs from the pool's known node, whether the driver reported
it or the resource was already registered in the process.

Closes NVIDIA#3508.

Signed-off-by: Ralf Juengling <rjuengling@nvidia.com>
@juenglin
juenglin force-pushed the fix-3508-pinned-ipc-numa-id branch from 48c3188 to 673d500 Compare November 26, 2026 00:11
… is unknown

An imported pool whose node neither the driver nor the caller reports no
longer reports 0. The numa_id property raises RuntimeError instead, as
NVIDIA#3508 now specifies.
…tests

Close imported resources through an ExitStack, as the other children in
test_ipc_pool_kind.py do, by letting import_pool_resource and
enter_imported_pool pass numa_id. Reuse _without_location_query in
child_import_without_location_query, and explain why the pickle tests
send the reducer's output instead of the resource.
@juenglin
juenglin marked this pull request as ready for review November 26, 2026 00:29
Cover the reducer output and the import from it in one pickle test, drop the
unknown-node assertion that test_import_uses_given_numa_id already makes, and
test a single negative numa_id.
@juenglin

Copy link
Copy Markdown
Contributor Author

/ok to test a2f7a7b

@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Explain Change →

Summary

Summary by CodeRabbit

  • New Features
    • Imported pinned memory resources can retain the exporting pool’s NUMA node through transfer or pickling. If the node can’t be detected automatically, you can provide it when importing an allocation handle or supply it for an existing import.
  • Behavior Changes
    • Accessing an unknown NUMA node now raises an error instead of returning 0. Invalid node values, including negative or out-of-range values, and values that conflict with a known node are rejected.

Imported pinned memory resources can obtain their NUMA node from the driver or an optional import argument. Pickling carries a known node to the importing process. If the node remains unknown, accessing numa_id raises RuntimeError instead of returning 0.

Changes: Pinned pool NUMA identity

Layer / File(s) Summary
NUMA-node contract
cuda_core/cuda/core/_memory/_pinned_memory_resource.pxd, cuda_core/cuda/core/_memory/_pinned_memory_resource.pyi
The resource tracks whether its NUMA node is known. The import API and property document node sources, validation, and behavior when the node is unknown.
Import and pickle behavior
cuda_core/cuda/core/_memory/_pinned_memory_resource.pyx
Imports record a node reported by the driver or supplied by the caller. Negative or conflicting supplied nodes raise ValueError. Pickling includes the node when known; accessing numa_id raises RuntimeError when it is unknown.
Import validation and release notes
cuda_core/tests/helpers/memory.py, cuda_core/tests/conftest.py, cuda_core/tests/memory_ipc/test_ipc_pool_kind.py, cuda_core/docs/source/release/1.4.0-notes.rst
Test helpers pass an optional node to pinned-resource imports. IPC tests cover driver lookup, caller-supplied nodes, unknown nodes, conflicts, concurrency, and pickling. Release notes describe the behavior.

Assessment against linked issues

Objective Addressed Explanation
Preserve the exporter’s NUMA node through pickling and accept an optional node for raw-handle imports [3508] ✅
Reject negative or conflicting node values, and leave an unavailable node unknown rather than reporting 0 [3508] ✅
Document node sources and behavior when the node is unknown [3508] ✅

Possibly related issues

  • NVIDIA/cuda-python#3615 — The PR implements the pinned-resource node conflict and unknown-node behavior discussed in this issue.

Possibly related PRs

  • NVIDIA/cuda-python#3516 — Both PRs change imported pinned-pool NUMA handling. This PR validates the supplied node against the driver-reported node and carries known nodes through pickling.

Suggested reviewers: leofang, mdboom, jpascucci-nv

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: Minimal · up to fde04

Imported pinned memory resources now take their NUMA node from the driver, the pickle payload, or an optional numa_id argument. When none of these supplies it, reading numa_id raises RuntimeError instead of returning 0. No concrete merge-blocking defect remains in the reviewed changes. The CUDA 12 build and multi-node hosts remain untested, as the author states.

Security architecture risk: Low · up to fde04

The change improves NUMA reporting without granting additional memory access. The main compatibility risk is that an updated process can send a pinned-memory resource that an older process cannot reconstruct, which matters if communicating processes are upgraded or rolled back separately.

Retained concerns

  • Trivial · reliability · observed: This PR breaks pinned-pool reconstruction from a new sender to an old receiver: the old reconstruction method accepts only the allocation handle, but the new sender always supplies a second argument, even when it is None. If peers are upgraded or rolled back independently, affected transfers fail until compatible peers are paired.

View findings in the submitted review

Security review details

Security Blast Radius

  • inferred — A caller or pickle sender can supply an unverified node when the receiver has no driver or registered value to compare against. That value can become visible to other users of the same wrapper in the receiving process and travel with a subsequent export of that resource; the inspected import path does not use it to grant additional access.

Trust Boundaries and Controls

  • observed — The import keeps the existing handle-open, registered-type, and driver pool-kind checks where available. NUMA validation checks representability and agreement with known metadata; it does not authenticate a caller-supplied node when no independent value is available.

Resilience and Maintainability Implications

  • observed — A fresh import that fails node validation exits before registry publication or the device-access grant. The temporary import uses the existing shared pool and file-descriptor ownership model; this PR does not add a separate cleanup path.
- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@juenglin
juenglin requested review from Andy-Jost and rwgk November 26, 2026 00:32

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between d1fc8a8 and a2f7a7b.

Files selected for processing: 6

  • cuda_core/cuda/core/_memory/_pinned_memory_resource.pxd
  • cuda_core/cuda/core/_memory/_pinned_memory_resource.pyi
  • cuda_core/cuda/core/_memory/_pinned_memory_resource.pyx
  • cuda_core/docs/source/release/1.4.0-notes.rst
  • cuda_core/tests/helpers/memory.py
  • cuda_core/tests/memory_ipc/test_ipc_pool_kind.py

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 11 remain after this review.

@github-actions

Copy link
Copy Markdown
Contributor

…nknown node

A second import of a registered handle, given a numa_id, now sets the node of
a resource whose first import had none, instead of leaving numa_id raising.
@juenglin

Copy link
Copy Markdown
Contributor Author

/ok to test 308de2d

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between a2f7a7b and 308de2d.

Files selected for processing: 3

  • cuda_core/cuda/core/_memory/_pinned_memory_resource.pyi
  • cuda_core/cuda/core/_memory/_pinned_memory_resource.pyx
  • cuda_core/tests/memory_ipc/test_ipc_pool_kind.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.

Check and set the node of a registered import in one critical section, and
read it under the same critical section in numa_id and the pickle reducer, so
that concurrent imports naming different nodes cannot both succeed on a
free-threaded build. The reducer no longer sends a negative node, which
from_allocation_handle rejects.
@juenglin

Copy link
Copy Markdown
Contributor Author

/ok to test 1f0258c

@rwgk rwgk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at commit 1f0258c: three low-priority issues (codex GPT-6.2-Sol ultra):

  • P3 · Fractional NUMA IDs are silently truncated. On both CUDA builds, from_allocation_handle(..., numa_id=1.75) accepted the value and reported node 1. On CUDA 13 it also passed validation against the driver-reported node 1. Normalize once with operator.index() and a checked integer conversion before importing the pool. Validation · Conversion
  • P3 · The fallback pickle test bypasses multiprocessing reconstruction. It calls the reducer directly and manually imports its arguments. I verified a real Pipe round trip with the location query disabled. Both builds recovered node 1, and both reported the node as unknown when I removed the serialized metadata. That round trip would cover the public behavior directly. Fallback pickle test · Saved probe
  • P3 · The rejected-import test can miss its cleanup warning. The first import stays alive while the conflicting import is rejected. The two imports share a native pool owner, which releases the driver references when the first import closes, after warning capture ends. Close the first import before testing rejection to exercise cleanup inside the capture. Test · Shared owner

# Conflicts:
#	cuda_core/tests/memory_ipc/test_ipc_pool_kind.py
…uma_id tests

from_allocation_handle normalizes numa_id with operator.index and bounds it by
INT_MAX before importing the pool, so a float is no longer truncated. The
pickle test now sends the resource through a multiprocessing Pipe, the
rejected-import test closes the first import so that its cleanup is checked,
the pinned IPC pool is a shared fixture, and the tests assert exception types
instead of messages.
@juenglin

Copy link
Copy Markdown
Contributor Author

/ok to test fde0453

@juenglin
juenglin enabled auto-merge (squash) November 30, 2026 22:03

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Architecture findings (1)

Advisory architecture findings (1)

  • Trivial — This PR breaks pinned-pool reconstruction from a new sender to an old receiver: the old reconstruction method accepts only the allocation handle, but the new sender always supplies a second argument, even when it is None. If peers are upgraded or rolled back independently, affected transfers fail until compatible peers are paired.
Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 1f0258c and fde0453.

Files selected for processing: 5

  • cuda_core/cuda/core/_memory/_pinned_memory_resource.pyi
  • cuda_core/cuda/core/_memory/_pinned_memory_resource.pyx
  • cuda_core/docs/source/release/1.4.0-notes.rst
  • cuda_core/tests/conftest.py
  • cuda_core/tests/memory_ipc/test_ipc_pool_kind.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.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working cuda.core Everything related to the cuda.core module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: PinnedMemoryResource imported over IPC reports numa_id 0 instead of the exporter's node

3 participants