Repository navigation
cuda: add F16 input to the FWHT - #29096
Merged
Merged
Conversation
This was referenced Sep 18, 2026
The CUDA FWHT accepts F32 input only. This makes the source type a template parameter, so the kernel reads an F16 source directly instead of requiring a converted copy. The F32 path is unchanged. supports_op accepts an F16 src1 against an F32 src0 for the Hadamard hint. Every other F16 src1 against a non-F16 src0 is still refused. ggml_cuda_op_mul_mat_use_fwht is the single predicate both supports_op and the dispatch call now share, checking contiguity and same-shape(src1, dst) in addition to the type/hint conditions above. Without a shared predicate, supports_op could admit an op that ggml_cuda_op_fwht then rejects only after the unconditional same-shape assert has already fired; that gap predates this change (it applies to the existing F32 path too) but this PR is what touches supports_op, so it closes it here. test-backend-ops on an A10 (lambdalabs): MUL_MAT 1297/1297, including all 24 Hadamard cases (18 existing F32, 6 new F16).
bri-prism
force-pushed
the
up/fwht-f16-cuda
branch
from
September 21, 2026 15:47
3b857f9 to
883f5e5
Compare
bri-prism
added a commit
to PrismML-Eng/llama.cpp
that referenced
this pull request
Sep 21, 2026
The CUDA FWHT covers widths 64 to 512. It runs one row per warp and keeps N/32 values per lane, so wider blocks need more registers per lane than that layout allows. fwht_cuda_block runs one row per thread block with 256 threads, so each thread keeps N/256 values. Stages below the warp width still shuffle, those up to the block width go through shared memory, and the rest stay in registers. Same butterfly and sign convention as the warp kernel. Widths 64 to 512 keep the warp kernel. 1024 through 8192 use the new one, for both F32 and F16 sources. ggml_cuda_op_mul_mat_use_fwht (the shared supports_op/dispatch predicate added in ggml-org#29096) does not check width, so it needed no change here: any width it admits that ggml_cuda_op_fwht can't serve already falls through correctly to the cuBLAS path. Rebased onto current master with ggml-org#29096's F16 commit underneath it, since this depends on the same F16 template infrastructure; that commit applied cleanly, the only conflict was in test-backend-ops.cpp where an unrelated intervening commit's own test additions landed near this block. test-backend-ops on an A10 (lambdalabs): MUL_MAT 1297/1297, including all FWHT/Hadamard cases (18 existing, 4 new F32 wide, 4 new F16 wide, 2 new many-rows, 1 too-big boundary moved to 16384).
bri-prism
marked this pull request as ready for review
September 22, 2026 04:22
am17an
reviewed
Sep 23, 2026
am17an
reviewed
Sep 23, 2026
am17an
approved these changes
Sep 23, 2026
katopz
added a commit
to riir-ai/riir-refine
that referenced
this pull request
Sep 25, 2026
…HT check - Pin 37814b1e LIVE via direct sha-fetch; repo moved +9 past pin (5 substantive K8V4-warp/fusion/verify-tree + 4 docs incl. fifth-pass sweep 19-28% shorter rounds) - slot-time adjudication pre-loaded - All 5 lead quotes re-verified verbatim at the pin - T1 dedup re-run vs post-B177 corpus: all 5 leads still novel; LEAD-4 REFRAME (exact-widening framing - kinship fast-accumulate gpu_40 / contrast int32-chunk gpu_33); LEAD-5 sm_89 setmaxnreg regime clause (gpu_37 kinship) - 38th FWHT check NOT FIRED (#29096 open/frozen; first probe hit the wrong repo bevy#29096 - instrument note recorded, canonical = ggml-org/llama.cpp#29096) - item-11 poll at open: bevy/wgpu/cubecl all DRY Session: shikuwa/4090 idle loop, 2026-09-25 ~07:4x-08:1x +07
Contributor
Author
|
@ggerganov gentle ping for a second review when you have a moment. @am17an's suggestions are applied in 6587611 and CI is green. |
JohannesGaessler
approved these changes
Sep 26, 2026
bri-prism
added a commit
to PrismML-Eng/llama.cpp
that referenced
this pull request
Sep 26, 2026
The CUDA FWHT covers widths 64 to 512. It runs one row per warp and keeps N/32 values per lane, so wider blocks need more registers per lane than that layout allows. fwht_cuda_block runs one row per thread block with 256 threads, so each thread keeps N/256 values. Stages below the warp width still shuffle, those up to the block width go through shared memory, and the rest stay in registers. Same butterfly and sign convention as the warp kernel. Widths 64 to 512 keep the warp kernel. 1024 through 8192 use the new one, for both F32 and F16 sources. ggml_cuda_op_mul_mat_use_fwht (the shared supports_op/dispatch predicate added in ggml-org#29096) does not check width, so it needed no change here: any width it admits that ggml_cuda_op_fwht can't serve already falls through correctly to the cuBLAS path. Rebased onto current master with ggml-org#29096's F16 commit underneath it, since this depends on the same F16 template infrastructure; that commit applied cleanly, the only conflict was in test-backend-ops.cpp where an unrelated intervening commit's own test additions landed near this block. test-backend-ops on an A10 (lambdalabs): MUL_MAT 1297/1297, including all FWHT/Hadamard cases (18 existing, 4 new F32 wide, 4 new F16 wide, 2 new many-rows, 1 too-big boundary moved to 16384).
edwardyoon
pushed a commit
to edwardyoon/focus-llama
that referenced
this pull request
Oct 2, 2026
* cuda: add F16 input to the FWHT The CUDA FWHT accepts F32 input only. This makes the source type a template parameter, so the kernel reads an F16 source directly instead of requiring a converted copy. The F32 path is unchanged. supports_op accepts an F16 src1 against an F32 src0 for the Hadamard hint. Every other F16 src1 against a non-F16 src0 is still refused. ggml_cuda_op_mul_mat_use_fwht is the single predicate both supports_op and the dispatch call now share, checking contiguity and same-shape(src1, dst) in addition to the type/hint conditions above. Without a shared predicate, supports_op could admit an op that ggml_cuda_op_fwht then rejects only after the unconditional same-shape assert has already fired; that gap predates this change (it applies to the existing F32 path too) but this PR is what touches supports_op, so it closes it here. test-backend-ops on an A10 (lambdalabs): MUL_MAT 1297/1297, including all 24 Hadamard cases (18 existing F32, 6 new F16). * cuda: use ggml_cuda_cast in the FWHT load, drop the comment
1 task
Wizard815
pushed a commit
to Wizard815/mx-llama.cpp-Rocm10
that referenced
this pull request
Oct 6, 2026
* cuda: add F16 input to the FWHT The CUDA FWHT accepts F32 input only. This makes the source type a template parameter, so the kernel reads an F16 source directly instead of requiring a converted copy. The F32 path is unchanged. supports_op accepts an F16 src1 against an F32 src0 for the Hadamard hint. Every other F16 src1 against a non-F16 src0 is still refused. ggml_cuda_op_mul_mat_use_fwht is the single predicate both supports_op and the dispatch call now share, checking contiguity and same-shape(src1, dst) in addition to the type/hint conditions above. Without a shared predicate, supports_op could admit an op that ggml_cuda_op_fwht then rejects only after the unconditional same-shape assert has already fired; that gap predates this change (it applies to the existing F32 path too) but this PR is what touches supports_op, so it closes it here. test-backend-ops on an A10 (lambdalabs): MUL_MAT 1297/1297, including all 24 Hadamard cases (18 existing F32, 6 new F16). * cuda: use ggml_cuda_cast in the FWHT load, drop the comment (cherry picked from commit 6f856c7)
edwardyoon
pushed a commit
to edwardyoon/focus-llama
that referenced
this pull request
Oct 7, 2026
* cuda: add F16 input to the FWHT The CUDA FWHT accepts F32 input only. This makes the source type a template parameter, so the kernel reads an F16 source directly instead of requiring a converted copy. The F32 path is unchanged. supports_op accepts an F16 src1 against an F32 src0 for the Hadamard hint. Every other F16 src1 against a non-F16 src0 is still refused. ggml_cuda_op_mul_mat_use_fwht is the single predicate both supports_op and the dispatch call now share, checking contiguity and same-shape(src1, dst) in addition to the type/hint conditions above. Without a shared predicate, supports_op could admit an op that ggml_cuda_op_fwht then rejects only after the unconditional same-shape assert has already fired; that gap predates this change (it applies to the existing F32 path too) but this PR is what touches supports_op, so it closes it here. test-backend-ops on an A10 (lambdalabs): MUL_MAT 1297/1297, including all 24 Hadamard cases (18 existing F32, 6 new F16). * cuda: use ggml_cuda_cast in the FWHT load, drop the comment (cherry picked from commit 6f856c7)
JohannesGaessler
pushed a commit
that referenced
this pull request
Oct 7, 2026
The CUDA FWHT covers widths 64 to 512. It runs one row per warp and keeps N/32 values per lane, so wider blocks need more registers per lane than that layout allows. fwht_cuda_block runs one row per thread block with 256 threads, so each thread keeps N/256 values. Stages below the warp width still shuffle, those up to the block width go through shared memory, and the rest stay in registers. Same butterfly and sign convention as the warp kernel. Widths 64 to 512 keep the warp kernel. 1024 through 8192 use the new one, for both F32 and F16 sources. ggml_cuda_op_mul_mat_use_fwht (the shared supports_op/dispatch predicate added in #29096) does not check width, so it needed no change here: any width it admits that ggml_cuda_op_fwht can't serve already falls through correctly to the cuBLAS path. Rebased onto current master with #29096's F16 commit underneath it, since this depends on the same F16 template infrastructure; that commit applied cleanly, the only conflict was in test-backend-ops.cpp where an unrelated intervening commit's own test additions landed near this block. test-backend-ops on an A10 (lambdalabs): MUL_MAT 1297/1297, including all FWHT/Hadamard cases (18 existing, 4 new F32 wide, 4 new F16 wide, 2 new many-rows, 1 too-big boundary moved to 16384).
edwardyoon
pushed a commit
to edwardyoon/focus-llama
that referenced
this pull request
Oct 8, 2026
The CUDA FWHT covers widths 64 to 512. It runs one row per warp and keeps N/32 values per lane, so wider blocks need more registers per lane than that layout allows. fwht_cuda_block runs one row per thread block with 256 threads, so each thread keeps N/256 values. Stages below the warp width still shuffle, those up to the block width go through shared memory, and the rest stay in registers. Same butterfly and sign convention as the warp kernel. Widths 64 to 512 keep the warp kernel. 1024 through 8192 use the new one, for both F32 and F16 sources. ggml_cuda_op_mul_mat_use_fwht (the shared supports_op/dispatch predicate added in ggml-org#29096) does not check width, so it needed no change here: any width it admits that ggml_cuda_op_fwht can't serve already falls through correctly to the cuBLAS path. Rebased onto current master with ggml-org#29096's F16 commit underneath it, since this depends on the same F16 template infrastructure; that commit applied cleanly, the only conflict was in test-backend-ops.cpp where an unrelated intervening commit's own test additions landed near this block. test-backend-ops on an A10 (lambdalabs): MUL_MAT 1297/1297, including all FWHT/Hadamard cases (18 existing, 4 new F32 wide, 4 new F16 wide, 2 new many-rows, 1 too-big boundary moved to 16384). (cherry picked from commit b86d2f0)
edwardyoon
pushed a commit
to edwardyoon/focus-llama
that referenced
this pull request
Oct 24, 2026
The CUDA FWHT covers widths 64 to 512. It runs one row per warp and keeps N/32 values per lane, so wider blocks need more registers per lane than that layout allows. fwht_cuda_block runs one row per thread block with 256 threads, so each thread keeps N/256 values. Stages below the warp width still shuffle, those up to the block width go through shared memory, and the rest stay in registers. Same butterfly and sign convention as the warp kernel. Widths 64 to 512 keep the warp kernel. 1024 through 8192 use the new one, for both F32 and F16 sources. ggml_cuda_op_mul_mat_use_fwht (the shared supports_op/dispatch predicate added in ggml-org#29096) does not check width, so it needed no change here: any width it admits that ggml_cuda_op_fwht can't serve already falls through correctly to the cuBLAS path. Rebased onto current master with ggml-org#29096's F16 commit underneath it, since this depends on the same F16 template infrastructure; that commit applied cleanly, the only conflict was in test-backend-ops.cpp where an unrelated intervening commit's own test additions landed near this block. test-backend-ops on an A10 (lambdalabs): MUL_MAT 1297/1297, including all FWHT/Hadamard cases (18 existing, 4 new F32 wide, 4 new F16 wide, 2 new many-rows, 1 too-big boundary moved to 16384).
auRose94
pushed a commit
to auRose94/llama.cpp
that referenced
this pull request
Oct 28, 2026
The CUDA FWHT covers widths 64 to 512. It runs one row per warp and keeps N/32 values per lane, so wider blocks need more registers per lane than that layout allows. fwht_cuda_block runs one row per thread block with 256 threads, so each thread keeps N/256 values. Stages below the warp width still shuffle, those up to the block width go through shared memory, and the rest stay in registers. Same butterfly and sign convention as the warp kernel. Widths 64 to 512 keep the warp kernel. 1024 through 8192 use the new one, for both F32 and F16 sources. ggml_cuda_op_mul_mat_use_fwht (the shared supports_op/dispatch predicate added in ggml-org#29096) does not check width, so it needed no change here: any width it admits that ggml_cuda_op_fwht can't serve already falls through correctly to the cuBLAS path. Rebased onto current master with ggml-org#29096's F16 commit underneath it, since this depends on the same F16 template infrastructure; that commit applied cleanly, the only conflict was in test-backend-ops.cpp where an unrelated intervening commit's own test additions landed near this block. test-backend-ops on an A10 (lambdalabs): MUL_MAT 1297/1297, including all FWHT/Hadamard cases (18 existing, 4 new F32 wide, 4 new F16 wide, 2 new many-rows, 1 too-big boundary moved to 16384).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
The CUDA FWHT accepts F32 input only. This makes the source type a template parameter, so
the kernel reads an F16 source directly instead of requiring a converted copy. The F32 path
is unchanged.
supports_opaccepts an F16src1against an F32src0for the Hadamard hint. Every otherF16
src1against a non-F16src0is still refused.This is the CUDA counterpart to #27779 (CPU) and #29094 (Metal).
Additional information
Tested on an H100 PCIe (compute capability 9.0, CUDA 12.8,
-DCMAKE_CUDA_ARCHITECTURES=90):test-backend-ops -o MUL_MAT_HADAMARD15/15, including the six new F16 casestest-backend-ops -o MUL_MAT1297/1297, run on the stacked tree that also carries cuda: FWHT kernels for block widths above 512 #29100The
supports_opexception is narrow on purpose: the generic F32 src0 against F16 src1 path isnot implemented, so admitting a case the FWHT dispatch then declines would fall through to a
kernel that does not exist. #29094 has the Metal version of that same reasoning.
Requirements
structure of the CPU and Metal versions, and to format this description to the PR template.
I reviewed every line and take full responsibility for the changes.