Skip to content

build: cache native compilation and incremental image builds - #97

Draft
DuncanBetts wants to merge 4 commits into
Neroued:masterfrom
DuncanBetts:build/cache-cxx-cuda
Draft

build: cache native compilation and incremental image builds#97
DuncanBetts wants to merge 4 commits into
Neroued:masterfrom
DuncanBetts:build/cache-cxx-cuda

Conversation

@DuncanBetts

@DuncanBetts DuncanBetts commented Aug 26, 2026

Copy link
Copy Markdown

Upstream image rebuilds discard the entire CMake/Ninja build tree when source files change. This PR retains that tree and adds ccache: editing one C++ file and one CUDA file then runs seven affected build steps instead of all 278. Native builds can enable the same compiler cache through standard CMake launchers.

  • Document optional native CMake compiler launchers, incremental rebuilds, cache configuration, statistics, and how to disable the launchers again. The ordinary native build needs neither ccache nor container tooling.
  • Retain the CMake/Ninja tree in a locked build cache mount. Synchronize sources by content, remove deleted files, and use a different build directory when installed toolchain/library versions change. Copy completed binaries out of the cache for the runtime image.
  • Install ccache and rsync only in the build stage. Keep ccache in a separate mount with a 20 GiB limit, so compiler outputs can also be reused when Ninja needs to compile again.
  • Use the existing Docker workflow. No Compose file, Podman-specific workflow, extra build stage, or Python dependency is introduced.

No project-specific CMake option is needed: CMake already supports compiler launchers for all three languages. The runtime image and inference behavior are unchanged.

Rebuild comparison: upstream versus this PR

Both recordings follow the same workload: build the image, add the same harmless static_assert to src/artifact/typed_binding.cpp and src/ops/launcher/residual_add.cu, rebuild, then restore the sources. The baseline is upstream without this PR; the after result is the final implementation with persistent Ninja and compiler caches.

Rebuild after the two-file edit Upstream without this PR With this PR
Image rebuild wall time 127.750 s 20.090 s
Ninja steps 278 7
Compiler invocations 263 2

The recorded rebuild is approximately 6.4× faster. These are single-run measurements recorded separately, not a contemporaneous controlled benchmark. The baseline is the original upstream recording; it has not been rerun alongside the final revision. The times cover image rebuilding, not native-build or inference performance.

The after run started with empty, isolated build and compiler caches. Its initial build made 263 compiler calls; the edited rebuild made only two more. Ninja skipped all 261 unchanged compiler inputs, so the cumulative ccache statistics are 265 calls, zero hits, and 265 misses. CUDA device linking still took about 13.4 seconds on the rebuild.

Validation

Using Ubuntu 24.04, CMake 3.28.3, CUDA 13.1.115, and ccache 4.9.1:

  • The revised Dockerfile built both product binaries and the runtime image successfully (278 Ninja steps; all 263 compiler calls cacheable).
  • Restoring the two source files with timestamps from 2000 correctly rebuilt both objects (two ccache hits).
  • Changing only non-code build context reported ninja: no work to do, with no new compiler-cache calls.
  • After clearing all three launchers and moving ccache out of PATH in a disposable build container, the C++ artifact-binding and CUDA residual-add objects compiled successfully.
  • Both runtime binaries passed --help with NVIDIA driver libraries exposed; the runtime image contains neither ccache nor rsync.
  • git diff --check passed.

Validation used Podman's Dockerfile support because Docker and a native host CMake/CUDA toolchain are not installed here. Docker BuildKit and a bare-host build were not executed; the native instructions use standard CMake settings and introduce no container dependency.

References

The original PR said "with careful steering and review by myself". This updated version I have not reviewed properly yet, so I am reverting its status to "draft" until I do.

Changes made using AI. Thanks for creating Ninfer Neroued, I hope you find these build time savings useful in future work, you can take it as a token of my appreciation :).

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e64041e07a

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread compose.yaml Outdated
Comment thread compose.yaml Outdated
@DuncanBetts DuncanBetts changed the title build: cache C++ and CUDA compilation in container builds build: cache C++ and CUDA compilation in container builds Aug 26, 2026
kaushikvira added a commit to kaushikvira/ninfer that referenced this pull request Sep 7, 2026
Port of upstream PR Neroued#97 (DuncanBetts/ninfer build/cache-cxx-cuda):
- add ccache, set CCACHE_DIR=/ccache (cache mount) + 20G max
- compiler launchers = ccache for C/C++/CUDA
- unchanged translation units stop recompiling on every docker build

Also staged: include/skip Responses fixes (333df.., dbe12502+).
Our fork main is now upstream 487f897 + engine registration + tools/docs
+ Responses include/skip + build cache.
kaushikvira added a commit to kaushikvira/ninfer that referenced this pull request Sep 7, 2026
… tooling')

main is upstream 487f897 + 9 commits: own nvfp4full registration + graft
tool, the Neroued#148/Neroued#97/Neroued#160/Neroued#61 PR ports (temp, drop as they merge), the
registry doc, and curl for healthchecks. Registry table in PATCHES.md now
covers all 9 (added curl + registry rows, date -> 2026-09-15).
@DuncanBetts DuncanBetts changed the title build: cache C++ and CUDA compilation in container builds build: cache native compilation and incremental image builds Sep 12, 2026
@DuncanBetts
DuncanBetts marked this pull request as draft September 12, 2026 02:32
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