Skip to content

Commit 71763c5

Browse files
Omar Atiecursoragent
authored andcommitted
revert(cuda.core): drop LaunchConfig.synchronization_policy (NVIDIA#2637)
CU_LAUNCH_ATTRIBUTE_SYNCHRONIZATION_POLICY is not accepted by cuLaunchKernelEx, so the per-launch API requested in NVIDIA#2628 cannot be implemented. Every GPU test job rejected the launch with CUDA_ERROR_INVALID_VALUE on CUDA 12.9, 13.0 and 13.3 across linux-64, linux-aarch64 and win-64. CUDA documents this attribute as "Valid for streams", unlike CU_LAUNCH_ATTRIBUTE_COOPERATIVE which is "Valid for graph nodes, launches". A driver-level probe on an RTX A4000 (driver 550.144.03, cuda-bindings 12.9.7) confirms the distinction is real: the same no-op kernel launches successfully with no attributes and with COOPERATIVE, but returns CUDA_ERROR_INVALID_VALUE for all four synchronization policies, while cuStreamSetAttribute accepts the same values. Revert the feature so this branch matches main, and defer to maintainers on whether NVIDIA#2628 should be re-scoped to a stream-level API. Co-authored-by: Cursor <[email protected]>
1 parent 21c56b0 commit 71763c5

7 files changed

Lines changed: 4 additions & 186 deletions

File tree

‎cuda_core/cuda/core/_launch_config.pxd‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ cdef class LaunchConfig:
1616
public int shmem_size
1717
public bint is_cooperative
1818
public bint programmatic_stream_serialization
19-
public object synchronization_policy
2019

2120
vector[cydriver.CUlaunchAttribute] _attrs
2221
object __weakref__

‎cuda_core/cuda/core/_launch_config.pyi‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,9 @@ class LaunchConfig:
3939
Whether to allow programmatic stream serialization (PDL). When True,
4040
the kernel may overlap with a previous kernel in the same stream that
4141
signals completion via programmatic means.
42-
synchronization_policy : SynchronizationPolicyType | None, optional
43-
CPU wait policy applied when synchronizing the launch stream after this
44-
kernel. Maps to ``CU_LAUNCH_ATTRIBUTE_SYNCHRONIZATION_POLICY``.
4542
"""
4643

47-
def __init__(self, grid: int | tuple[int, ...] | None=None, cluster: int | tuple[int, ...] | None=None, block: int | tuple[int, ...] | None=None, shmem_size: int | None=None, is_cooperative: bool=False, programmatic_stream_serialization: bool=False, synchronization_policy: object=None) -> None:
44+
def __init__(self, grid: int | tuple[int, ...] | None=None, cluster: int | tuple[int, ...] | None=None, block: int | tuple[int, ...] | None=None, shmem_size: int | None=None, is_cooperative: bool=False, programmatic_stream_serialization: bool=False) -> None:
4845
"""Initialize LaunchConfig with validation.
4946
5047
Parameters
@@ -61,8 +58,6 @@ class LaunchConfig:
6158
Whether to launch as cooperative kernel (default: False)
6259
programmatic_stream_serialization : bool, optional
6360
Whether to allow programmatic stream serialization / PDL (default: False)
64-
synchronization_policy : SynchronizationPolicyType | None, optional
65-
CPU wait policy for synchronizing the launch stream (default: None)
6661
"""
6762

6863
def _identity(self) -> tuple[Any, ...]:
@@ -76,7 +71,7 @@ class LaunchConfig:
7671

7772
def __hash__(self) -> int:
7873
...
79-
_LAUNCH_CONFIG_ATTRS = ('grid', 'cluster', 'block', 'shmem_size', 'is_cooperative', 'programmatic_stream_serialization', 'synchronization_policy')
74+
_LAUNCH_CONFIG_ATTRS = ('grid', 'cluster', 'block', 'shmem_size', 'is_cooperative', 'programmatic_stream_serialization')
8075
__all__ = ['LaunchConfig']
8176

8277
def _to_native_launch_config(config: LaunchConfig) -> object:

‎cuda_core/cuda/core/_launch_config.pyx‎

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -20,32 +20,8 @@ _LAUNCH_CONFIG_ATTRS = (
2020
'shmem_size',
2121
'is_cooperative',
2222
'programmatic_stream_serialization',
23-
'synchronization_policy',
2423
)
2524

26-
27-
cdef object _validate_synchronization_policy(object policy):
28-
from cuda.core.typing import SynchronizationPolicyType
29-
30-
if policy is None:
31-
return None
32-
if isinstance(policy, SynchronizationPolicyType):
33-
return policy
34-
try:
35-
value = int(policy)
36-
except (TypeError, ValueError) as exc:
37-
raise TypeError(
38-
"LaunchConfig.synchronization_policy must be a SynchronizationPolicyType, "
39-
f"cuda.bindings.driver.CUsynchronizationPolicy, or int; got {type(policy).__name__}"
40-
) from exc
41-
try:
42-
return SynchronizationPolicyType(value)
43-
except ValueError as exc:
44-
raise ValueError(
45-
f"LaunchConfig.synchronization_policy must be one of "
46-
f"{[member.name for member in SynchronizationPolicyType]}; got {policy!r}"
47-
) from exc
48-
4925
__all__ = ['LaunchConfig']
5026

5127

@@ -83,9 +59,6 @@ cdef class LaunchConfig:
8359
Whether to allow programmatic stream serialization (PDL). When True,
8460
the kernel may overlap with a previous kernel in the same stream that
8561
signals completion via programmatic means.
86-
synchronization_policy : SynchronizationPolicyType | None, optional
87-
CPU wait policy applied when synchronizing the launch stream after this
88-
kernel. Maps to ``CU_LAUNCH_ATTRIBUTE_SYNCHRONIZATION_POLICY``.
8962
"""
9063

9164
# TODO: expand LaunchConfig to include other attributes
@@ -99,7 +72,6 @@ cdef class LaunchConfig:
9972
shmem_size: int | None = None,
10073
is_cooperative: bool = False,
10174
programmatic_stream_serialization: bool = False,
102-
synchronization_policy: object = None,
10375
) -> None:
10476
"""Initialize LaunchConfig with validation.
10577

@@ -117,8 +89,6 @@ cdef class LaunchConfig:
11789
Whether to launch as cooperative kernel (default: False)
11890
programmatic_stream_serialization : bool, optional
11991
Whether to allow programmatic stream serialization / PDL (default: False)
120-
synchronization_policy : SynchronizationPolicyType | None, optional
121-
CPU wait policy for synchronizing the launch stream (default: None)
12292
"""
12393
# Convert and validate grid and block dimensions
12494
self.grid = cast_to_3_tuple("LaunchConfig.grid", grid)
@@ -146,7 +116,6 @@ cdef class LaunchConfig:
146116

147117
self.is_cooperative = is_cooperative
148118
self.programmatic_stream_serialization = programmatic_stream_serialization
149-
self.synchronization_policy = _validate_synchronization_policy(synchronization_policy)
150119

151120
if self.is_cooperative and not Device().properties.cooperative_launch:
152121
raise CUDAError("cooperative kernels are not supported on this device")
@@ -170,7 +139,6 @@ cdef class LaunchConfig:
170139
cdef cydriver.CUlaunchConfig _to_native_launch_config(self):
171140
cdef cydriver.CUlaunchConfig drv_cfg
172141
cdef cydriver.CUlaunchAttribute attr
173-
cdef int sync_policy_value
174142
memset(&drv_cfg, 0, sizeof(drv_cfg))
175143
self._attrs.resize(0)
176144

@@ -201,12 +169,6 @@ cdef class LaunchConfig:
201169
attr.value.programmaticStreamSerializationAllowed = 1
202170
self._attrs.push_back(attr)
203171

204-
if self.synchronization_policy is not None:
205-
sync_policy_value = int(self.synchronization_policy)
206-
attr.id = cydriver.CUlaunchAttributeID.CU_LAUNCH_ATTRIBUTE_SYNCHRONIZATION_POLICY
207-
attr.value.syncPolicy = <cydriver.CUsynchronizationPolicy>sync_policy_value
208-
self._attrs.push_back(attr)
209-
210172
drv_cfg.numAttrs = self._attrs.size()
211173
drv_cfg.attrs = self._attrs.data()
212174

@@ -268,14 +230,6 @@ cpdef object _to_native_launch_config(LaunchConfig config):
268230
attr.value.programmaticStreamSerializationAllowed = 1
269231
attrs.append(attr)
270232

271-
if config.synchronization_policy is not None:
272-
attr = driver.CUlaunchAttribute()
273-
attr.id = driver.CUlaunchAttributeID.CU_LAUNCH_ATTRIBUTE_SYNCHRONIZATION_POLICY
274-
attr.value.syncPolicy = driver.CUsynchronizationPolicy(
275-
int(config.synchronization_policy)
276-
)
277-
attrs.append(attr)
278-
279233
drv_cfg.numAttrs = len(attrs)
280234
drv_cfg.attrs = attrs
281235

‎cuda_core/cuda/core/typing.py‎

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"""Public type aliases, protocols, and enumerations used in cuda.core API signatures."""
66

77
import sys
8-
from enum import IntEnum
98
from typing import TYPE_CHECKING
109
from typing import Literal as _Literal
1110
from typing import TypeAlias as _TypeAlias
@@ -48,7 +47,6 @@ class StrEnum(str, Enum):
4847
"ProcessStateType",
4948
"ReadModeType",
5049
"SourceCodeType",
51-
"SynchronizationPolicyType",
5250
"VirtualMemoryAccessType",
5351
"VirtualMemoryAllocationType",
5452
"VirtualMemoryGranularityType",
@@ -126,24 +124,6 @@ class PCHStatusType(StrEnum):
126124
FAILED = "failed"
127125

128126

129-
class SynchronizationPolicyType(IntEnum):
130-
"""CPU wait policy for host-side stream synchronization after a launch.
131-
132-
Maps to ``CU_LAUNCH_ATTRIBUTE_SYNCHRONIZATION_POLICY`` and
133-
``cuda.bindings.driver.CUsynchronizationPolicy``.
134-
135-
* ``AUTO`` — inherit the stream's synchronization policy.
136-
* ``SPIN`` — busy-wait on the CPU (lowest latency).
137-
* ``YIELD`` — yield the CPU while waiting.
138-
* ``BLOCKING_SYNC`` — block in the OS scheduler while waiting.
139-
"""
140-
141-
AUTO = driver.CUsynchronizationPolicy.CU_SYNC_POLICY_AUTO
142-
SPIN = driver.CUsynchronizationPolicy.CU_SYNC_POLICY_SPIN
143-
YIELD = driver.CUsynchronizationPolicy.CU_SYNC_POLICY_YIELD
144-
BLOCKING_SYNC = driver.CUsynchronizationPolicy.CU_SYNC_POLICY_BLOCKING_SYNC
145-
146-
147127
class GraphConditionalType(StrEnum):
148128
"""Conditional node flavor for :class:`~cuda.core.graph.GraphBuilder`.
149129

‎cuda_core/docs/source/api_private.rst‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ CUDA runtime
3535
typing.ProcessStateType
3636
typing.ReadModeType
3737
typing.SourceCodeType
38-
typing.SynchronizationPolicyType
3938
typing.VirtualMemoryAccessType
4039
typing.VirtualMemoryAllocationType
4140
typing.VirtualMemoryGranularityType

‎cuda_core/tests/test_launcher.py‎

Lines changed: 1 addition & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import pytest
1616
from conftest import skipif_need_cuda_headers
1717

18-
from cuda.bindings import driver
1918
from cuda.core import (
2019
Device,
2120
DeviceMemoryResource,
@@ -27,7 +26,7 @@
2726
)
2827
from cuda.core._memory._legacy import _SynchronousMemoryResource
2928
from cuda.core._utils.cuda_utils import CUDAError
30-
from cuda.core.typing import ObjectCodeFormatType, SourceCodeType, SynchronizationPolicyType
29+
from cuda.core.typing import ObjectCodeFormatType, SourceCodeType
3130

3231

3332
def test_launch_config_init(init_cuda):
@@ -203,114 +202,6 @@ def test_to_native_launch_config_pdl():
203202
)
204203

205204

206-
@pytest.mark.parametrize(
207-
("policy", "expected_value"),
208-
[
209-
(SynchronizationPolicyType.AUTO, driver.CUsynchronizationPolicy.CU_SYNC_POLICY_AUTO),
210-
(SynchronizationPolicyType.SPIN, driver.CUsynchronizationPolicy.CU_SYNC_POLICY_SPIN),
211-
(SynchronizationPolicyType.YIELD, driver.CUsynchronizationPolicy.CU_SYNC_POLICY_YIELD),
212-
(
213-
SynchronizationPolicyType.BLOCKING_SYNC,
214-
driver.CUsynchronizationPolicy.CU_SYNC_POLICY_BLOCKING_SYNC,
215-
),
216-
(driver.CUsynchronizationPolicy.CU_SYNC_POLICY_SPIN, driver.CUsynchronizationPolicy.CU_SYNC_POLICY_SPIN),
217-
],
218-
)
219-
def test_to_native_launch_config_synchronization_policy(policy, expected_value):
220-
"""LaunchConfig.synchronization_policy maps to CU_LAUNCH_ATTRIBUTE_SYNCHRONIZATION_POLICY."""
221-
from cuda.core._launch_config import _to_native_launch_config
222-
223-
config = LaunchConfig(grid=1, block=1, synchronization_policy=policy)
224-
assert config.synchronization_policy == SynchronizationPolicyType(int(expected_value))
225-
226-
native = _to_native_launch_config(config)
227-
assert native.numAttrs == 1
228-
attr = native.attrs[0]
229-
assert attr.id == driver.CUlaunchAttributeID.CU_LAUNCH_ATTRIBUTE_SYNCHRONIZATION_POLICY
230-
assert attr.value.syncPolicy == expected_value
231-
232-
233-
def test_launch_config_synchronization_policy_default():
234-
config = LaunchConfig(grid=1, block=1)
235-
assert config.synchronization_policy is None
236-
237-
from cuda.core._launch_config import _to_native_launch_config
238-
239-
native = _to_native_launch_config(config)
240-
assert native.numAttrs == 0
241-
242-
243-
@pytest.mark.parametrize("invalid_policy", ["spin", -1, 99])
244-
def test_launch_config_synchronization_policy_invalid(invalid_policy):
245-
with pytest.raises((TypeError, ValueError)):
246-
LaunchConfig(grid=1, block=1, synchronization_policy=invalid_policy)
247-
248-
249-
def test_to_native_launch_config_synchronization_policy_with_cooperative(monkeypatch):
250-
"""synchronization_policy can be combined with other launch attributes."""
251-
from cuda.core import _launch_config as _lc_mod
252-
from cuda.core._launch_config import _to_native_launch_config
253-
254-
class _FakeProps:
255-
cooperative_launch = True
256-
257-
class _FakeDev:
258-
properties = _FakeProps()
259-
260-
monkeypatch.setattr(_lc_mod, "Device", lambda: _FakeDev())
261-
262-
config = LaunchConfig(
263-
grid=1,
264-
block=1,
265-
is_cooperative=True,
266-
synchronization_policy=SynchronizationPolicyType.SPIN,
267-
)
268-
native = _to_native_launch_config(config)
269-
assert native.numAttrs == 2
270-
attr_ids = {attr.id for attr in native.attrs}
271-
assert driver.CUlaunchAttributeID.CU_LAUNCH_ATTRIBUTE_COOPERATIVE in attr_ids
272-
assert driver.CUlaunchAttributeID.CU_LAUNCH_ATTRIBUTE_SYNCHRONIZATION_POLICY in attr_ids
273-
sync_attrs = [
274-
attr
275-
for attr in native.attrs
276-
if attr.id == driver.CUlaunchAttributeID.CU_LAUNCH_ATTRIBUTE_SYNCHRONIZATION_POLICY
277-
]
278-
assert len(sync_attrs) == 1
279-
assert sync_attrs[0].value.syncPolicy == driver.CUsynchronizationPolicy.CU_SYNC_POLICY_SPIN
280-
281-
282-
@pytest.mark.parametrize(
283-
"policy",
284-
[
285-
SynchronizationPolicyType.AUTO,
286-
SynchronizationPolicyType.SPIN,
287-
SynchronizationPolicyType.YIELD,
288-
SynchronizationPolicyType.BLOCKING_SYNC,
289-
],
290-
)
291-
def test_launch_with_synchronization_policy(init_cuda, policy):
292-
"""Driver accepts per-launch synchronization policies on a real kernel launch."""
293-
import cuda.bindings
294-
from cuda.core._utils.version import driver_version
295-
296-
if int(cuda.bindings.__version__.split(".")[0]) >= 13 and driver_version()[0] < 13:
297-
pytest.skip("CUDA 13 bindings produce modules incompatible with CUDA 12 drivers")
298-
299-
dev = Device()
300-
dev.set_current()
301-
stream = dev.create_stream()
302-
303-
code = 'extern "C" __global__ void noop() {}'
304-
arch = "".join(f"{i}" for i in dev.compute_capability)
305-
program = Program(code, SourceCodeType.CXX, options=ProgramOptions(arch=f"sm_{arch}"))
306-
mod = program.compile(ObjectCodeFormatType.CUBIN)
307-
ker = mod.get_kernel("noop")
308-
309-
config = LaunchConfig(grid=1, block=1, synchronization_policy=policy)
310-
launch(stream, config, ker)
311-
stream.sync()
312-
313-
314205
@skipif_need_cuda_headers
315206
def test_pdl_primary_secondary_overlap_same_stream():
316207
"""Primary + secondary PDL launch on one stream can overlap on Hopper+.

‎cuda_core/tests/test_object_protocols.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ def sample_switch_node_alt(sample_graphdef):
685685
"sample_launch_config",
686686
r"LaunchConfig\(grid=\(\d+, \d+, \d+\), cluster=.+, block=\(\d+, \d+, \d+\), "
687687
r"shmem_size=\d+, is_cooperative=(?:True|False), "
688-
r"programmatic_stream_serialization=(?:True|False), synchronization_policy=(?:None|SynchronizationPolicyType\.\w+)\)",
688+
r"programmatic_stream_serialization=(?:True|False)\)",
689689
),
690690
("sample_kernel", r"<Kernel handle=0x[0-9a-f]+>"),
691691
# ObjectCode variations (by code_type)

0 commit comments

Comments
 (0)