Skip to content

samples: demonstrate Grace Hopper host and managed memory - #3278

Open
0z5a wants to merge 3 commits into
NVIDIA:mainfrom
0z5a:samples/grace-hopper-memory
Open

0z5a wants to merge 3 commits into
NVIDIA:mainfrom
0z5a:samples/grace-hopper-memory

Conversation

@0z5a

@0z5a 0z5a commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Description

Related to #3219.

This sample demonstrates GPU operations on host-accessible memory on Grace Hopper. It allocates pinned memory on the GPU's host NUMA node and managed memory with cuda.core, alongside a pageable NumPy array. CuPy doubles and sums the data; the CPU checks the results. A device-memory case demonstrates the corresponding explicit host/device copies.

The sample uses CuPy operations rather than custom kernels. CuPy does not import the pinned or pageable buffers through DLPack here, so it wraps their pointers with cupy.cuda.UnownedMemory. The sample waives when the required host-page-table, managed-memory or NUMA-pool capabilities are unavailable.

The minimum cuda-core version is 1.2.2, which is available on PyPI and provides the APIs used by the sample.

Validation

On 2026-11-04, tested the sample on a GH200 480GB (compute capability 9.0, driver 595.58.03). The host NUMA node was 0; host-page-table access, concurrent managed access and host NUMA memory-pool support were reported as available.

  • Pinned, managed and pageable buffers, each 64 MiB, produced a GPU sum of 17,163,091,968 and passed the CPU array comparison.
  • The device-memory result passed its CPU comparison after the explicit device-to-host copy. The sample exited 0.
  • A clean environment installed from the updated requirements used Python 3.12.3, cuda-core 1.2.2, cuda-bindings 13.4.4, cuda-toolkit 13.4.3, CuPy 14.2.0 and NumPy 2.5.4; the host CUDA toolkit was 13.2.
  • The tested script and requirements have the same SHA-256 hashes as commit a7058a32e3541634cbc1600ceb5f5c654edb9693: a67cea6066c72ccf8d82f5da9878edfc7eb32a7c43274e3fbc7b5a5285f8e04f and c088005b55f735c586bf4d833634a9395e1d5ea17edee679ae72e3fce64fe79a, respectively. The test ran before the commit was created.
  • All applicable pre-commit hooks passed, including Ruff, secret scanning and the README link check.

The non-ATS waiver path was not rerun. Managed-memory access may migrate pages; the sample makes no bandwidth claim.

Signed-off-by: 0z5a <dezhen.lu@student.uni-tuebingen.de>
@copy-pr-bot

copy-pr-bot Bot commented Oct 29, 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 29, 2026
@0z5a
0z5a marked this pull request as ready for review October 29, 2026 14:41
@coderabbitai

coderabbitai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • New Features
    • Added a Grace Hopper sample that processes and validates host-resident buffers using GPU operations, alongside a device-memory comparison using explicit transfers.
    • The sample checks required device and memory features and reports when execution is waived because they are unavailable.
  • Documentation
    • Added setup instructions, requirements, example output, and details on memory handling and DLPack import limitations.

Adds a Grace Hopper CUDA sample that checks system capabilities, exercises pinned host, managed, pageable, and device memory, and validates results. The README documents dependencies, requirements, setup commands, and example output.

Changes: Grace Hopper Memory Sample

Layer / File(s) Summary
Dependencies and runtime helpers
samples/cuda_core/graceHopperMemory/requirements.txt, samples/cuda_core/graceHopperMemory/graceHopperMemory.py
Adds minimum dependency versions, imports, buffer-size and waiver constants, a helper to wrap a pointer as a CuPy array, and a helper that runs and validates CuPy operations.
Capability checks and memory operations
samples/cuda_core/graceHopperMemory/graceHopperMemory.py, samples/cuda_core/graceHopperMemory/README.md
Checks system capabilities and reports a waiver when requirements are not met. On supported systems, allocates device, NUMA-local pinned, managed, and pageable buffers; validates operations on host-resident buffers and explicit copies for device memory; and synchronizes and closes resources. Documents memory behavior, requirements, setup, and example output.

Possibly related issues

Change: Feature

Merge Risk: Minimal · up to a7058

No actionable code risk remains that should block merging.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between b71ede7 and a7058a3.

Files selected for processing: 3
  • samples/cuda_core/graceHopperMemory/README.md
  • samples/cuda_core/graceHopperMemory/graceHopperMemory.py
  • samples/cuda_core/graceHopperMemory/requirements.txt

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

@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 d4c71ef and 8b0d893.

Files selected for processing: 3
  • samples/cuda_core/graceHopperMemory/README.md
  • samples/cuda_core/graceHopperMemory/graceHopperMemory.py
  • samples/cuda_core/graceHopperMemory/requirements.txt

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

@rparolin
rparolin requested a review from danielfrg October 29, 2026 14:55
@rparolin rparolin added the P1 Medium priority - Should do label Oct 29, 2026
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

# /// script
# dependencies = ["cuda-python>=13.0.0", "cuda-core>=1.3.0", "numpy>=2.2.5"]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
# dependencies = ["cuda-python>=13.0.0", "cuda-core>=1.3.0", "numpy>=2.2.5"]
# dependencies = ["cuda-core>=1.3.0", "numpy>=2.2.5"]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I dropped cuda-python. Two changes to the suggested line: the rewrite uses CuPy, so cupy-cuda13x>=14.0.0 is now listed, and I use cuda-core[cu13] because plain cuda-core does not install cuda-bindings (import cuda.core failed in a clean venv without it). The header is now:

# dependencies = ["cuda-core[cu13]>=1.3.0", "cupy-cuda13x>=14.0.0", "numpy>=2.2.5"]

requirements.txt matches. Happy to switch back to plain cuda-core>=1.3.0 if you prefer.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The example seems overly complicated here. What are we trying to achieve?

We can allocate buffers from different MRs, and then wrap them as CuPy arrays via cp.from_dlpack(buf). Then, all the custom kernels can be replaced by standard CuPy ops.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed. I removed the custom kernels, NVRTC and the bandwidth timing. The goal is to show that on Grace Hopper the GPU can work in place on host memory and the CPU sees the result without a copy. The sample now allocates from PinnedMemoryResource (on the GPU's host NUMA node), ManagedMemoryResource and DeviceMemoryResource, adds a plain NumPy array as pageable memory, wraps each one as a CuPy array, and uses only CuPy ops (*=, sum). The CPU writes the input and checks the result in the same memory.

One snag: cp.from_dlpack() works for the device and managed buffers, but CuPy 14.2 rejects the pinned buffer (kDLCUDAHost: TypeError: Unsupported array type: 3) and NumPy memory (kDLCPU). For those two the sample wraps the pointer with cupy.cuda.UnownedMemory in a small helper. Is there a better way to do this in CuPy?

Verified on GH200.

0z5a added 2 commits November 1, 2026 23:14
Wrap buffers from the pinned (host NUMA), managed and device memory
resources, plus a pageable NumPy array, as CuPy arrays and use standard
CuPy ops instead of custom kernels. Drop the bandwidth timing and the
NVML C2C query, and verify every result on the CPU.

cp.from_dlpack() does not import pinned or CPU memory, so those two are
wrapped with cupy.cuda.UnownedMemory.

Update the script dependencies to cuda-core[cu13], CuPy and NumPy, and
drop cuda-python.

Signed-off-by: 0z5a <dezhen.lu@student.uni-tuebingen.de>
cuda-core 1.2.2 supplies the APIs used by this sample. Lower the minimum version consistently in the script metadata, requirements, and README; verify the clean requirements and sample on GH200.

Signed-off-by: 0z5a <dezhen.lu@student.uni-tuebingen.de>

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

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.

3 participants