Commit c2cade2
PR tensorflow#43503: [ROCM] Important fixes for GpuBlasLt MatmulPlan cache
Imported from GitHub PR openxla/xla#43503
## Summary
This change prevents GPU BLASLt autotuning from blowing up the MatmulPlan cache by removing the selected algorithm from the plan cache key. MatmulPlans are now cached by the canonical GEMM key with the selected algorithm unset, while each plan caches its own algorithm list and currently selected algorithm.
The original problem came with a new GEMM autotuner which, instead of calling gpublas_lt directly for each supported algorithm, profiles tiny GpuExecutables. That is, during the autotuning, we go through CublasLtMatmulThunk::ExecuteOnStream(..) which then inserts new entries to MatmulPlan cache (since canonical HLOs differ by **selected algorithm**):
```
I0000 00:00:1779469188.517485 1847675 gpublas_lt_matmul_thunk.cc:140] 0x7f4d0403d9c0: Adding new grouped MatmulPlan for stream: 0x21d619e0 instr: (f16[2400,8]{1,0}, s8[117600]{0}) custom-call(f16[2400,9]{1,0}, f16[600,9,8]{2,1,0}, s32[600]{0}), custom_call_target="__cublas$lt$groupedMatmul", backend_config={"operation_queue_id":"0","force_earliest_schedule":false,"reification_cost":[],"device_type":"DEVICE_TYPE_INVALID","grouped_gemm_backend_config":{"gemm_backend_config":{"selected_algorithm":"0","alpha_real":1,"beta":0,"dot_dimension_numbers":{"lhs_contracting_dimensions":["1"],"rhs_contracting_dimensions":["1"],"lhs_batch_dimensions":[],"rhs_batch_dimensions":[]},"alpha_imag":0,"epilogue":"DEFAULT","grad_x":false,"grad_y":false,"damax_output":false,"autotune_workspace_size":"117600","scale_mode":0},"ragged_dot_dimension_numbers":{"dot_dimension_numbers":{"lhs_contracting_dimensions":["1"],"rhs_contracting_dimensions":["1"],"lhs_batch_dimensions":[],"rhs_batch_dimensions":[]},"lhs_ragged_dimensions":["0"],"rhs_group_dimensions":["0"]}}}
I0000 00:00:1779469188.957549 1847675 gpu_blas_lt.cc:314] 0x7f4f68001478: Plan created: cache size: 1
I0000 00:00:1779469190.125376 1847675 gpublas_lt_matmul_thunk.cc:140] 0x7f4d0803d9d0: Adding new grouped MatmulPlan for stream: 0x21d619e0 instr: (f16[2400,8]{1,0}, s8[117600]{0}) custom-call(f16[2400,9]{1,0}, f16[600,9,8]{2,1,0}, s32[600]{0}), custom_call_target="__cublas$lt$groupedMatmul", backend_config={"operation_queue_id":"0","force_earliest_schedule":false,"reification_cost":[],"device_type":"DEVICE_TYPE_INVALID","grouped_gemm_backend_config":{"gemm_backend_config":{"selected_algorithm":"1","alpha_real":1,"beta":0,"dot_dimension_numbers":{"lhs_contracting_dimensions":["1"],"rhs_contracting_dimensions":["1"],"lhs_batch_dimensions":[],"rhs_batch_dimensions":[]},"alpha_imag":0,"epilogue":"DEFAULT","grad_x":false,"grad_y":false,"damax_output":false,"autotune_workspace_size":"117600","scale_mode":0},"ragged_dot_dimension_numbers":{"dot_dimension_numbers":{"lhs_contracting_dimensions":["1"],"rhs_contracting_dimensions":["1"],"lhs_batch_dimensions":[],"rhs_batch_dimensions":[]},"lhs_ragged_dimensions":["0"],"rhs_group_dimensions":["0"]}}}
I0000 00:00:1779469202.151521 1847675 gpu_blas_lt.cc:314] 0x7f4f68001478: Plan created: cache size: 2
```
This might not be that bad for regular gemms, but can slow down the autotuning grouped gemm significantly. Furthermore, the MatmulPlan cache keeps a list of **128 MatmulPlans** for each gemm config after autotuning.
## Details
- Introduces two-level caching for GPU BLASLt matmul execution: the outer cache reuses MatmulPlans across autotuned algorithm choices, and the inner cache keeps the retrieved algorithms and selected algorithm on the plan.
- Updates thunk emission and execution to pass the selected algorithm separately from the canonical plan key.
- Applies the cache flow across CUDA and ROCm BLASLt implementations, including grouped GEMM handling.
- Adds coverage asserting that autotuned GEMM and grouped GEMM create a single MatmulPlan cache entry instead of one entry per selected algorithm.
## Test Plan
- Added/updated `GpuBlasLtMatmulThunkTest` coverage for shared MatmulPlans and autotuned cache behavior.
Copybara import of the project:
--
9a670c13c02ca01650590a0ac905f9991b4d7b5c by Pavel Emeliyanenko <pavel.emeliyanenko@amd.com>:
redesigning blaslt cache
Revert "redesigning blaslt cache"
This reverts commit 5a96365fc83024a011c5a829926aed5cbd0d8594.
moving towards cached algorithms inside matmul plan
adding setcachedalgorithm
added cached index
improving set cached algorithm
simplified set algorithm
fixing cuda build
cleanup
fixing macros
Revert "redesigning blaslt cache"
This reverts commit 8a7481576e5fff2b13d39b646d3d607db8bb9628.
fixing thunk emitter cache key
just skip the test to check if it hangs
reenabled subtests
disabled all
enabled 2 subtests
disabled GemmWithAutotuneOneCacheEntry
disabled functional test
enabled autotune tests
enabled only autotuneonecache
enabled just single test
running single test
fix
debugging why matmul_test hangs on CI
reenabled again canonicalhlo string
use workspace_size in the if statement
restored ci_build
--
ad8dfba320b4dc4de038570a9edc7d51a4746099 by Pavel Emeliyanenko <pavel.emeliyanenko@amd.com>:
reenabled grouped gemm test
--
685309d9109ba3dfcea95976e2bb3b9b144f05be by Pavel Emeliyanenko <pavel.emeliyanenko@amd.com>:
reduced the number of parallel threads
Merging this change closes tensorflow#43503
PiperOrigin-RevId: 9324092891 parent 53a6a1f commit c2cade2
11 files changed
Lines changed: 232 additions & 92 deletions
File tree
- third_party/xla/xla
- backends/gpu/runtime
- service/gpu
- stream_executor
- cuda
- gpu
- rocm
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1475 | 1475 | | |
1476 | 1476 | | |
1477 | 1477 | | |
| 1478 | + | |
1478 | 1479 | | |
1479 | 1480 | | |
1480 | 1481 | | |
| |||
Lines changed: 9 additions & 21 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
129 | 129 | | |
130 | 130 | | |
131 | 131 | | |
| 132 | + | |
132 | 133 | | |
133 | 134 | | |
134 | 135 | | |
| |||
139 | 140 | | |
140 | 141 | | |
141 | 142 | | |
142 | | - | |
| 143 | + | |
143 | 144 | | |
144 | 145 | | |
145 | 146 | | |
146 | 147 | | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | 148 | | |
166 | 149 | | |
167 | | - | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
168 | 156 | | |
169 | 157 | | |
170 | 158 | | |
| |||
216 | 204 | | |
217 | 205 | | |
218 | 206 | | |
219 | | - | |
| 207 | + | |
220 | 208 | | |
221 | 209 | | |
222 | 210 | | |
| |||
Lines changed: 99 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
48 | 49 | | |
49 | 50 | | |
50 | 51 | | |
51 | 52 | | |
52 | 53 | | |
53 | 54 | | |
54 | 55 | | |
| 56 | + | |
55 | 57 | | |
56 | 58 | | |
57 | 59 | | |
| |||
199 | 201 | | |
200 | 202 | | |
201 | 203 | | |
202 | | - | |
203 | 204 | | |
204 | 205 | | |
205 | 206 | | |
| |||
211 | 212 | | |
212 | 213 | | |
213 | 214 | | |
214 | | - | |
215 | 215 | | |
216 | 216 | | |
217 | 217 | | |
| |||
329 | 329 | | |
330 | 330 | | |
331 | 331 | | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
332 | 397 | | |
333 | 398 | | |
334 | 399 | | |
| |||
346 | 411 | | |
347 | 412 | | |
348 | 413 | | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
349 | 433 | | |
350 | 434 | | |
351 | 435 | | |
352 | 436 | | |
353 | 437 | | |
354 | 438 | | |
355 | | - | |
| 439 | + | |
356 | 440 | | |
357 | 441 | | |
358 | | - | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
359 | 445 | | |
360 | 446 | | |
361 | | - | |
| 447 | + | |
362 | 448 | | |
363 | 449 | | |
364 | 450 | | |
| |||
573 | 659 | | |
574 | 660 | | |
575 | 661 | | |
576 | | - | |
| 662 | + | |
577 | 663 | | |
578 | | - | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
579 | 669 | | |
580 | 670 | | |
581 | 671 | | |
| |||
598 | 688 | | |
599 | 689 | | |
600 | 690 | | |
601 | | - | |
602 | | - | |
| 691 | + | |
| 692 | + | |
603 | 693 | | |
604 | 694 | | |
605 | 695 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
118 | 118 | | |
119 | 119 | | |
120 | 120 | | |
121 | | - | |
| 121 | + | |
| 122 | + | |
122 | 123 | | |
123 | | - | |
124 | | - | |
125 | | - | |
| 124 | + | |
126 | 125 | | |
127 | 126 | | |
128 | 127 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
321 | 321 | | |
322 | 322 | | |
323 | 323 | | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
324 | 340 | | |
325 | 341 | | |
326 | 342 | | |
| |||
568 | 584 | | |
569 | 585 | | |
570 | 586 | | |
571 | | - | |
572 | | - | |
| 587 | + | |
| 588 | + | |
573 | 589 | | |
574 | 590 | | |
575 | 591 | | |
| |||
658 | 674 | | |
659 | 675 | | |
660 | 676 | | |
661 | | - | |
662 | | - | |
| 677 | + | |
663 | 678 | | |
664 | 679 | | |
665 | 680 | | |
| |||
734 | 749 | | |
735 | 750 | | |
736 | 751 | | |
737 | | - | |
738 | | - | |
| 752 | + | |
739 | 753 | | |
740 | 754 | | |
741 | 755 | | |
| |||
788 | 802 | | |
789 | 803 | | |
790 | 804 | | |
791 | | - | |
792 | | - | |
| 805 | + | |
793 | 806 | | |
794 | 807 | | |
795 | 808 | | |
| |||
Lines changed: 13 additions & 17 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
458 | 458 | | |
459 | 459 | | |
460 | 460 | | |
461 | | - | |
| 461 | + | |
462 | 462 | | |
463 | 463 | | |
464 | 464 | | |
| |||
474 | 474 | | |
475 | 475 | | |
476 | 476 | | |
477 | | - | |
478 | | - | |
| 477 | + | |
| 478 | + | |
479 | 479 | | |
480 | 480 | | |
481 | | - | |
| 481 | + | |
482 | 482 | | |
483 | 483 | | |
484 | 484 | | |
485 | 485 | | |
486 | | - | |
| 486 | + | |
487 | 487 | | |
488 | 488 | | |
489 | 489 | | |
490 | 490 | | |
491 | | - | |
492 | 491 | | |
493 | 492 | | |
494 | 493 | | |
| |||
557 | 556 | | |
558 | 557 | | |
559 | 558 | | |
560 | | - | |
561 | | - | |
562 | | - | |
563 | | - | |
564 | | - | |
565 | | - | |
566 | | - | |
567 | | - | |
568 | | - | |
569 | | - | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
570 | 565 | | |
571 | 566 | | |
572 | 567 | | |
573 | 568 | | |
574 | 569 | | |
575 | | - | |
| 570 | + | |
| 571 | + | |
576 | 572 | | |
577 | 573 | | |
578 | 574 | | |
| |||
0 commit comments