Skip to content

cuda.core: expose wqConcurrencyLimit on WorkqueueResource#2329

Merged
leofang merged 7 commits into
NVIDIA:mainfrom
leofang:leof/wq-concurrency-limit
Jul 9, 2026
Merged

cuda.core: expose wqConcurrencyLimit on WorkqueueResource#2329
leofang merged 7 commits into
NVIDIA:mainfrom
leofang:leof/wq-concurrency-limit

Conversation

@leofang

@leofang leofang commented Jul 8, 2026

Copy link
Copy Markdown
Member

Summary

Add concurrency_limit to WorkqueueResourceOptions, so the user-facing options for WorkqueueResource.configure() mirror the driver's user-writable fields on the workqueue config (sharing_scope + concurrency_limit).

Also fixes WorkqueueResource.configure() where the sharing_scope is None early return silently dropped any other option that might be set, and moves both sharing_scope and concurrency_limit validation to WorkqueueResourceOptions.__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 how sharing_scope works 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 >= 1 accepted; 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 TestWorkqueueResource in test_green_context.py:

  • configure(concurrency_limit=N) accepted on valid values
  • combined sharing_scope + concurrency_limit in one configure() call
  • WorkqueueResourceOptions(concurrency_limit=0) and negative values raise ValueError at construction
  • WorkqueueResourceOptions(sharing_scope="bogus") raises ValueError at construction (was: at configure())

Extended TestGreenContextKernelLaunch::test_with_workqueue_resource to configure the workqueue with both sharing_scope="green_ctx_balanced" and concurrency_limit=4 before green ctx creation + kernel launch, so the end-to-end path is exercised.

Full test_green_context.py locally: 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

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.
@copy-pr-bot

copy-pr-bot Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@github-actions github-actions Bot added the cuda.core Everything related to the cuda.core module label Jul 8, 2026
@leofang leofang added the enhancement Any code-related improvements label Jul 8, 2026
@leofang leofang self-assigned this Jul 8, 2026
@leofang leofang added this to the cuda.core v1.1.0 milestone Jul 8, 2026
leofang added 3 commits July 8, 2026 22:19
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.
@leofang

leofang commented Jul 8, 2026

Copy link
Copy Markdown
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.
@github-actions

This comment has been minimized.

@leofang

leofang commented Jul 8, 2026

Copy link
Copy Markdown
Member Author

/ok to test 4416db4

@leofang
leofang requested a review from Andy-Jost July 8, 2026 23:24
@leofang leofang added the P0 High priority - Must do! label Jul 8, 2026
@leofang
leofang marked this pull request as ready for review July 8, 2026 23:24
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.
@leofang

leofang commented Jul 8, 2026

Copy link
Copy Markdown
Member Author

/ok to test 53ef8df

@leofang
leofang enabled auto-merge (squash) July 9, 2026 00:38
@leofang
leofang merged commit c08caa8 into NVIDIA:main Jul 9, 2026
200 of 202 checks passed
@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
Doc Preview CI
Preview removed because the pull request was closed or merged.

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
leofang deleted the leof/wq-concurrency-limit branch July 9, 2026 03:20
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cuda.core Everything related to the cuda.core module enhancement Any code-related improvements P0 High priority - Must do!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants