|
15 | 15 | import pytest |
16 | 16 | from conftest import skipif_need_cuda_headers |
17 | 17 |
|
18 | | -from cuda.bindings import driver |
19 | 18 | from cuda.core import ( |
20 | 19 | Device, |
21 | 20 | DeviceMemoryResource, |
|
27 | 26 | ) |
28 | 27 | from cuda.core._memory._legacy import _SynchronousMemoryResource |
29 | 28 | 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 |
31 | 30 |
|
32 | 31 |
|
33 | 32 | def test_launch_config_init(init_cuda): |
@@ -203,114 +202,6 @@ def test_to_native_launch_config_pdl(): |
203 | 202 | ) |
204 | 203 |
|
205 | 204 |
|
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 | | - |
314 | 205 | @skipif_need_cuda_headers |
315 | 206 | def test_pdl_primary_secondary_overlap_same_stream(): |
316 | 207 | """Primary + secondary PDL launch on one stream can overlap on Hopper+. |
|
0 commit comments