Skip to content

Port CoMet's INT4 tensor-core GEMM, the kernel an nsys profile says i… - #16

Closed
laesse10 wants to merge 1 commit into
mainfrom
comet
Closed

Port CoMet's INT4 tensor-core GEMM, the kernel an nsys profile says i…#16
laesse10 wants to merge 1 commit into
mainfrom
comet

Conversation

@laesse10

@laesse10 laesse10 commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

…s 99.8% of it

CoMet (Joubert et al., SC18 Gordon Bell) computes pairwise genomic similarity metrics. Profiling a real 2-way CCC run on a GH200 -- 18 back-to-back invocations at --num_field 800000 --num_vector 20000 --tc 6 --num_kernel 10, ~19 minutes of GPU time -- puts one CUTLASS int4 GEMM at 99.8% of it (61.87s/call), with the three surrounding kernels at 0.1%, 0.1%, and <0.1%. Only the GEMM is ported; the other three are real kernels but not hot ones, and padding the count would misreport where the time goes.

Classified dense_linear_algebra rather than the genomics default of dynamic_programming/graph_traversal. CoMet's whole trick is reformulating a bit-tally count as a dense GEMM so it lands on tensor cores -- there is no recurrence and no graph, it is cutlass::gemm::device::Gemm<int4b_t,...>. Level 1 for the same reason tests/test_levels.py calls "gemm" level 1: the unusual part is the operand encoding, not the computational pattern.

The extraction keeps the GEMM's mathematical contract and drops the parts with no CPU meaning. Traced from CoMet's source rather than guessed: tc_buf_write_kernel_ writes cnt_iE(v), the number of iE-valued bits in a 2-bit field code, as the int4 operand (src/tc_in.i.hh:202-210) -- not a one-hot expansion and not a reinterpret -- so the INT32 accumulator is exactly sum_f cnt_iE(left[I,f]) * cnt_jE(right[J,f]). LinearCombinationClamp is a numerical no-op at ElementOutput == ElementCompute == int32_t, and OpMultiplyAddSaturate never saturates for this data (per-field products are bounded by 4, so overflow needs >5e8 fields in one --num_tc_steps chunk), so plain accumulation is bit-exact. tc_repair_metrics_kernel_ only undoes a GPU-tiling row permutation, which a CPU port has no reason to introduce.

The OpenMP decomposition mirrors CUTLASS's actual grid: one task per 128x256 output tile, the shape GemmIdentityThreadblockSwizzle + ThreadblockShape <128,256,256> produces. The warp/MMA tier below that exists to keep tensor cores fed and has no scalar-CPU analogue, so it is not reproduced. No scatter here -- each output element is owned by one tile -- so there are no atomics and the result is bit-identical across thread counts, which the port test asserts rather than grading peak-relative.

Verified on Alps (aarch64, GH200): 10 port tests pass, and the e2e oracle passes all three native-emit backends including fortran, which could not be checked on macOS.

…s 99.8% of it

CoMet (Joubert et al., SC18 Gordon Bell) computes pairwise genomic similarity
metrics. Profiling a real 2-way CCC run on a GH200 -- 18 back-to-back
invocations at --num_field 800000 --num_vector 20000 --tc 6 --num_kernel 10,
~19 minutes of GPU time -- puts one CUTLASS int4 GEMM at 99.8% of it
(61.87s/call), with the three surrounding kernels at 0.1%, 0.1%, and <0.1%.
Only the GEMM is ported; the other three are real kernels but not hot ones,
and padding the count would misreport where the time goes.

Classified dense_linear_algebra rather than the genomics default of
dynamic_programming/graph_traversal. CoMet's whole trick is reformulating a
bit-tally count as a dense GEMM so it lands on tensor cores -- there is no
recurrence and no graph, it is cutlass::gemm::device::Gemm<int4b_t,...>.
Level 1 for the same reason tests/test_levels.py calls "gemm" level 1: the
unusual part is the operand encoding, not the computational pattern.

The extraction keeps the GEMM's mathematical contract and drops the parts
with no CPU meaning. Traced from CoMet's source rather than guessed:
tc_buf_write_kernel_ writes cnt_iE(v), the number of iE-valued bits in a 2-bit
field code, as the int4 operand (src/tc_in.i.hh:202-210) -- not a one-hot
expansion and not a reinterpret -- so the INT32 accumulator is exactly
sum_f cnt_iE(left[I,f]) * cnt_jE(right[J,f]). LinearCombinationClamp is a
numerical no-op at ElementOutput == ElementCompute == int32_t, and
OpMultiplyAddSaturate never saturates for this data (per-field products are
bounded by 4, so overflow needs >5e8 fields in one --num_tc_steps chunk), so
plain accumulation is bit-exact. tc_repair_metrics_kernel_ only undoes a
GPU-tiling row permutation, which a CPU port has no reason to introduce.

The OpenMP decomposition mirrors CUTLASS's actual grid: one task per 128x256
output tile, the shape GemmIdentityThreadblockSwizzle + ThreadblockShape
<128,256,256> produces. The warp/MMA tier below that exists to keep tensor
cores fed and has no scalar-CPU analogue, so it is not reproduced. No scatter
here -- each output element is owned by one tile -- so there are no atomics
and the result is bit-identical across thread counts, which the port test
asserts rather than grading peak-relative.

Verified on Alps (aarch64, GH200): 10 port tests pass, and the e2e oracle
passes all three native-emit backends including fortran, which could not be
checked on macOS.
@laesse10 laesse10 closed this Aug 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant