Commit 27dcceb
[Kernel] fp8 conv3d: 8-wave GEMM pipeline + BIG_IN fix (#860)
* conv3d fp8: port kernel onto the fp8_gemm 8-wave pipeline
Rewrites conv3d_implicit_fp8 on top of the fp8_gemm_8wave pipeline
(G2SLoader / S2RLoader / Mfma16x16x128), taking FP8 E4M3FN inputs
directly instead of quantizing bf16 in the kernel. Adds WGM L2-swizzle
(configurable + autotuned), generalizes to N/K-partial and tiny-K
shapes via OOB masking, dispatches 1D/2D/3D by filter rank, and fixes
NaN / memory faults on >2 GB tensors by rebasing the buffer descriptor.
Renames conv3d_implicit_autotune.py -> conv3d_autotune.py: the module
now serves both the bf16 (conv3d_implicit.py) and fp8 kernels, so
"implicit" in the name is no longer accurate. Pure rename, no content
change; the two importers are updated.
* conv3d: accept any channel count and unaligned spatial extents
C values that are not a multiple of the gather's vector width (8 bf16 / 16 fp8)
were rejected outright, and the NCHW->NHWC transpose fell back to torch for any
spatial extent that was not a multiple of the same width.
Channels: zero-pad C instead of asserting. The padded channels multiply against
zero weights, so the result is unchanged; rel_l2 against an fp32 reference is
1.66e-3, matching torch's own bf16 error. The weight packers pad too, keyed on
the caller's unpadded tensor so their identity caches still hit.
Spatial extent: the transpose guards were stricter than the kernels need. For
bf16, s has no alignment requirement at all -- the read's tail lands in LDS
columns the write-back guard never visits. For fp8 the read indexes the input
in dwords, so the requirement is s%4 rather than s%16. Only the write side
needs channel alignment, since it stores a full vector along C.
Both transposes leave the input descriptor at max_size on purpose: an exact
num_records makes the hardware zero a 16-byte access that straddles the end of
the tensor, including the valid elements inside it.
bf16 end-to-end vs torch/MIOpen on MI355X (autotuned, 5 trials averaged): the
previously-failing C=3 shape runs at 1.49x, and the stride-2 shapes go 1.04x ->
1.91x, 0.92x -> 1.51x, 0.81x -> 1.36x. Geomean over the real conv shapes
improves 1.295x -> 1.431x with no regression on aligned shapes.
Tests: 57 bf16 (was 30) and 36 fp8 (was 29), covering C in {1,3,4,5,6,12,24,48}
and unaligned spatial extents.
* fix buffer_ops import
* conv3d fp8: migrate raw pointer construction to the fx.* API
Replace the buffer_ops pointer helpers with the current DSL surface:
- extract_base_index(t) -> fx.ptrtoint(fx.get_iter(t))
- create_llvm_ptr(addr, address_space=N) -> <fx ptr>.llvm_ptr, which
resolves the LLVM address space via the compile backend instead of
hardcoding <1>/<3>.
The two global raw-address sites share a new _global_ptr_from_addr()
helper, which _make_fp8_buffer_tensor_from_addr() now also uses for its
inttoptr step. The LDS store reuses the recast_iter(u8, ...) idiom the
neighbouring load already used.
Behaviour-preserving. tests/kernels/test_conv3d_implicit_fp8.py 35/35
pass on gfx950; the untested BIG_IN and BIG_OUT branches were both
force-compiled to cover the const_expr paths the shape-gated tests skip.
Co-Authored-By: Claude <noreply@anthropic.com>
* conv3d fp8: migrate buffer_ops resources/loads/stores to fx.copy
Replace the last buffer_ops users with the layout + copy-atom surface, so
the module no longer imports kernels.common.buffer_ops:
- create_buffer_resource -> fx.rocdl.make_buffer_tensor + logical_divide
- buffer_load/buffer_store -> fx.copy through an rmem staging tensor,
following the StoreC pattern in kernels/gemm/fp8_gemm_utils.py.
Two details worth flagging:
- The transpose input load moves off the i32-element offset (the old
'// 4') to a u8 buffer tensor, where the copy-atom element offset is
the byte offset directly. Same address, one less scaling step to get
wrong.
- The masked epilogue store now routes masked-off lanes to element
npq*k (one past the end) instead of relying on buffer_store's
mask=, matching StoreC's oob idiom. The hardware num_records bound
drops them. This branch only compiles when npq*k*2 <= 2^31, so the
offset always fits in i32.
_vec_store moves up beside BIG_IN/BIG_OUT because the copy atoms are now
built at kernel entry.
Verified on gfx950 (MI355X):
- test_conv3d_implicit_fp8.py 35/35 pass, re-run with
FLYDSL_RUNTIME_ENABLE_CACHE=0 to defeat the JIT cache
- BIG_IN / BIG_OUT / TR_BIG / has_bias force-compiled, since all four are
const_expr branches the default test tier never reaches
- bias has no test coverage at all, so it was checked numerically
against torch conv3d on 3 shapes (rel_err 1.7e-03, matching no-bias)
- perf unchanged: 2158 vs 2171 TF (1x3x3) and 2489 vs 2496 TF (3x3x3),
median of 10, within run-to-run noise
Co-Authored-By: Claude <noreply@anthropic.com>
* conv3d bf16: migrate buffer_ops to the fx.* API
Mirrors the fp8 migration in the two preceding commits, so both conv
kernels now use the same surface and neither imports
kernels.common.buffer_ops:
- create_buffer_resource -> fx.rocdl.make_buffer_tensor
- create_buffer_resource_from_addr -> make_buffer_ptr(fx.inttoptr(...)),
reusing the _x_div_from_addr idiom already in this file
- buffer_load / buffer_store -> fx.copy via an rmem staging tensor
- extract_base_index -> fx.ptrtoint(fx.get_iter(t))
- create_llvm_ptr -> .llvm_ptr
Descriptor semantics are unchanged: every migrated site kept its
num_records (all were the max_size 0xFFFFFFFF default, including the
rebased transpose resources, whose comment explains why an exact bound
would zero the straddling tail read).
The split-K epilogue still needs a raw !llvm.ptr<8> because
buffer_atomic_add takes a resource rather than a tensor, so it derives
one with fx.rocdl.get_buffer_rsrc -- the same approach
kernels/moe/moe_gemm_2stage/gemm2.py uses for its scatter atomics.
_row_chk / _need_chk / _vec_store move up to the enclosing scope since
the copy atoms they select are now built at kernel entry.
Verified on gfx950 (MI355X):
- test_conv3d_implicit.py 57/57 pass with FLYDSL_RUNTIME_ENABLE_CACHE=0
- split-K has no test coverage and is the one path that changed shape
here, so it was checked numerically against torch conv3d at splitk=4
and 8, with and without bias (rel_err 6.9e-07..3.1e-03)
- BIG_IN_N1 / BIG_IN_NM / BIG_OUT / splitk / transpose-BIG force-compiled
- transpose verified bit-exact vs torch.permute, including the BIG
branch on a real 4.1 GiB tensor (2.2e9 elements, >2^31)
- perf unchanged: 723 vs 717 TF (3x3x3) and 657 vs 660 TF (1x3x3)
Co-Authored-By: Claude <noreply@anthropic.com>
* conv3d: tighten migration comments
Drop the comment that restated the buffer-tensor construction and move
the byte-offset note down to the offset arithmetic it explains.
Co-Authored-By: Claude <noreply@anthropic.com>
---------
Co-authored-by: jiacao-amd <jiacao@amd.com>
Co-authored-by: Nikolai Protasov <nprotaso@amd.com>
Co-authored-by: Claude <noreply@anthropic.com>1 parent e338067 commit 27dcceb
5 files changed
Lines changed: 978 additions & 567 deletions
File tree
- kernels/conv
- tests/kernels
File renamed without changes.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
23 | 22 | | |
24 | 23 | | |
25 | 24 | | |
| |||
46 | 45 | | |
47 | 46 | | |
48 | 47 | | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
49 | 52 | | |
50 | 53 | | |
51 | 54 | | |
52 | 55 | | |
53 | 56 | | |
54 | | - | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
55 | 60 | | |
56 | 61 | | |
57 | 62 | | |
| |||
67 | 72 | | |
68 | 73 | | |
69 | 74 | | |
70 | | - | |
| 75 | + | |
71 | 76 | | |
72 | 77 | | |
73 | 78 | | |
74 | 79 | | |
75 | 80 | | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
76 | 93 | | |
77 | 94 | | |
78 | | - | |
79 | | - | |
80 | 95 | | |
81 | 96 | | |
82 | 97 | | |
| |||
88 | 103 | | |
89 | 104 | | |
90 | 105 | | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
91 | 113 | | |
92 | | - | |
93 | | - | |
| 114 | + | |
94 | 115 | | |
95 | | - | |
96 | | - | |
| 116 | + | |
97 | 117 | | |
98 | 118 | | |
99 | 119 | | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
100 | 124 | | |
101 | 125 | | |
102 | | - | |
103 | | - | |
| 126 | + | |
104 | 127 | | |
105 | 128 | | |
106 | 129 | | |
| |||
120 | 143 | | |
121 | 144 | | |
122 | 145 | | |
123 | | - | |
124 | | - | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
125 | 149 | | |
126 | 150 | | |
127 | 151 | | |
| |||
139 | 163 | | |
140 | 164 | | |
141 | 165 | | |
142 | | - | |
| 166 | + | |
| 167 | + | |
143 | 168 | | |
144 | 169 | | |
145 | 170 | | |
| |||
156 | 181 | | |
157 | 182 | | |
158 | 183 | | |
159 | | - | |
| 184 | + | |
160 | 185 | | |
161 | 186 | | |
162 | 187 | | |
| |||
186 | 211 | | |
187 | 212 | | |
188 | 213 | | |
189 | | - | |
| 214 | + | |
190 | 215 | | |
191 | 216 | | |
192 | 217 | | |
| |||
214 | 239 | | |
215 | 240 | | |
216 | 241 | | |
| 242 | + | |
| 243 | + | |
217 | 244 | | |
218 | 245 | | |
219 | 246 | | |
220 | 247 | | |
| 248 | + | |
221 | 249 | | |
222 | 250 | | |
223 | 251 | | |
| |||
246 | 274 | | |
247 | 275 | | |
248 | 276 | | |
249 | | - | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
250 | 291 | | |
251 | 292 | | |
252 | 293 | | |
| |||
257 | 298 | | |
258 | 299 | | |
259 | 300 | | |
260 | | - | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
261 | 304 | | |
262 | 305 | | |
263 | 306 | | |
| |||
285 | 328 | | |
286 | 329 | | |
287 | 330 | | |
| 331 | + | |
288 | 332 | | |
289 | 333 | | |
290 | 334 | | |
| |||
299 | 343 | | |
300 | 344 | | |
301 | 345 | | |
302 | | - | |
| 346 | + | |
303 | 347 | | |
304 | 348 | | |
305 | | - | |
| 349 | + | |
306 | 350 | | |
307 | 351 | | |
308 | 352 | | |
| |||
551 | 595 | | |
552 | 596 | | |
553 | 597 | | |
554 | | - | |
555 | | - | |
556 | | - | |
557 | | - | |
558 | 598 | | |
559 | | - | |
| 599 | + | |
560 | 600 | | |
561 | 601 | | |
562 | 602 | | |
563 | | - | |
| 603 | + | |
564 | 604 | | |
565 | 605 | | |
566 | 606 | | |
| |||
582 | 622 | | |
583 | 623 | | |
584 | 624 | | |
585 | | - | |
| 625 | + | |
| 626 | + | |
586 | 627 | | |
587 | 628 | | |
588 | 629 | | |
| |||
594 | 635 | | |
595 | 636 | | |
596 | 637 | | |
597 | | - | |
| 638 | + | |
| 639 | + | |
598 | 640 | | |
599 | 641 | | |
600 | 642 | | |
| |||
624 | 666 | | |
625 | 667 | | |
626 | 668 | | |
627 | | - | |
| 669 | + | |
| 670 | + | |
628 | 671 | | |
629 | 672 | | |
630 | 673 | | |
| |||
696 | 739 | | |
697 | 740 | | |
698 | 741 | | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
699 | 748 | | |
700 | 749 | | |
701 | 750 | | |
702 | 751 | | |
703 | 752 | | |
704 | 753 | | |
705 | 754 | | |
706 | | - | |
| 755 | + | |
707 | 756 | | |
708 | 757 | | |
709 | 758 | | |
| |||
723 | 772 | | |
724 | 773 | | |
725 | 774 | | |
726 | | - | |
| 775 | + | |
727 | 776 | | |
728 | 777 | | |
729 | 778 | | |
| |||
0 commit comments