Skip to content

GGML-CUDA: Optimized build time of project ggml-cuda - #31182

Draft
kmorennv wants to merge 6 commits into
ggml-org:masterfrom
kmorennv:optimized-build-time-ggml-cuda
Draft

kmorennv wants to merge 6 commits into
ggml-org:masterfrom
kmorennv:optimized-build-time-ggml-cuda

Conversation

@kmorennv

@kmorennv kmorennv commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Overview

This branch reduce the build time of cold un-cached ggml-cuda project.

Applied are two major approaches to speed up build times:

  • reduce the number of parser passes on headers in nvcc front-end. The commit 65b042f7 that batch TUs increases the reuse of parsed big headers such as common.cuh.
  • reduce and filter out unused template instances commits: 7ba40e2f518, ccbd39377027171

Why

It should reduce pressure on CI/CD pipelines with cold-caches. This can be seen as simple low-hanging fruit PR with non invasive code changes that reduce build-time.

Other more involved ideas such as: quant-specific build options in cmake reduce significantly build time. However they modify more TUs and headers and can be seen as follow PRs.

Additional information

Tests on Linux and Windows systems show ~ 20% reduction independent on platform.
The tests on AMD-Backend are also safe without regressions.

Requirements

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: Yes, agent explored and automatically benchmarked mechanical code changes. I decided what should be explored and accepted.

@github-actions github-actions Bot added ggml changes relating to the ggml tensor library for machine learning CUDA Related to the CUDA backend labels Oct 26, 2026
@CISC

CISC commented Oct 26, 2026 •

Copy link
Copy Markdown
Member

Awesome, but there seems to be unrelated changes?
Nvm, read the comments.

@kmorennv

Copy link
Copy Markdown
Contributor Author

@CISC I have still open other PR #26048. I make update today and expect soon merge it. Than open this one. Nevertheless, I am open to any suggestions.

@ORippler ORippler left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. IMO, the pruning for mmvf/fattn-tile.cuh should follow the logic of MMQ (i.e. ggml_cuda_*_config for host/device side (potentially shared) that is used to gate both host and device side of things).
  2. That batched compilation seems a bit arbitrary/potentially brittle. How much of perf is gained from pruning vs. batching?

Comment thread ggml/src/ggml-cuda/CMakeLists.txt Resolved

@JohannesGaessler JohannesGaessler left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason why we are not using the built-in UNITY_BUILD?

@kmorennv

Copy link
Copy Markdown
Contributor Author

@JohannesGaessler no at all. Thanks for point on it. I take a look.

@kmorennv

Copy link
Copy Markdown
Contributor Author

@JohannesGaessler Thank you for this pointer to UNITY_BUILD. I used this since its cleaner change in CMake.

I explored this approach with NVRTC tetherto#488

AmanG applies NVRTC where in short:

  • Groups compatible pointwise, normalization, copy/view, and SSM convolution operations into generated CUDA kernels.
  • Compiles source to CUBIN for the current GPU using NVRTC, then loads and launches it through the CUDA Driver API.
  • Caches kernel structure and functions in memory, and CUBINs on disk. Compilation happens before CUDA graph capture.
  • Falls back to existing kernels when generation, compilation, or memory checks reject a group.

This feature without doubt minimize the project-build time significantly. I do PoC on side that in short use NVRTC to compile the templated-instances on-demand. Dependent on the model the binaries are build during the model load. I need to invest my time to something else till begin of next week. I write update during next week.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CUDA Related to the CUDA backend ggml changes relating to the ggml tensor library for machine learning

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants