Repository navigation
[ROCm] enable CK backend for bf16/fp16 on gfx11 - #143971
jfactory07 wants to merge 6 commits into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/143971
Note: Links to docs will display an error until the docs builds have been completed. ⏳ 1 Pending, 1 Unrelated FailureAs of commit de21e88 with merge base 790f93d ( UNSTABLE - The following job is marked as unstable, possibly due to flakiness on trunk:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
@pytorchbot label "topic: not user facing" |
|
@jeffdaily please help to review it. |
|
|
||
|
|
||
| auto stream = at::cuda::getCurrentHIPStream().stream(); | ||
| #if 1 |
There was a problem hiding this comment.
Why are we keeping the #else condition dead code here?
There was a problem hiding this comment.
it is useful to performance tuning, so I keep it.
|
This is challenging to approve since we do not have gfx11-enabled CI runners to verify the changes. |
it shouldn't break anything, since CK backend is disabled by default. |
That might be so, but in the absence of testing in CI, can you please attach some results with this PR's changes on your local gfx11 node? |
can you tell my the test command ? I have tested it on vLLM inference. |
Assuming that exercises the ops being enabled for CK here, maybe some diagnostic output that shows CK kernels being invoked and also maybe some numbers on how CK backend performs compared to the non-CK backend? |
ok, here is my local test and output on gfx1100: here is the output: |
|
Hi! I've built this branch, and if I try to run SDXL in ComfyUI with the ck blas backend, it immediately runs into I don't see where the printf ends up. edit: Update/correction: it's not the edit: Ah it doesn't even hit the half code in this PR because ComfyUI fails with some 32-bit float ops before it can even get to the half float ones, and I can't pick and choose the blas backend. edit: Yep, it happens on the shipped nightly pytorch as well. |
hi @FeepingCreature , |
|
Well it should still use the existing non-wmma gemm code otherwise, if I'm reading the diff right? And afaict that already falls over with the ck backend when running comfyui sdxl against it, so even if I have, say, a model with fp16 unet and fp32 vae I can't even get to the wmma code for the unet, cause the non-wmma non-fp16 ck gemm code already doesn't work with the vae anyway. Not relevant for this PR at any rate. |
The existing non-wmma gemm code only works on MI series. |
|
It works if you set the CK backend to choose, say, hipBLASLt instead of CK for FP32 in CUDABlas.cpp. Sadly WMMA does not have any instructions for FP32 so it can't be implemented at all. It does work correctly with BF16 if you repeat the changes for ck_gemm_half.hip in ck_gemm_bfloat16.hip. Here's the patch explaining what I mean; no device checks, certainly not PR material but it does work if you're only using GFX11. Also, I'm on gfx1101; with all the instances of gfx1100 replaced with gfx1101 in the 2 patch files it is faster than hipBLASLt.
|
Thanks for your test on gfx1101. Good to know gfx1101 also has uplift with CK GEMM. |
|
Can confirm it works with the @gel-crabs patch on my gfx1100. ComfyUI SDXL 1024x1024 (torch.compiled, stable over 3 runs):
and printf debugging confirms it hits the wmma branch. (Though with 2048x2048 it falls over with |
|
@pytorchbot merge |
|
Pull workflow has not been scheduled for the PR yet. It could be because author doesn't have permissions to run those or skip-checks keywords were added to PR/commits, aborting merge. Please get/give approval for the workflows and/or remove skip ci decorators before next merge attempt. If you think this is a mistake, please contact PyTorch Dev Infra. |
|
To be safe, I reran my ComfyUI SDXL benchs with this branch rebased on main:
Pretty much same difference as before. Though if I turn on And of course, FlashAttention trounces both, with a peak 5.7it/s with tuning and torch.compile. |
TunableOp does not consider CK GEMM currently, only roc/hipblas or hipblaslt. |
|
@pytorchbot rebase |
|
@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here |
|
Successfully rebased |
3051eae to
de21e88
Compare
When the preferred BLAS library is set to CK, TunableOp chooses "Default" as the fastest solution for practically every GemmAndBiasTunableOp problem, i.e. what it would be if TunableOp was off. Otherwise it would be rocblas/hipblaslt solutions. CK is being selected, but not specifically, just as the default solution if that makes sense. |
Aha, yes, that makes sense. We had postponed adding CK to TunableOp because there is the 1) quick/easy way, and 2) the comprehensive way to do it. The quick/easy would be to run the few CK GEMM implementations we have in the CK backend of torch.mm within TunableOp. The comprehensive approach would mimic what onnxruntime is doing which is to compile all possible combinations of CK params and try them all. Doing (2) would cause the already long compile time of ROCm torch to balloon into something prohibitive. But I think we can do (1). I will add (1) to a TODO list. |
|
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
HI Jeff,
|
### Summary
The CK GEMM supported-architecture allowlist currently lives hardcoded in three
places: `torch_filter_ck_gemm_arches` (cmake/public/utils.cmake), the runtime
check `at::Context::ckGemmSupported()`, and the `gemm_internal_ck` dispatch in
`ck_gemm_{half,bfloat16}.hip`. Keeping them in sync is manual, and the
gfx11/gfx12 WMMA path (#143971) can only be re-enabled by editing source in
several spots.
This PR makes the list a single source of truth:
- A new CMake cache variable `TORCH_CK_GEMM_ARCH_LIST` (default
`gfx90a;gfx942;gfx950`) drives the `ck_gemm` build arch filter and is surfaced
to C++ through a generated `ATen/ROCmCKGEMMConfig.h` header, mirroring the
existing `AT_ROCM_CK_SDPA_ARCHS` mechanism. It is forwarded from the
environment via `cmake/EnvVarForwarding.cmake`.
- `Context.cpp` parses the list once through a shared `parseArchList` helper
used by both `ckSDPASupported()` and `ckGemmSupported()`.
- The `.hip` dispatch calls `at::globalContext().ckGemmSupported()` instead of
re-parsing the list, so the header include, the parser, and the fallback are
removed from both `.hip` files.
A WMMA arch can now be opted back in at both build and run time without patching
source, e.g. `TORCH_CK_GEMM_ARCH_LIST="gfx90a;gfx942;gfx950;gfx1200"`.
### BC-breaking
No. Default behavior is unchanged -- the default list is the same three archs
that were previously hardcoded.
### Supporting maintainer
@jeffdaily (requested this refactor in review).
### Test plan
CMake wiring, standalone project including `cmake/public/utils.cmake`:
- default: `torch_filter_ck_gemm_arches` filters
`gfx942;gfx1250-strict;gfx950;gfx1200` to `gfx942;gfx950`; generated header
`#define TORCH_CK_GEMM_ARCH_LIST "gfx90a,gfx942,gfx950"`.
- override `TORCH_CK_GEMM_ARCH_LIST="gfx90a;gfx942;gfx950;gfx1200"`: filter keeps
`gfx942;gfx950;gfx1200`; header `"gfx90a,gfx942,gfx950,gfx1200"`.
Full build:
```
PYTORCH_ROCM_ARCH="gfx90a gfx942 gfx950" pip install -e . --no-build-isolation -v
```
rc=0, 0 failed. `ck_gemm_half.hip.o` offload bundle = `gfx90a,gfx942,gfx950`;
`libtorch_hip.so` links (the `ck_gemm` -> `Context::ckGemmSupported()` cross-TU
call resolves).
Pull Request resolved: #201113
Approved by: https://github.com/jeffdaily
Co-authored-by: Claude Opus 4.8 <[email protected]>
Co-authored-by: Jeff Daily <[email protected]>
this change enables enable CK backend for fp16 on Gfx11
@jeffdaily
cc @jeffdaily @sunway513 @jithunnair-amd @pruthvistony @ROCmSupport @dllehr-amd @jataylo @hongxiayang @naromero77amd