-
Notifications
You must be signed in to change notification settings - Fork 31
retain global pointers to previous default rmm memory resources #995
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -163,17 +163,29 @@ def _get_gpu_id(task_context: TaskContext) -> int: | |||||||||
| return gpu_id | ||||||||||
|
|
||||||||||
|
|
||||||||||
| # When changing default rmm memory resources we retain the old ones | ||||||||||
| # in this global array singleton to so that any (C++) allocations using them can | ||||||||||
| # invoke the corresponding deallocate methods. They will get cleaned up only when | ||||||||||
| # the process exits. This avoids a segfault in the case of creating a new | ||||||||||
| # SAM resource with a smaller headroom. | ||||||||||
| _old_memory_resources = [] | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: potential thread safety issue if
Suggested change
|
||||||||||
|
|
||||||||||
| # keep track of last headroom to check if new sam mr is needed. | ||||||||||
| _last_sam_headroom_size = None | ||||||||||
|
|
||||||||||
|
|
||||||||||
| def _configure_memory_resource( | ||||||||||
| uvm_enabled: bool = False, | ||||||||||
| sam_enabled: bool = False, | ||||||||||
| sam_headroom: Optional[int] = None, | ||||||||||
| force_sam_headroom: bool = False, | ||||||||||
| ) -> None: | ||||||||||
| import cupy as cp | ||||||||||
| import rmm | ||||||||||
| from cuda.bindings import runtime | ||||||||||
| from rmm.allocators.cupy import rmm_cupy_allocator | ||||||||||
|
|
||||||||||
| global _last_sam_headroom_size | ||||||||||
|
|
||||||||||
| _SYSTEM_MEMORY_SUPPORTED = rmm._cuda.gpu.getDeviceAttribute( | ||||||||||
| runtime.cudaDeviceAttr.cudaDevAttrPageableMemoryAccess, | ||||||||||
| rmm._cuda.gpu.getDevice(), | ||||||||||
|
|
@@ -193,19 +205,24 @@ def _configure_memory_resource( | |||||||||
| if not type(rmm.mr.get_current_device_resource()) == type( | ||||||||||
| rmm.mr.SystemMemoryResource() | ||||||||||
| ): | ||||||||||
| _old_memory_resources.append(rmm.mr.get_current_device_resource()) | ||||||||||
| _last_sam_headroom_size = None | ||||||||||
| mr = rmm.mr.SystemMemoryResource() | ||||||||||
| rmm.mr.set_current_device_resource(mr) | ||||||||||
| elif sam_enabled and sam_headroom is not None: | ||||||||||
| if force_sam_headroom or not type(rmm.mr.get_current_device_resource()) == type( | ||||||||||
| rmm.mr.SamHeadroomMemoryResource(headroom=sam_headroom) | ||||||||||
| ): | ||||||||||
| if sam_headroom != _last_sam_headroom_size or not type( | ||||||||||
| rmm.mr.get_current_device_resource() | ||||||||||
| ) == type(rmm.mr.SamHeadroomMemoryResource(headroom=sam_headroom)): | ||||||||||
| _old_memory_resources.append(rmm.mr.get_current_device_resource()) | ||||||||||
| _last_sam_headroom_size = sam_headroom | ||||||||||
| mr = rmm.mr.SamHeadroomMemoryResource(headroom=sam_headroom) | ||||||||||
| rmm.mr.set_current_device_resource(mr) | ||||||||||
|
|
||||||||||
| if uvm_enabled: | ||||||||||
| if not type(rmm.mr.get_current_device_resource()) == type( | ||||||||||
| rmm.mr.ManagedMemoryResource() | ||||||||||
| ): | ||||||||||
| _old_memory_resources.append(rmm.mr.get_current_device_resource()) | ||||||||||
| rmm.mr.set_current_device_resource(rmm.mr.ManagedMemoryResource()) | ||||||||||
|
|
||||||||||
| if sam_enabled or uvm_enabled: | ||||||||||
|
|
||||||||||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does that cause the memory already allocated within the default RMM mem resources not to be freed?