Repository navigation
[CK] [JIT] Add basic HIP/CK JIT kernel support in Windows - #4306
menglcai-amd wants to merge 3 commits into
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
|
36b7eff to
8d44d07
Compare
|
No activity for 15 days, so this is now labelled |
|
@menglcai — apologies for the long silence on this, and thank you for the work. Some context you'll want: #2699 ("[HIP] [JIT] Add Windows support") was merged on 8 October as I would rather not resolve those conflicts on your behalf. #2699 made some deliberate choices that are easy to lose in a merge — for instance Looking at your diff against what landed, the parts that appear genuinely unique to this PR are If you think something else here is still needed, say so and I'll look again. And if you'd rather not carry this forward, that's completely fine — just let me know and I'll close it with thanks. |
8d44d07 to
bd83a7f
Compare
|
Hi @zufayu, Thanks for the review. #2699 is an impressive piece of work, and you're right that it supersedes most of what this PR was carrying — I've dropped everything it made obsolete. On the two files you called out:
One caveat: on Windows this PR also needs a CK submodule fix. Without it the ck_tile buffer addressing path fails to compile:
With that CK fix applied on top of this one, So while this PR does depend on the CK fix to be useful, it is still a net positive for the Windows platform. |
… hosts mha_fwd failed at dispatch with "invalid argument for fmha_fwd" on every non-gfx9 GPU. ck-tile's generate.py defaults to --targets gfx9,gfx950, so the JIT path emitted an empty kernel set for gfx10/11/12 even though the compiler was correctly given --offload-arch for the runtime arch. mha_recipes already has _ck_targets_flag() and the prebuild path already uses it; wire it into the six cmdGenFunc blob_gen_cmd sites the JIT path goes through. For batch_prefill the same gap produced CDNA-shaped kernels (w32x32x16) that fail to compile for RDNA at all, rather than an empty set. flash_attn_func and flash_attn_varlen_func import the FlyDSL kernels unconditionally, but flydsl ships Linux-only wheels and setup.py already drops it from the install requirements on Windows, so the import raised ModuleNotFoundError instead of falling back to CK. Add is_flydsl_available() and gate the three entry points on it. The probe imports the same module the callers do, so the version check in aiter/ops/flydsl/__init__.py stays the single source of truth; it is lazy because that package imports the rest of aiter. At the varlen backward gate it is applied with `and` at the call site instead of inside the capability chain, whose `&=` would not short-circuit, so a host ruled out by arch or shape never imports FlyDSL. The quotes in flags_extra_cc reached clang literally: clang: error: no such file or directory: ''-DONLY_FAV3=0'' Verified on gfx1151 (Windows, TheRock SDK, torch 2.14.0+rocm10.2.0): fwd and bwd both build and match the reference within tolerance, for test_mha.py and test_mha_varlen.py. Signed-off-by: menglcai <[email protected]>
bd83a7f to
a93c7b9
Compare
|
Thanks for narrowing the scope. The FlyDSL fallback itself looks reasonable, but I don't think this is merge-ready yet:
Please also update the PR description, since it still describes the files and test results from the old, much larger version of this PR. |
… memcpy fix Signed-off-by: menglcai <[email protected]>
|
These are all fair points. I have removed the batch_prefill change and bumped the submodule, then re-ran Re-validated on a cleared JIT cache with the bumped submodule, no local CK patches and no Environment: gfx1151 (Radeon 8060S), Windows 11 25H2 (build 26200.9168), TheRock SDK, torch 2.14.0+rocm10.2.0a20261009, CK submodule pinned at
I have not made the remaining changes yet, because I noticed that #4340 already covers most of what you raised — the multi-arch What this PR still has that is not covered there:
I would like your view on narrowing this PR as follows:
Does that sound reasonable? I will update the PR changes and description once the direction is settled. |
|
Yes, narrowing this PR to the backward-specific delta sounds right. Please rebase after #4340 lands and keep only:
The forward target policy, FlyDSL availability handling, and CK submodule update should come from #4340 rather than being duplicated here. Please extend the #4340 PREBUILD policy tests to cover the backward modules, confirm that the existing gfx9 behavior remains unchanged, and rerun both the clean-cache Windows JIT tests and an actual single-architecture Windows PREBUILD/codegen build on gfx1151. Please also update the PR description to reflect the final reduced scope. |
|
A quick correction after reviewing this against AITER's longer-term backend direction: please hold off on the backward-only CK expansion for now. AITER expects to reduce, rather than expand, its CK-specific maintenance surface. Adding new Windows CK JIT and PREBUILD handling for backward would create a permanent target-policy and validation obligation that our current Windows CI does not cover. Before taking that on, we need a concrete Windows consumer or workload that requires CK and cannot be served by the Triton/FlyDSL path. Please do not spend time reworking this PR yet. We will first determine whether the small |
|
No problem, thanks for the careful review and for pushing this along. |
|
Thanks for pausing this work. We have decided not to expand the Windows CK support surface, so I am closing this PR. If the ONLY_FAV3=0 quoting fix is still independently needed, please send it as a small standalone PR without the CK backward/PREBUILD changes. |
|
I have opened #6616 for the |
Motivation
Enable aiter to build and run CK/HIP JIT kernels on Windows using the TheRock ROCm SDK package. Previously Windows was forced into Triton-only mode via a hardcoded
AITER_TRITON_ONLY=True; this change removes that restriction and adds the necessary platform-specific build glue.Technical Details
Build system (
cpp_extension.py):.pyd/.exe/.dllextensions on Windows instead of.soget_hip_version(): fall back to reading.hipVersionfrom the SDK whenrocm_sdk_coreis absent in pip build-isolated environments-fPICfromCOMMON_HIP_FLAGSandcflagson Windows (rejected by the MSVC target clang with a hard error)get_cxx_compiler(): usehipcc.exeon Windows; update_accepted_compilers_for_platform()to accepthipcc.exe/clang++.exeget_compiler_abi_compatibility_and_version(): skip the GCC ABI version check on Windows (irrelevant for clang; also leftversionundefined)_prepare_ldflags(): link Python import lib (-L libs/) explicitly on Windows (Linux resolves it at runtime); guard ELF-only linker flags; normalise lib paths withos.sep(no-op on Linux)_get_rocm_arch_flags(): use_detect_native()on Windows instead oftorch._C._cuda_getArchFlags(), which returns all 24 supported archs and would generate 24 duplicate--offload-archflags after replacementposix_prefixgives wrong path on Windows)_ninja_escape(): escape Windows drive-letter colons (C:→C$:) in ninja build rule paths; apply to all source/object/link paths_write_ninja_file(): derivenvccpath viaexecutable_path("hipcc")instead of hardcoding<ROCM_HOME>/bin/hipccGPU detection (
chip_info.py):_resolve_gpu_info_tool(): abstractsrocminfo(Linux) vshipInfo.exe(Windows) tool selection and output regex_detect_native()andget_cu_num_custom_op()to use itMHA kernels (
mha.py):_ck_targets_flag()to allblob_gen_cmdentries so non-gfx9 targets pass the correct--targetsflag to CK'sgenerate.py"-DONLY_FAV3=0"flag (was incorrectly wrapped in extra quotes, causing clang to treat it as a filename)_MHA_LOGITS_BLOB_FILTER: on Windows, logits (softcap) blob variants fail to compile because the CK pipelinestatic_assertrequiresCK_TILE_FMHA_FWD_FAST_EXP2=1which defaults to0; exclude these variants until the root cause is resolved upstreamPackaging (
setup.py/pyproject.toml):flydslfrom build and install requirements on WindowsOther:
*.pydto.gitignoretorch.distributedBackend/ProcessGroupimport withtry/exceptinparallel_state.pyrm_module/build_moduleincore.py: use.pydon Windows,.soon LinuxTest Plan
Run all tests under
op_tests/on Windows 11 / gfx1151 with TheRock ROCm 7.15.0a20260718:Test Result
Test Device : AMD RYZEN AI MAX+ 395 w
Python 3.12.10 | PyTorch 2.12.0+rocm7.15.0a20260718 | TheRock ROCm 7.15.0a20260718
14 PASS / 17 SKIP / 1 PASS* / 51 FAIL / 20 TIMEOUT (103 tests total, Windows)
✅ PASS (14) — correctness verified
checkAllclose atol=0.01 rtol=0.01 passedis_equal=TrueALL_PASScheckAllclose atol=0.03 rtol=0.01 passedcheckAllclose atol=0.01 rtol=0.01 passedOutput max diff: 0.00390625(within tolerance)checkAllclose atol=0.01 rtol=0.01 passed84 passed, 0 failedcheckAllclose passedprefill_topk.csvall_close=False, output_diff=0.301, state_diff=0.723; test does not assert on correctness so rc=0⏭️ SKIP (17) — gfx1151 not in supported arch list; test exited rc=0
F4GEMM unsupported on gfx1151requires gfx1250kernel only supports gfx950unsupported on gfx1151unsupported on gfx1151FP8 tests skipping on gfx1151AQRowMajor only supported on gfx950requires gfx1250unsupported on gfx1151unsupported on gfx1151shipped only for gfx950moe_sorting unsupported on gfx1151mxfp8fp4 gemm unsupported on gfx1151requires gfx950/gfx942/gfx1250requires gfx1250requires gfx950❌ FAIL (51)
hip_bfloat16→__halfconversion error inbinary_operator.cuhkv cache data type is not supportedincache_kernels.cuModuleNotFoundError: No module named 'flydsl'ImportError: cannot import from flydslImportError: cannot import from flydslFileNotFoundError: module_gemm_common.so— ctypes standalone module uses.so; Windows needs.pydOSError: Invalid argument— multi-path config file path issue on WindowsValueError: Unsupported FP8 dtypeFileNotFoundError: module_gemm_common.so— same as test_gemm_a16w16torch.finfo()type errorFileNotFoundError: module_cache.so— ctypes standalone module.sopath issueAssertionError: parallel MLA metadata divergedModuleNotFoundError: No module named 'flydsl'tabulateinstalledModuleNotFoundError: No module named 'flydsl'ModuleNotFoundError: No module named 'flydsl'FileNotFoundError: module_X.so— ctypes standalone module.sopath issueAttributeError: host_time_sumOSError: Invalid argument— multi-path config file path issue on WindowsAssertionError: GPU arch['']invalid — gfx1151 not in paged attention supported arch listFileNotFoundError: module_attention_asm.so— ctypes standalone module.sopath issueAssertionError: GPU arch['']invalid — same as test_paAssertionError: GPU arch['']invalid — same as test_paAssertionError: GPU arch['']invalid — same as test_paFileNotFoundError: module_X.so— ctypes standalone module.sopath issueModuleNotFoundError: No module named 'scipy'⏱️ TIMEOUT (20)
Submission Checklist