Skip to content

feat(cuda.core): support CU_LAUNCH_ATTRIBUTE_PRIORITY in LaunchConfig - #2706

Open
ichensun wants to merge 2 commits into
NVIDIA:mainfrom
ichensun:feat/issue-2631-launch-priority
Open

feat(cuda.core): support CU_LAUNCH_ATTRIBUTE_PRIORITY in LaunchConfig#2706
ichensun wants to merge 2 commits into
NVIDIA:mainfrom
ichensun:feat/issue-2631-launch-priority

Conversation

@ichensun

@ichensun ichensun commented Aug 26, 2026

Copy link
Copy Markdown

Description

issues #2631

Adds a priority attribute to LaunchConfig that maps to CU_LAUNCH_ATTRIBUTE_PRIORITY, following the same pattern used for programmatic_stream_serialization (#1334).

  • priority: int | None = None (default None) — when omitted, the launch uses the stream's priority, matching existing LaunchConfig attribute conventions.
  • The value is validated in __init__ against the device's stream priority range: a nonzero priority outside [greatestPriority, leastPriority], as returned by cuCtxGetStreamPriorityRange, raises ValueError.
  • The attribute is stored as a C int with 0 meaning "unset", so config.priority reads back 0 (not None) when omitted, and both native-config conversion paths (LaunchConfig._to_native_launch_config and the module-level _to_native_launch_config) use a truthiness check, emitting no launch attribute for 0. This makes an explicit priority=0 indistinguishable from an unset priority, which is behaviorally equivalent in practice: on devices without multiple stream priorities both bounds are 0, and elsewhere 0 is leastPriority, so omitting the attribute and inheriting the stream's priority yields the same scheduling.
  • Tests cover the getter/setter (including that direct assignment bypasses therange check), the native attribute mapping for unset/0/nonzero priorities, and an updated LaunchConfig repr pattern in test_object_protocols.py.

@copy-pr-bot

copy-pr-bot Bot commented Aug 26, 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 Aug 26, 2026
@lijinf2

lijinf2 commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

/ok to test b963404

@lijinf2 lijinf2 added the feature New feature or request label Aug 27, 2026
@lijinf2 lijinf2 added this to the cuda.core next milestone Aug 27, 2026
@github-actions

Copy link
Copy Markdown

Whether to allow programmatic stream serialization (PDL). When True,
the kernel may overlap with a previous kernel in the same stream that
signals completion via programmatic means.
priority : int, optional

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a range for the value we can set? It cannot be any number.
CUDA doc should provide guidance on what value to set. Let's include the guidance in docstring.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The range depends on the device, so there's no single fixed number to document. It's queried at runtime via cuCtxGetStreamPriorityRange(), which reports the valid bounds for the currently active context. On a device that doesn't support multiple stream priorities, both bounds come back as 0.

Comment thread cuda_core/cuda/core/_launch_config.pyi Outdated
Comment thread cuda_core/cuda/core/_launch_config.pyx Outdated
Comment thread cuda_core/cuda/core/_launch_config.pxd Outdated
public int shmem_size
public bint is_cooperative
public bint programmatic_stream_serialization
public object priority

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use int instead of obejct

@ichensun
ichensun force-pushed the feat/issue-2631-launch-priority branch from c71a56d to 070353d Compare September 2, 2026 00:25

@sylvesterkaczmarek sylvesterkaczmarek left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is still a semantic gap in the current head around priority=0.

StreamOptions uses None as the sentinel and treats 0 as a real priority. This PR now stores LaunchConfig.priority as an int, but both construction and native conversion use truthiness (if priority: / if self.priority:). That makes an explicit priority=0 indistinguishable from not specifying the launch attribute at all.

That matters when the launch runs on a nonzero-priority stream. For example, if the stream priority is -1 and the caller passes LaunchConfig(priority=0), the expected behavior is to emit CU_LAUNCH_ATTRIBUTE_PRIORITY=0 and override the stream priority. The current code emits no priority attribute, so the launch inherits -1 instead. This also conflicts with the PR description's original distinction that 0 is meaningful rather than an unset sentinel.

Could we keep the public/int storage requested in the earlier review but track whether the option was explicitly supplied separately (for example with a _priority_is_set flag), and add a regression that distinguishes None from 0?

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 feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants