1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//! CUDA Driver Tests (PMAT-018: 95% Coverage Strike)
//!
//! These tests REQUIRE CUDA hardware. They WILL NOT SKIP.
//! The RTX 4090 is present. Execute the tests.
use ;
use ;
use GpuBuffer;
use CudaModule;
use CudaStream;
use LaunchConfig;
use c_void;
/// Serialises graph capture against context-wide synchronization.
///
/// GPU-ORD-4: `cuCtxSynchronize` is illegal while *any* stream in the context
/// is capturing a graph, and the attempt also invalidates the capture — so the
/// two tests destroy each other, in both directions at once:
/// `test_context_synchronize` panicking with
/// `CUDA_ERROR_STREAM_CAPTURE_UNSUPPORTED` (900) while
/// `test_cuda_graph_capture_modes` panicked with
/// `CUDA_ERROR_STREAM_CAPTURE_INVALIDATED` (901) in the same run. Every test in
/// this crate shares one primary context, so this is not avoidable by using a
/// different context.
///
/// This is the CUDA rule, not a defect in either test, so the fix is to stop
/// running them at the same time. Capture mode is irrelevant here: `Global` vs
/// `ThreadLocal` changes how other threads' *unsafe actions* are policed, not
/// whether a context-wide sync may proceed during a capture.
///
/// CONTRACT: a test that opens a stream capture, or that calls
/// `CudaContext::synchronize()`, MUST hold this lock — and must also be listed
/// in the `gpu-exclusive` group in `.config/nextest.toml`, because under
/// nextest each test is its own process and an in-process lock excludes
/// nothing.
pub static CAPTURE_VS_CTX_SYNC: Mutex = new;
/// Acquire [`CAPTURE_VS_CTX_SYNC`], recovering from poisoning.
///
/// The lock only orders test bodies; it guards no invariant a panic could
/// leave broken, so recovering stops one unrelated failure from cascading.
pub