cuda : accelerate conv2d with implicit GEMM - #29135
Conversation
|
Hi @leejet, thanks for your contribution! Per our contribution guidelines, the automated PR checker found the following issue(s) that need your attention:
Please note that maintainers reserve the right to make final decisions on PRs. If you believe there is a mistake, please comment below. |
|
For an example of the actual speedup achieved on real models in sd.cpp, please refer to leejet/stable-diffusion.cpp#1993. |
ggerganov
left a comment
There was a problem hiding this comment.
I think it is OK to merge since this is battle-tested downstream, but let's give some time in case someone from @ggml-org/ggml-cuda can take a look too.
am17an
left a comment
There was a problem hiding this comment.
I tested this out locally and it works. I know there were several attempts at getting this right but this one is particularly well written, so thanks!
|
Thanks for reviewing and merging the PR! Really appreciate it. |
Overview
Accelerate the existing CUDA CONV_2D operator for F16 weights and F32 activations with a compact implicit-GEMM implementation. It uses a fixed 64x64x64 tile and the existing
mma.cuhinterface, with F32 accumulation, split-K for small spatial maps, and a cuBLAS path for eligible 1x1 convolutions.The existing direct kernel remains the fallback, including F32 weights and small convolutions where conversion and launch overhead can outweigh the benefit. Three regression cases cover channel tails, multiple batches, stride/dilation, and the 1x1 path. The change is confined to
conv2d.cuand the existing operator test file.Additional information
Existing work such as #15805 already explores implicit-GEMM convolution. This proposal focuses on keeping the implementation compact and straightforward to review: reuse the existing MMA primitives, use one tile configuration, keep the indexing and dispatch local, and retain the current fallback. The goal is to reduce review and maintenance overhead while providing useful acceleration.
Selected operator timings on an RTX 4090 with CUDA 12.4, Release, and CUDA graphs enabled, compared with
1af554f. Input dimensions are [W,H,IC,N]; kernel dimensions are [KW,KH,IC,OC]. These are microbenchmarks, not end-to-end model results.Requirements