Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 321
cuda.core: expose driver-populated fields on WorkqueueResource#2330
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
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
1c6a5e1
cuda.core: expose driver-populated fields on WorkqueueResource
leofang 2afae3f
cuda.core: fill in PR number in release-notes entry
leofang a22005d
cuda.core: drop TYPE_CHECKING Device import to satisfy cython-lint
leofang 08a6419
cuda.core: fold #2329 + #2330 release notes; parametrize enum test; a…
leofang e4ebbba
cuda.core tests: drop init_cuda from multi-GPU workqueue test
leofang 1c3ceb7
cuda.core tests: drop unnecessary set_current calls in multi-GPU work…
leofang 9092dc4
cuda.core tests: extract shared _RESOURCE_UNAVAILABLE_ERRORS tuple wi…
leofang aebf271
cuda.core: restore Device TYPE_CHECKING import with noqa
leofang cb15baf
cuda.core: simplify noqa to bare form (cython-lint didn't parse the p…
leofang 202959b
cuda.core: use bare Device annotation on WorkqueueResource.device
leofang 0a1c7df
cuda.core tests: register WorkqueueSharingScopeType in _CASES
leofang 8fd22bc
cuda.core tests: gate WorkqueueSharingScopeType binding entry on CUDA…
leofang 106d5c1
cuda.core tests: sharpen CUDA-version boundary in WorkqueueSharingSco…
leofang be917b6
cuda.core: apply Mike's suggestion for WorkqueueResourceOptions.shari…
leofang a9939b5
fix typing
leofang 37483ae
Update _device_resources.pyi
leofang ccb50cc
cuda.core: regenerate .pyi to match stubgen-pyx output
leofang 119238b
Apply suggestions from code review
leofang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -6,6 +6,11 @@ from __future__ import annotations | ||
| from collections.abc import Sequence as SequenceABC | ||
| from dataclasses import dataclass | ||
| from typing import TYPE_CHECKING | ||
| if TYPE_CHECKING: | ||
| from cuda.core._device import Device | ||
| from cuda.core.typing import WorkqueueSharingScopeType | ||
| from libc.stdint cimport intptr_t | ||
| from libc.stdlib cimport free, malloc | ||
| @@ -126,9 +131,9 @@ cdef class WorkqueueResourceOptions: | ||
| Attributes | ||
| ---------- | ||
| sharing_scope : str, optional | ||
| Workqueue sharing scope. Accepted values: ``"device_ctx"`` | ||
| or ``"green_ctx_balanced"``. (Default to ``None``) | ||
| sharing_scope : :class:`~cuda.core.typing.WorkqueueSharingScopeType` | str, optional | ||
| Workqueue sharing scope. Accepted values: ``"device_ctx"`` or | ||
| ``"green_ctx_balanced"``. | ||
| concurrency_limit : int, optional | ||
| Expected maximum number of concurrent stream-ordered | ||
| workloads. Must be ``>= 1`` when set. The effective | ||
| @@ -138,7 +143,7 @@ cdef class WorkqueueResourceOptions: | ||
| submission remains non-overlapping. (Default to ``None``) | ||
| """ | ||
| sharing_scope: str | None = None | ||
| sharing_scope: WorkqueueSharingScopeType | str | None = None | ||
| concurrency_limit: int | None = None | ||
| def __post_init__(self): | ||
| @@ -554,6 +559,57 @@ cdef class WorkqueueResource: | ||
| """Return the address of the underlying config ``CUdevResource`` struct.""" | ||
| return <intptr_t>(&self._wq_config_resource) | ||
| @property | ||
| def sharing_scope(self) -> WorkqueueSharingScopeType: | ||
| """Current sharing scope of this workqueue resource. | ||
| Returns the :class:`~cuda.core.typing.WorkqueueSharingScopeType` | ||
| member corresponding to the driver-populated | ||
| ``wqConfig.sharingScope`` field. It can be updated via | ||
| :meth:`configure` with | ||
| :attr:`WorkqueueResourceOptions.sharing_scope`. | ||
| """ | ||
| IF CUDA_CORE_BUILD_MAJOR >= 13: | ||
| from cuda.core.typing import WorkqueueSharingScopeType | ||
| cdef object scope = self._wq_config_resource.wqConfig.sharingScope | ||
| if scope == cydriver.CUdevWorkqueueConfigScope.CU_WORKQUEUE_SCOPE_DEVICE_CTX: | ||
| return WorkqueueSharingScopeType.DEVICE_CTX | ||
| elif scope == cydriver.CUdevWorkqueueConfigScope.CU_WORKQUEUE_SCOPE_GREEN_CTX_BALANCED: | ||
| return WorkqueueSharingScopeType.GREEN_CTX_BALANCED | ||
| raise RuntimeError(f"Unknown sharing scope enum value: {scope}") | ||
leofang marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| ELSE: | ||
| raise RuntimeError( | ||
| "WorkqueueResource requires cuda.core to be built with CUDA 13.x bindings" | ||
| ) | ||
| @property | ||
| def concurrency_limit(self) -> int: | ||
| """Current expected maximum concurrent stream-ordered workloads. | ||
| Reflects the driver-populated ``wqConfig.wqConcurrencyLimit`` field. | ||
| When first queried from a device, this matches the driver-reported | ||
| cap (typically ``CUDA_DEVICE_MAX_CONNECTIONS``). It can be updated | ||
| via :meth:`configure` with | ||
| :attr:`WorkqueueResourceOptions.concurrency_limit`. | ||
| """ | ||
| IF CUDA_CORE_BUILD_MAJOR >= 13: | ||
| return self._wq_config_resource.wqConfig.wqConcurrencyLimit | ||
| ELSE: | ||
| raise RuntimeError( | ||
| "WorkqueueResource requires cuda.core to be built with CUDA 13.x bindings" | ||
| ) | ||
| @property | ||
| def device(self) -> Device: | ||
| """The :class:`~cuda.core.Device` this workqueue resource is available on.""" | ||
| IF CUDA_CORE_BUILD_MAJOR >= 13: | ||
| from cuda.core._device import Device # avoid circular import | ||
| return Device(int(self._wq_config_resource.wqConfig.device)) | ||
| ELSE: | ||
| raise RuntimeError( | ||
| "WorkqueueResource requires cuda.core to be built with CUDA 13.x bindings" | ||
| ) | ||
| def configure(self, options: WorkqueueResourceOptions) -> None: | ||
| """Configure the workqueue resource in place. | ||
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 |
|---|---|---|
| @@ -106,9 +106,19 @@ New features | ||
| (`#2068 <https://github.com/NVIDIA/cuda-python/pull/2068>`__, | ||
| closes `#2049 <https://github.com/NVIDIA/cuda-python/issues/2049>`__) | ||
| - Added ``concurrency_limit`` to :class:`WorkqueueResourceOptions` to | ||
| configure the expected maximum concurrent stream-ordered workloads. | ||
| (`#2329 <https://github.com/NVIDIA/cuda-python/pull/2329>`__) | ||
| - Extended :class:`WorkqueueResource` and :class:`WorkqueueResourceOptions` | ||
| to cover the full driver-side workqueue-config surface. Added | ||
| ``concurrency_limit`` to :class:`WorkqueueResourceOptions` for | ||
| configuring the expected maximum concurrent stream-ordered workloads, | ||
| and read-only :attr:`WorkqueueResource.sharing_scope`, | ||
| :attr:`~WorkqueueResource.concurrency_limit`, and | ||
| :attr:`~WorkqueueResource.device` properties for round-tripping the | ||
| driver-populated values. Added | ||
| :class:`~cuda.core.typing.WorkqueueSharingScopeType` StrEnum accepted | ||
| by :attr:`WorkqueueResourceOptions.sharing_scope` in addition to raw | ||
| strings. | ||
| (`#2329 <https://github.com/NVIDIA/cuda-python/pull/2329>`__, | ||
| `#2330 <https://github.com/NVIDIA/cuda-python/pull/2330>`__) | ||
leofang marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| Fixes and enhancements | ||
| ---------------------- | ||
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
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.
nit: Could use a
matchstatement here.