Commit 067fb15
refactor(cuda.core): factor shared body of _do_batch_{prefetch,discard_prefetch} (N2)
Per Leo's review on PR #1775 (_managed_memory_ops.pyx:425), the two
batched-with-locations helpers were byte-for-byte identical except for
the driver function being called. Both:
- declare the same four std::vectors (ptrs, sizes, loc_arr, loc_indices)
- resize and fill them in the same loop
- release the GIL and call cuMem{Prefetch,DiscardAndPrefetch}BatchAsync
with the same argument shape
Introduce a function-pointer typedef _BatchPrefetchFn (the two driver
calls share signature), parameterize the shared body as
_do_batch_prefetch_op, and have the two callers pass the appropriate
driver function. Both the typedef and the helper live inside the
IF CUDA_CORE_BUILD_MAJOR >= 13 block since they reference cu13-only
types.
Net: -28 lines duplication, +25 for the shared helper. No behavior
change; tests unaffected.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 36012fd commit 067fb15
1 file changed
Lines changed: 19 additions & 27 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
322 | 322 | | |
323 | 323 | | |
324 | 324 | | |
325 | | - | |
326 | | - | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
327 | 337 | | |
328 | 338 | | |
329 | 339 | | |
| |||
343 | 353 | | |
344 | 354 | | |
345 | 355 | | |
346 | | - | |
| 356 | + | |
347 | 357 | | |
348 | 358 | | |
349 | 359 | | |
350 | 360 | | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
351 | 366 | | |
352 | 367 | | |
353 | 368 | | |
| |||
400 | 415 | | |
401 | 416 | | |
402 | 417 | | |
403 | | - | |
404 | | - | |
405 | | - | |
406 | | - | |
407 | | - | |
408 | | - | |
409 | | - | |
410 | | - | |
411 | | - | |
412 | | - | |
413 | | - | |
414 | | - | |
415 | | - | |
416 | | - | |
417 | | - | |
418 | | - | |
419 | | - | |
420 | | - | |
421 | | - | |
422 | | - | |
423 | | - | |
424 | | - | |
425 | | - | |
426 | | - | |
| 418 | + | |
427 | 419 | | |
428 | 420 | | |
429 | 421 | | |
| |||
0 commit comments