-
Notifications
You must be signed in to change notification settings - Fork 245
Warn when ManagedMemoryResource is created without concurrent managed access #1618
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
Open
Andy-Jost
wants to merge
1
commit into
NVIDIA:main
Choose a base branch
from
Andy-Jost:warn-managed-memory-no-concurrent-access
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+127
−2
Open
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| """ | ||
| Test that a warning is emitted when ManagedMemoryResource is created on a | ||
| platform without concurrent managed memory access. | ||
|
|
||
| These tests only run on affected platforms (concurrent_managed_access is False). | ||
| """ | ||
|
|
||
| import warnings | ||
|
|
||
| import pytest | ||
| from cuda.core import Device, ManagedMemoryResource, ManagedMemoryResourceOptions | ||
| from cuda.core._memory._managed_memory_resource import reset_concurrent_access_warning | ||
|
|
||
|
|
||
| def _make_managed_mr(device_id): | ||
| """Create a ManagedMemoryResource with an explicit device preference.""" | ||
| return ManagedMemoryResource(options=ManagedMemoryResourceOptions(preferred_location=device_id)) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def device_without_concurrent_managed_access(init_cuda): | ||
| """Return a device that lacks concurrent managed access, or skip.""" | ||
| device = Device() | ||
| device.set_current() | ||
|
|
||
| try: | ||
| pools_supported = device.properties.memory_pools_supported | ||
| except AttributeError: | ||
| pytest.skip("ManagedMemoryResource requires CUDA 13.0 or later") | ||
|
|
||
| if not pools_supported: | ||
| pytest.skip("Device does not support memory pools") | ||
|
|
||
| if device.properties.concurrent_managed_access: | ||
| pytest.skip("Device supports concurrent managed access; warning not applicable") | ||
|
|
||
| return device | ||
|
|
||
|
|
||
| def test_warning_emitted(device_without_concurrent_managed_access): | ||
| """ManagedMemoryResource emits a warning when concurrent managed access is unsupported.""" | ||
| dev_id = device_without_concurrent_managed_access.device_id | ||
| reset_concurrent_access_warning() | ||
|
|
||
| with warnings.catch_warnings(record=True) as w: | ||
| warnings.simplefilter("always") | ||
| mr = _make_managed_mr(dev_id) | ||
|
|
||
| concurrent_warnings = [ | ||
| warning for warning in w if "concurrent managed memory access" in str(warning.message).lower() | ||
| ] | ||
| assert len(concurrent_warnings) == 1 | ||
| assert concurrent_warnings[0].category is UserWarning | ||
| assert "segfault" in str(concurrent_warnings[0].message).lower() | ||
|
|
||
| mr.close() | ||
|
|
||
|
|
||
| def test_warning_emitted_only_once(device_without_concurrent_managed_access): | ||
| """Warning fires only once even when multiple ManagedMemoryResources are created.""" | ||
| dev_id = device_without_concurrent_managed_access.device_id | ||
| reset_concurrent_access_warning() | ||
|
|
||
| with warnings.catch_warnings(record=True) as w: | ||
| warnings.simplefilter("always") | ||
| mr1 = _make_managed_mr(dev_id) | ||
| mr2 = _make_managed_mr(dev_id) | ||
|
|
||
| concurrent_warnings = [ | ||
| warning for warning in w if "concurrent managed memory access" in str(warning.message).lower() | ||
| ] | ||
| assert len(concurrent_warnings) == 1 | ||
|
|
||
| mr1.close() | ||
| mr2.close() |
Oops, something went wrong.
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.
I think we want https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#gpu-exclusive-access-to-managed-memory as the link?