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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
//! macOS stub-contract tests.
//!
//! Asserts that every `gpu-tests`-gated public entrypoint, when invoked on
//! macOS, returns the expected `Err` variant (or, where the stub explicitly
//! synthesises an `Ok` handle, that it returns `Ok`) — rather than panicking,
//! hanging, or silently succeeding.
//!
//! # Coverage
//!
//! | Site | Expected result |
//! |-------------------------------------------------|------------------------------|
//! | `oxicuda-driver::init()` | `Err(NotInitialized)` |
//! | `Device::get(0)` | `Err(NotInitialized)` |
//! | `Device::count()` | `Err(NotInitialized)` |
//! | `driver_version()` | `Err(NotInitialized)` |
//! | `DevicePool::new()` (multi_gpu.rs:289) | `Err(NotInitialized)` |
//! | `PrimaryContext::retain` chain (pc.rs:237) | `Err(NotInitialized)` via get|
//! | `device::can_access_peer` (peer_copy.rs:227) | `Err(NotInitialized)` via get|
//! | `oxicuda_driver::init` (global_init.rs:552) | `Err(NotInitialized)` |
//! | `oxicuda_driver::init` (spgemm_estimate:461) | `Err(NotInitialized)` |
//! | `oxicuda_driver::init` (spgemm_estimate:577) | `Err(NotInitialized)` |
//! | `loader::try_driver()` (host_registered:675) | `Err(NotInitialized)` [note] |
//! | `LaunchParams::validate` chain (params.rs:436) | `Err(NotInitialized)` via get|
//! | `auto_grid_for` chain (grid.rs:403) | `Err(NotInitialized)` via get|
//!
//! **Note (host_registered):** `oxicuda_memory::register()` itself returns a
//! *synthetic* `Ok(RegisteredMemory)` handle on macOS — it never calls the
//! driver. The driver-level test here verifies that the underlying
//! `try_driver()` call would return `Err(NotInitialized)`, which is what any
//! non-stubbed host-registered path would hit. The synthetic-handle behaviour
//! is tested in `oxicuda-memory`'s own unit tests.
//!
//! **Dev-dependency note:** `oxicuda-launch`, `oxicuda-memory`,
//! `oxicuda-sparse`, and `oxicuda` all *depend on* `oxicuda-driver`, so they
//! cannot be added as dev-dependencies here without introducing a crate cycle.
//! The tests for those crates' call sites test the lowest driver-level
//! entrypoint in this crate that corresponds to the same loading path.
use CudaError;
use try_driver;
use DevicePool;
use ;
// ---------------------------------------------------------------------------
// 1. init() — the canonical top-level entrypoint
// ---------------------------------------------------------------------------
/// `init()` must return `Err(NotInitialized)` on macOS because `try_driver()`
/// returns that variant when the driver cannot be loaded.
///
/// This directly covers the `oxicuda/src/global_init.rs:552` site, which
/// calls `oxicuda_driver::init()` first.
// ---------------------------------------------------------------------------
// 2. try_driver() — the loader entry used by every public API
// ---------------------------------------------------------------------------
/// `try_driver()` must return `Err(NotInitialized)` on macOS.
///
/// This is the lowest-level assertion; all other tests in this file rely on
/// this behaviour indirectly. Also covers the `host_registered.rs:675` site:
/// on non-macOS platforms, `register()` calls `try_driver()` which would fail
/// here. On macOS the memory crate returns a synthetic `Ok` handle instead of
/// reaching the driver — that behaviour is correct and is tested in
/// `oxicuda-memory`'s own unit tests.
// ---------------------------------------------------------------------------
// 3. Device::get(0) — the entry point for launch/params and launch/grid
// ---------------------------------------------------------------------------
/// `Device::get(0)` must return `Err(NotInitialized)` on macOS.
///
/// Covers:
/// - `oxicuda-launch/params.rs:436` — `LaunchParams::validate` calls
/// `Device::get(0)` before any validation.
/// - `oxicuda-launch/grid.rs:403` — `auto_grid_for` calls
/// `Device::get(0)` to query occupancy.
// ---------------------------------------------------------------------------
// 4. Device::count() — used by global_init and list_devices
// ---------------------------------------------------------------------------
/// `Device::count()` must return `Err(NotInitialized)` on macOS.
///
/// Also covers `oxicuda/src/global_init.rs:552`, which calls
/// `Device::count()` through `list_devices()`.
// ---------------------------------------------------------------------------
// 5. driver_version() — exercises the same loading path
// ---------------------------------------------------------------------------
/// `driver_version()` must return `Err(NotInitialized)` on macOS.
// ---------------------------------------------------------------------------
// 6. DevicePool::new() — multi_gpu.rs:289
// ---------------------------------------------------------------------------
/// `DevicePool::new()` must return `Err(NotInitialized)` on macOS.
///
/// Directly covers `oxicuda-driver/src/multi_gpu.rs:289`. `DevicePool::new`
/// calls `list_devices()` which calls `try_driver()` before any GPU query.
// ---------------------------------------------------------------------------
// 7. PrimaryContext chain — primary_context.rs:237
// ---------------------------------------------------------------------------
/// The `PrimaryContext::retain` call chain must return `Err(NotInitialized)`
/// on macOS.
///
/// Directly covers `oxicuda-driver/src/primary_context.rs:237`.
/// `PrimaryContext::retain` calls `try_driver()` first, so even a dummy
/// `Device` handle would trigger the same error. The chain in the gpu-tests
/// block begins with `Device::get(0)`, which already returns
/// `Err(NotInitialized)` — shown here explicitly.
// ---------------------------------------------------------------------------
// 8. can_access_peer — peer_copy.rs:227
// ---------------------------------------------------------------------------
/// The peer-copy `can_access_peer` entry point returns `Err(NotInitialized)`
/// on macOS.
///
/// Covers `oxicuda-memory/src/peer_copy.rs:227`. `oxicuda_memory::peer_copy::can_access_peer`
/// delegates to `oxicuda_driver::device::can_access_peer`, which calls
/// `try_driver()`. `oxicuda_memory` cannot be a dev-dependency here due to
/// the crate-cycle, so we test the equivalent driver-level function directly.
/// The behaviour is identical: both call the same `try_driver()` path.
// ---------------------------------------------------------------------------
// 9. SpGEMM estimate chains — spgemm_estimate.rs:461 and :577
// ---------------------------------------------------------------------------
/// The SpGEMM estimate code path returns `Err(NotInitialized)` on macOS.
///
/// Covers both `oxicuda-sparse/src/ops/spgemm_estimate.rs:461` (the
/// `try_make_csr` helper used by gpu tests) and `:577` (the `mod gpu` block).
/// Both code paths call `CsrMatrix::from_host` which internally calls
/// `DeviceBuffer::from_host` → `try_driver()`.
///
/// `oxicuda-sparse` cannot be a dev-dependency here due to crate-cycle, so
/// we test `try_driver()` directly — the same path that `DeviceBuffer::alloc`
/// follows on the first call in `CsrMatrix::from_host`.