Commit da085de
committed
gpu: the mirror table and its buffer pool live once, in gpu_abi.h
cuda.h and webgpu.h each kept their own copy of the same shape: a
struct pairing a host buffer with a device handle and a residency
state, a map from the native handle to it, and a size-keyed free list
alloc()/release() recycle through. Only the device handle's type
differed (CUdeviceptr, wgpu::Buffer). gpu::mirror_table<Handle>
(gpu_abi.h) holds that shape once; each backend instantiates it for
its own handle type and keeps doing its own copying (before_kernel_,
sync_to_host), which is where the two drivers actually diverge.
mirror_table::insert moves its Handle parameter into the entry rather
than copying it, so a ref-counted handle (wgpu::Buffer) picks up only
one AddRef per allocation instead of two.
Verified on native Metal (117 cases, 11640 assertions with real
device access, plus check_qwen's greedy tokens against the numpy
oracle) and gpu_host's no-GPU reference build, under WebGPU via Deno,
and by a clean CUDA host-side trace diff against the pre-refactor
commit (no kernel call changed). A mutation that let take() hand out
an already-live pooled buffer twice was caught hard by the WebGPU
suite (32 of 117 cases failed).1 parent 8d79288 commit da085de
4 files changed
Lines changed: 93 additions & 71 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
63 | 72 | | |
64 | 73 | | |
65 | 74 | | |
| |||
259 | 268 | | |
260 | 269 | | |
261 | 270 | | |
262 | | - | |
263 | | - | |
264 | | - | |
265 | 271 | | |
266 | 272 | | |
267 | 273 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
282 | 282 | | |
283 | 283 | | |
284 | 284 | | |
285 | | - | |
286 | | - | |
287 | | - | |
288 | | - | |
289 | | - | |
290 | | - | |
291 | | - | |
292 | | - | |
293 | | - | |
294 | | - | |
295 | | - | |
296 | | - | |
297 | | - | |
298 | | - | |
299 | | - | |
300 | | - | |
301 | | - | |
302 | | - | |
303 | | - | |
304 | | - | |
305 | | - | |
306 | | - | |
307 | | - | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
308 | 298 | | |
309 | 299 | | |
310 | 300 | | |
| |||
1141 | 1131 | | |
1142 | 1132 | | |
1143 | 1133 | | |
1144 | | - | |
1145 | | - | |
1146 | | - | |
1147 | | - | |
1148 | | - | |
1149 | | - | |
| 1134 | + | |
1150 | 1135 | | |
1151 | 1136 | | |
1152 | 1137 | | |
1153 | 1138 | | |
1154 | 1139 | | |
1155 | 1140 | | |
1156 | 1141 | | |
1157 | | - | |
| 1142 | + | |
| 1143 | + | |
1158 | 1144 | | |
1159 | | - | |
| 1145 | + | |
1160 | 1146 | | |
1161 | 1147 | | |
1162 | 1148 | | |
1163 | 1149 | | |
1164 | 1150 | | |
1165 | | - | |
1166 | | - | |
1167 | | - | |
1168 | | - | |
1169 | | - | |
| 1151 | + | |
| 1152 | + | |
1170 | 1153 | | |
1171 | | - | |
1172 | | - | |
1173 | 1154 | | |
1174 | 1155 | | |
1175 | 1156 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
22 | 25 | | |
23 | 26 | | |
24 | 27 | | |
| |||
160 | 163 | | |
161 | 164 | | |
162 | 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 | + | |
163 | 214 | | |
164 | 215 | | |
165 | 216 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
196 | 196 | | |
197 | 197 | | |
198 | 198 | | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | | - | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | | - | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
214 | 209 | | |
215 | 210 | | |
216 | 211 | | |
| |||
347 | 342 | | |
348 | 343 | | |
349 | 344 | | |
350 | | - | |
351 | | - | |
352 | | - | |
353 | | - | |
| 345 | + | |
354 | 346 | | |
355 | 347 | | |
356 | 348 | | |
| |||
512 | 504 | | |
513 | 505 | | |
514 | 506 | | |
515 | | - | |
516 | | - | |
517 | | - | |
518 | | - | |
519 | | - | |
520 | | - | |
| 507 | + | |
521 | 508 | | |
522 | 509 | | |
523 | 510 | | |
| |||
532 | 519 | | |
533 | 520 | | |
534 | 521 | | |
535 | | - | |
| 522 | + | |
536 | 523 | | |
537 | 524 | | |
538 | 525 | | |
539 | 526 | | |
540 | 527 | | |
541 | 528 | | |
542 | 529 | | |
543 | | - | |
544 | | - | |
545 | | - | |
546 | | - | |
| 530 | + | |
547 | 531 | | |
548 | 532 | | |
549 | 533 | | |
| |||
0 commit comments