mirror of
https://github.com/Comfy-Org/comfy-kitchen.git
synced 2026-11-04 23:37:42 +00:00
[PR #74] [MERGED] Add HIP backend for AMD RDNA2-RDNA4 to the existing wheels #123
Labels
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Comfy-Org/comfy-kitchen#123
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Comfy-Org/comfy-kitchen/pull/74
Author: @0xDELUXA
Created: 7/13/2026
Status: ✅ Merged
Merged: 7/29/2026
Merged by: @comfyanonymous
Base:
main← Head:amd/hip-backend📝 Commits (3)
94a5202Add HIP backend67da18afix test_hip_wmma.py hang7d2a04cFix Windows ROCm pytest exit hang via cuda.synchronize in sessionfinish📊 Changes
34 files changed (+7421 additions, -152 deletions)
View changed files
📝
.github/workflows/build-wheels.yml(+190 -30)📝
README.md(+130 -15)📝
comfy_kitchen/__init__.py(+6 -0)➕
comfy_kitchen/backends/hip/CMakeLists.txt(+168 -0)➕
comfy_kitchen/backends/hip/__init__.py(+1414 -0)➕
comfy_kitchen/backends/hip/dlpack_bindings.cpp(+805 -0)➕
comfy_kitchen/backends/hip/epilogue.h(+70 -0)➕
comfy_kitchen/backends/hip/fp8_utils.h(+189 -0)➕
comfy_kitchen/backends/hip/gemm_wmma.h(+219 -0)➕
comfy_kitchen/backends/hip/hadamard.h(+183 -0)➕
comfy_kitchen/backends/hip/mma.h(+310 -0)➕
comfy_kitchen/backends/hip/ops/adaln.hip(+142 -0)➕
comfy_kitchen/backends/hip/ops/apply_rope.hip(+110 -0)➕
comfy_kitchen/backends/hip/ops/convrot_w4a4.hip(+122 -0)➕
comfy_kitchen/backends/hip/ops/gemm_fp8.hip(+116 -0)➕
comfy_kitchen/backends/hip/ops/gemm_int8.hip(+112 -0)➕
comfy_kitchen/backends/hip/ops/gemv_awq.hip(+114 -0)➕
comfy_kitchen/backends/hip/ops/per_tensor_fp8.hip(+114 -0)➕
comfy_kitchen/backends/hip/ops/quantize_int8.hip(+142 -0)➕
comfy_kitchen/backends/hip/ops/rms_rope.hip(+156 -0)...and 14 more files
📄 Description
Supersedes #72. That PR is sitting at ~100 review comments and is gfx12-only, so rather than force-push another rewrite on top of it I opened a fresh one. This picks up the two things that actually blocked it:
This builds one wheel with both backends in it, and keeps the
abi3tag while doing it.This adds RDNA3, RDNA3.5 and RDNA2.
The kernels are #72's, rebased on current main. The packaging follows the approach in dev/hip1 by @rattus128.
Packaging
setup.pydetects both toolchains and emitsbackends/cuda/_C*andbackends/hip/_C*into a single wheel. The Linux job installs CUDA and ROCm into the same manylinux container; the Windows job installs the ROCm toolchain from AMD's release directory (https://repo.radeon.com/), the same host the Linux job takes its RPMs from.auditwheelexcludes the ROCm runtime libs the same way it already excludes the CUDA ones, and both jobs fail if the wheel does not contain both extensions. Each backend withdraws itself at import when its runtime is missing, so a CUDA-only or ROCm-only machine gets the same wheel and just sees one backend register.The HIP extension is built against the Python limited API on 3.12+, like the CUDA one. That matters for the packaging goal: an extension that is not abi3 drags the whole wheel back to version-specific builds, so adding AMD would otherwise have multiplied the wheel matrix. It does not. Nothing outside
backends/hip/changes in the build, and the wheel matrix does not grow: one wheel, both backends, sameabi3tag as today.Architectures
gfx1200,gfx1201gfx1150-gfx1153gfx1100-gfx1103gfx1030-gfx1036v_wmma_*_w32_gfx12has no gfx11 encoding, and the difference is not only the intrinsic name: gfx12 splits a K-step across the half-waves and takes 8-byte operands, while gfx11 gives each lane the whole K-step and duplicates it across the half-waves (rocWMMA calls this input duplication). The fragment type and the bytes of a K-row one MMA consumes therefore moved into anMmapolicy in the newmma.h, and the tile GEMM stays byte-addressed and shared between the two.gfx11 has no fp8 WMMA at all, so
MmaFp8/MmaBf8widen the operands to bf16 there. The widening is exact (e4m3 and e5m2 mantissas both fit bf16's 7 bits) and both paths accumulate in f32, so RDNA3 fp8 should be as accurate as RDNA4's native path, just slower.RDNA2 has no matrix cores. It runs the kernels that never needed them (RoPE, AdaLN, the fp8/int8 quantizers, stochastic rounding, the AWQ GEMV) and does not advertise the four GEMMs, which fall through to triton/eager. The GEMM kernels still compile for gfx103x, where they trap, so the registry gates them by architecture instead: with a mix of GPUs in one process the capability set is the intersection, since kernels launch on the tensor's own device.
scaled_mm_fp8is reached directly rather than through the registry, so it testship.has_wmma()explicitly.The default arch list is every RDNA2/3/3.5/4 target ROCm supports.
COMFY_HIP_ARCHSstill overrides it, and a local build for the one GPU it can see is much faster.Testing
tests/test_hip_wmma.pypasses on a gfx1200 (RX 9060 XT), Windows, ROCm 7.15, torch 2.12. The suite is arch-aware: the GEMM tests skip themselves on a device without matrix cores.COMFY_KITCHEN_DISABLE_HIP.v_wmmainstructions and each of the 7 gfx103x targets emits zero plus the traps. A missing arch macro would not fail the build, it would silently drop that GPU into the no-WMMA stub, which is how I caught thatgfx1103was missing.bdist_wheelon Windows produces a wheel containingbackends/hip/_C.abi3.pyd, so theabi3tag does survive the HIP extension.ruffclean.v_wmma, the 7 gfx103x emit none, as intended.backends/cuda/_C*.soandbackends/hip/_C*.so, and the "Verify Linux wheels contain CUDA and HIP extensions" step - which hard-fails if either is missing - passes; the Windows jobs do the same for.pyd. The CPU-only test jobs then install that wheel on runners with neither GPU runtime and pass, which exercises the "each backend withdraws itself at import" path.Kernel changes to improve RDNA3 performance can only be properly validated on an actual RDNA3 GPU. If you have access to RDNA3 hardware and would like to help, feel free to fork the amd/hip-backend branch, implement and test RDNA3-specific improvements there, and open a PR against that branch. Once those changes are merged, they'll automatically become part of this PR.
RDNA2 users should still use Triton for int8, as rocBLAS doesn't contain int kernels, and hipBLASLt doesn't support RDNA2. As things are today, the INT8-Fast-ROCM node is the best option.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.