cuda.core: expose wqConcurrencyLimit on WorkqueueResource#2329
Merged
Conversation
Add concurrency_limit to WorkqueueResourceOptions so callers can hint the expected maximum stream-ordered concurrency to the driver, and add a read-only WorkqueueResource.concurrency_limit property mirroring the driver-populated value. Also fix the sharing_scope-only early return in configure() so setting concurrency_limit alone isn't silently dropped.
Contributor
Fail-fast at construction rather than deferring both `sharing_scope` and `concurrency_limit` validation to `configure()`. This surfaces bad options immediately (and on any build, not just CUDA 13.x) and keeps the invariant colocated with the field it protects. Also add a 1.1.0 release-notes entry for the new field/property.
Member
Author
|
/ok to test ff5cdb3 |
Exercise sharing_scope + concurrency_limit end-to-end through green ctx creation and kernel launch, not just the property round-trip.
This comment has been minimized.
This comment has been minimized.
Member
Author
|
/ok to test 4416db4 |
Keep the surface symmetric with sharing_scope: configure() is the only way to set concurrency_limit, and there is no query-side property. The end-to-end verification lives in test_with_workqueue_resource, which now exercises a configured workqueue through green ctx creation and a kernel launch.
Member
Author
|
/ok to test 53ef8df |
Andy-Jost
approved these changes
Jul 9, 2026
leofang
enabled auto-merge (squash)
July 9, 2026 00:38
|
leofang
added a commit
to leofang/cuda-python
that referenced
this pull request
Jul 9, 2026
…enum test; add 2-GPU device check - Merge the two 1.1.0 workqueue entries into one bullet crediting both PRs. - Parametrize test_configure_scope_with_enum over both WorkqueueSharingScopeType members. - Add test_device_id_matches_source_multi_gpu verifying WorkqueueResource.device.device_id tracks the source device when the caller switches devices. Uses the established system.get_num_devices() < 2 skip pattern.
leofang
added a commit
that referenced
this pull request
Jul 9, 2026
* cuda.core: expose driver-populated fields on WorkqueueResource Add read-only sharing_scope, concurrency_limit, and device properties on WorkqueueResource so users can inspect the driver-populated config without dropping to raw cydriver. Add WorkqueueSharingScopeType StrEnum in cuda.core.typing to give the sharing scope a typed return; strings matching the enum member values remain accepted for backward compat. Follows section 5(d) "opaque but round-trippable" from the green ctx design doc, which was written into SMResource but not applied to WorkqueueResource. * cuda.core: fill in PR number in release-notes entry * cuda.core: drop TYPE_CHECKING Device import to satisfy cython-lint The lazy import inside WorkqueueResource.device already imports Device at call time; the top-level TYPE_CHECKING import was unused as far as cython-lint could see and blocked pre-commit. * cuda.core: fold #2329 + #2330 release notes; parametrize enum test; add 2-GPU device check - Merge the two 1.1.0 workqueue entries into one bullet crediting both PRs. - Parametrize test_configure_scope_with_enum over both WorkqueueSharingScopeType members. - Add test_device_id_matches_source_multi_gpu verifying WorkqueueResource.device.device_id tracks the source device when the caller switches devices. Uses the established system.get_num_devices() < 2 skip pattern. * cuda.core tests: drop init_cuda from multi-GPU workqueue test * cuda.core tests: drop unnecessary set_current calls in multi-GPU workqueue test cuDeviceGetDevResource doesn't require the device to be current; verified locally that cuCtxGetCurrent returns the same context before and after the test body. * cuda.core tests: extract shared _RESOURCE_UNAVAILABLE_ERRORS tuple with rationale * cuda.core: restore Device TYPE_CHECKING import with noqa mypy needs Device resolvable in the generated .pyi (WorkqueueResource.device returns 'Device' as a string forward reference); noqa: F401 keeps cython-lint from re-flagging it as unused. * cuda.core: simplify noqa to bare form (cython-lint didn't parse the parenthetical) * cuda.core: use bare Device annotation on WorkqueueResource.device cython-lint doesn't count string-quoted forward references as usage of the TYPE_CHECKING import. The bare form works because from __future__ import annotations makes it a string at runtime anyway (matches _stream.pyx pattern). * cuda.core tests: register WorkqueueSharingScopeType in _CASES test_all_str_enums_in_cases enforces that every StrEnum in cuda.core.typing is bound to a driver-side counterpart or explicitly marked unbound. WorkqueueSharingScopeType wraps CUdevWorkqueueConfigScope 1:1 — clean binding-coverage entry. * cuda.core tests: gate WorkqueueSharingScopeType binding entry on CUDA 13+ CUdevWorkqueueConfigScope doesn't exist in CUDA 12.x cuda_bindings, so importing test_enum_coverage crashed with AttributeError. Only register the binding-coverage entry when the driver exposes the enum; otherwise mark the wrapper as unbound so test_all_str_enums_in_cases still passes. Verified both paths locally (real CUDA 13 + delattr-simulated CUDA 12). * cuda.core tests: sharpen CUDA-version boundary in WorkqueueSharingScopeType comment CUdevWorkqueueConfigScope landed in the driver in 13.1, not 13.0. Update the inline comment on the hasattr gate to reflect that the missing-driver-enum path covers cuda-bindings for both CUDA 12.x and CUDA 13.0.x. * cuda.core: apply Mike's suggestion for WorkqueueResourceOptions.sharing_scope docstring * fix typing Co-authored-by: Michael Droettboom <mdboom@gmail.com> * Update _device_resources.pyi * cuda.core: regenerate .pyi to match stubgen-pyx output end-of-file-fixer excludes .pyi (per .pre-commit-config.yaml), so the trailing newline manually added in the previous commit made stubgen-pyx flag the file every run. Reverting to the newline-less form stubgen emits. * Apply suggestions from code review Co-authored-by: Michael Droettboom <mdboom@gmail.com> --------- Co-authored-by: Michael Droettboom <mdboom@gmail.com>
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.
Summary
Add
concurrency_limittoWorkqueueResourceOptions, so the user-facing options forWorkqueueResource.configure()mirror the driver's user-writable fields on the workqueue config (sharing_scope+concurrency_limit).Also fixes
WorkqueueResource.configure()where thesharing_scope is Noneearly return silently dropped any other option that might be set, and moves bothsharing_scopeandconcurrency_limitvalidation toWorkqueueResourceOptions.__post_init__so bad options fail at construction and are caught on any build (not just CUDA 13.x).Following the "no speculative sugar" principle, no query-side property is added —
configure()is the only user-facing setter, symmetric with howsharing_scopeworks today.Semantics
An input hint to the driver — "expected maximum number of concurrent stream-ordered workloads" — bounded in practice by
CUDA_DEVICE_MAX_CONNECTIONS(see CUDA docs). Values>= 1accepted; per the green contexts docs, configurations may exceed the driver-reported cap at the cost of the non-overlap guarantee, so no upper cap is enforced.Test coverage
Extended
TestWorkqueueResourceintest_green_context.py:configure(concurrency_limit=N)accepted on valid valuessharing_scope+concurrency_limitin oneconfigure()callWorkqueueResourceOptions(concurrency_limit=0)and negative values raiseValueErrorat constructionWorkqueueResourceOptions(sharing_scope="bogus")raisesValueErrorat construction (was: atconfigure())Extended
TestGreenContextKernelLaunch::test_with_workqueue_resourceto configure the workqueue with bothsharing_scope="green_ctx_balanced"andconcurrency_limit=4before green ctx creation + kernel launch, so the end-to-end path is exercised.Full
test_green_context.pylocally: 35 passed, 2 skipped (arch), zero regressions.Release notes entry added under 1.1.0 "New features".
Related: #1976 (green context support).
-- Leo's bot