add cuda 13 patch for cupy memadvise to host memory as used with SAM #1001
Merged
eordentlich merged 4 commits intoNVIDIA:mainfrom Dec 24, 2025
Merged
add cuda 13 patch for cupy memadvise to host memory as used with SAM #1001eordentlich merged 4 commits intoNVIDIA:mainfrom
eordentlich merged 4 commits intoNVIDIA:mainfrom
Conversation
Signed-off-by: Erik Ordentlich <eordentlich@gmail.com>
Signed-off-by: Erik Ordentlich <eordentlich@gmail.com>
Contributor
Greptile SummaryThis PR implements a workaround for a CuPy 13.6 bug in the memAdvise API when using CUDA 13. The changes introduce a new helper function
The helper function is then used consistently across Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Caller as Algorithm Code<br/>(clustering/core/umap)
participant Helper as _memadvise_cpu
participant Version as cuda.bindings.__version__
participant CuPy as cp.cuda.runtime.memAdvise<br/>(CUDA < 13)
participant CudaPython as cuda.bindings.runtime<br/>(CUDA >= 13)
Note over Caller: SAM enabled with numpy array
Caller->>Helper: _memadvise_cpu(data, nbytes)
Helper->>Version: Check cuda.bindings.__version__
alt CUDA < 13.0.0
Version-->>Helper: version < 13.0.0
Helper->>CuPy: memAdvise(data, nbytes, 3, -1)
Note over CuPy: Uses CuPy API<br/>(original method)
CuPy-->>Helper: Success
else CUDA >= 13.0.0
Version-->>Helper: version >= 13.0.0
Note over Helper: Workaround for CuPy 13.6 bug
Helper->>CudaPython: Import cudaMemLocation,<br/>cudaMemLocationType,<br/>cudaMemoryAdvise
Helper->>Helper: Create cudaMemLocation<br/>with Host type
Helper->>CudaPython: cudaMemAdvise(data, nbytes,<br/>SetPreferredLocation, mem_location)
Note over CudaPython: Uses low-level<br/>cuda-python bindings
CudaPython-->>Helper: Success
end
Helper-->>Caller: Memory pinned to CPU
Note over Caller: Prevents page migration<br/>during GPU concatenation
|
Collaborator
Author
|
build |
rishic3
previously approved these changes
Dec 24, 2025
Collaborator
rishic3
left a comment
There was a problem hiding this comment.
LGTM, minor rewording suggestion
python/src/spark_rapids_ml/utils.py
Outdated
| def _memadvise_cpu(data: Any, nbytes: int) -> None: | ||
| """ | ||
| Advise data referenced by pointer to stay in cpu memory. | ||
| For use with SAM to prevent migration of host memory staged partial matrices to remain on cpu during |
Collaborator
There was a problem hiding this comment.
Suggested change
| For use with SAM to prevent migration of host memory staged partial matrices to remain on cpu during | |
| For use with SAM to prevent partial matrices staged on host from migrating to device during |
Signed-off-by: Erik Ordentlich <eordentlich@gmail.com>
Collaborator
Author
|
build |
rishic3
approved these changes
Dec 24, 2025
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
No description provided.