Skip to content

fix(cuda.core): pass numa_id to cuMemCreate for host_numa virtual memory - #3149

Open
somtri wants to merge 3 commits into
NVIDIA:mainfrom
somtri:fix/2694-vmm-host-numa
Open

somtri wants to merge 3 commits into
NVIDIA:mainfrom
somtri:fix/2694-vmm-host-numa

Conversation

@somtri

@somtri somtri commented Oct 19, 2026

Copy link
Copy Markdown

Description

closes #2694

VirtualMemoryResource with location_type="host_numa" passed -1 as the location id to cuMemCreate, and the driver rejects that with CUDA_ERROR_INVALID_VALUE. This follows the fix described in the issue comment:

  • VirtualMemoryResourceOptions has a new numa_id: int | None = None field, added last so the positional order does not change. _check_config requires it for "host_numa", rejects it for every other location type, and rejects negative values with the message PinnedMemoryResourceOptions uses. _fill_prop writes it to prop.location.id.
  • location_type="host_numa_current" raises ValueError at construction. The enum member stays.
  • One addition the comment did not ask for: in modify_allocation, _check_config also rejects a per-call config whose numa_id differs from the resource's, as it already does for location_type. _fill_prop takes the location from the resource, so without the check a different value would be ignored silently. I can drop it if you prefer.
  • test_vmm_host_location_types_report_host_accessible and test_is_ipc_enabled built host_numa without numa_id and built host_numa_current, so both needed updates. Three new tests cover the allocation, the host_numa_current rejection, and the numa_id checks. They carry agent_authored markers.
  • Release note in 1.3.0-notes.rst.

The allocation test writes and reads the buffer from the host. The resource grants access only to its own location, so cuMemsetD8 on the buffer fails with CUDA_ERROR_INVALID_VALUE unless the device is in peers. That is the host-resource peers gap from #2910, which this PR leaves alone.

Testing

Windows 11, RTX 3080 Laptop GPU (WDDM, driver 617.42), CUDA 13.4, cuda-bindings 13.4.4, Python 3.14. The device reports host_numa_id = 0 and host_numa_virtual_memory_management_supported = True.

The issue's reproducer, extended to host_numa_current and catching each error, before the change:

host allocated 2097152 bytes
host_numa FAILED: CUDAError CUDA_ERROR_INVALID_VALUE: ...
host_numa_current FAILED: CUDAError CUDA_ERROR_INVALID_VALUE: ...

After the change, numa_id=0 allocates 2097152 bytes, and host_numa_current raises ValueError at construction.

$ pytest tests/test_memory.py -k "vmm_host_numa or vmm_numa_id or host_location_types" -v
8 passed
$ pytest tests/test_memory.py tests/memory_ipc/test_vmm_ipc.py -k "vmm or Vmm or VirtualMemory or is_ipc_enabled" -q
50 passed, 29 skipped    (before the change: 45 passed, 30 skipped)

test_is_ipc_enabled skips on Windows ("Sharing virtual memory needs POSIX file descriptor handles"), so the test_vmm_ipc.py change has not run locally. pre-commit run passes on the five changed files.

Claude Code (claude-opus-5-5) wrote this change and ran the tests above on my machine. I reviewed the diff.

Checklist

  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

VirtualMemoryResource passed -1 as the location id for host_numa
allocations, and cuMemCreate rejects that with CUDA_ERROR_INVALID_VALUE.

Add VirtualMemoryResourceOptions.numa_id. It is required for host_numa,
rejected for other location types, and must match in a per-call
modify_allocation config. Reject host_numa_current at construction,
because the driver does not accept it for physical allocations.

Closes NVIDIA#2694

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Som Tripathi <somtri@iastate.edu>
@copy-pr-bot

copy-pr-bot Bot commented Oct 19, 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.

@github-actions github-actions Bot added the cuda.core Everything related to the cuda.core module label Oct 19, 2026
@coderabbitai

coderabbitai Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
📥 Commits

Reviewing files that changed from the base of the PR and between 1e11c4a and e9a2441.

📒 Files selected for processing: 5
  • cuda_core/cuda/core/_memory/_virtual_memory_resource.pyi
  • cuda_core/cuda/core/_memory/_virtual_memory_resource.pyx
  • cuda_core/docs/source/release/1.3.0-notes.rst
  • cuda_core/tests/memory_ipc/test_vmm_ipc.py
  • cuda_core/tests/test_memory.py
🚧 Files skipped from review as they are similar to previous changes: 1
  • cuda_core/docs/source/release/1.3.0-notes.rst

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

📝 Summary

Summary by CodeRabbit

  • New Features
    • Physical memory allocations can target a specific host NUMA node using location_type="host_numa" and a nonnegative numa_id.
    • Device properties identify the NUMA node closest to the device. On systems without NUMA, use numa_id=0.
  • Bug Fixes
    • Invalid NUMA configurations are rejected, including missing or misplaced NUMA IDs, negative IDs, per-call growth on a different NUMA node, and host_numa_current for physical allocations.

VirtualMemoryResourceOptions now accepts a NUMA node ID for host NUMA allocations. VirtualMemoryResource validates the configuration and uses that ID for physical allocations. Tests cover allocation, host access, and invalid configurations.

Changes: Host NUMA allocations

Layer / File(s) Summary
NUMA option contract
cuda_core/cuda/core/_memory/_virtual_memory_resource.pyx, cuda_core/cuda/core/_memory/_virtual_memory_resource.pyi
Adds and documents the optional numa_id option. It is required for host_numa, rejected for other location types, and must be nonnegative.
NUMA validation and allocation
cuda_core/cuda/core/_memory/_virtual_memory_resource.pyx
Validates the NUMA configuration, rejects host_numa_current, and sets the host NUMA allocation location ID to numa_id.
NUMA behavior coverage
cuda_core/tests/test_memory.py, cuda_core/tests/memory_ipc/test_vmm_ipc.py, cuda_core/docs/source/release/1.3.0-notes.rst
Tests cover host NUMA allocation, host access, IPC configuration, and invalid settings. Release notes describe the option and its constraints.

Assessment against linked issues

Objective Addressed Explanation
Enable host_numa allocations by providing the required NUMA node ID [#2694] ✅
Reject host_numa_current for physical allocations [#2694] ✅

Possibly related issues

Possibly related PRs

  • NVIDIA/cuda-python#3034: Both PRs change the handling of release notes in cuda_core/docs/source/release/1.3.0-notes.rst; #3034 deletes that file and may remove this PR’s note if it is not migrated.

Suggested reviewers: andy-jost

Priority: ➖ Normal

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to e9a24

The NUMA allocation change appears ready to merge after normal checks; no actionable merge-blocking issue was established.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@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
  • Configuration used: Repository: NVIDIA/cuda-python/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Enterprise
  • Run ID: b60e59cb-b28e-419e-a1f0-4c8405fefed6
📥 Commits

Reviewing files that changed from the base of the PR and between 576ef68 and c33542b.

📒 Files selected for processing: 5
  • cuda_core/cuda/core/_memory/_virtual_memory_resource.pyi
  • cuda_core/cuda/core/_memory/_virtual_memory_resource.pyx
  • cuda_core/docs/source/release/1.3.0-notes.rst
  • cuda_core/tests/memory_ipc/test_vmm_ipc.py
  • cuda_core/tests/test_memory.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.

Comment thread cuda_core/cuda/core/_memory/_virtual_memory_resource.pyx Outdated
The numa_id docstring points to Device.properties.host_numa_id, which is
-1 on a system without NUMA, and numa_id rejects -1. cuMemCreate wants
location id 0 on such a system, so say that in the docstring.

Signed-off-by: Som Tripathi <somtri@iastate.edu>
@Andy-Jost Andy-Jost added bug Something isn't working P1 Medium priority - Should do labels Oct 23, 2026
@Andy-Jost Andy-Jost added this to the cuda.core 1.3.0 milestone Oct 23, 2026
@Andy-Jost

Copy link
Copy Markdown
Contributor

/ok to test 1e11c4a

@Andy-Jost Andy-Jost 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.

Thank you for the fix, @somtri. The change is small, it matches the scope agreed in #2694, and the new tests cover the host_numa path that was broken. I have one non-blocking nit.

Nits

  1. cuda_core/cuda/core/_memory/_virtual_memory_resource.pyx, line 716 (modify_allocation docstring). The new check at lines 484-488 rejects a per-call config whose numa_id differs from the resource's, but the docstring still describes only location_type and handle_type. Please add numa_id in two places: the config entry under Parameters ("must name the resource's location_type, handle_type, and numa_id") and the ValueError entry under Raises ("if config names a different location type, handle type, or numa_id"). That matches how the existing location_type rule is documented.

Your questions

  1. Keep the per-call numa_id mismatch check in modify_allocation. Yes, keep it. It mirrors the existing location_type rule, and _fill_prop reads the location from the resource's config, so without the check a different per-call numa_id would be ignored silently. We prefer an explicit error over a silent fallback. The docstring update in nit 1 is the only follow-up.
  2. The test_vmm_ipc.py change that has not run locally. That is fine. The module skips on Windows, and CI runs it on Linux, so CI will be its first run. If the host_numa row fails there, we can look at it together.

Next steps

I am adding the missing metadata (assignee, bug and P1 labels, milestone "cuda.core 1.3.0") and starting CI with /ok to test. Once CI is green and the docstring nit is in, I will merge.

…1.0 library names)

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@Andy-Jost

Copy link
Copy Markdown
Contributor

I merged main into this branch to pick up #3188 (cuDSS 1.0 library names), which the pathfinder CI step needs now. No other change. CI runs again on the new head.

@Andy-Jost

Copy link
Copy Markdown
Contributor

/ok to test e9a2441

@github-actions

Copy link
Copy Markdown
Contributor

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 P1 Medium priority - Should do

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: VirtualMemoryResource host_numa allocations always fail

2 participants