diff --git a/Dockerfile b/Dockerfile index bc3dc5db9a..10d0f4fc2a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,6 +5,7 @@ FROM nvidia/cuda:13.1.2-devel-ubuntu24.04 AS build ARG DEBIAN_FRONTEND=noninteractive RUN apt-get update \ && apt-get install --yes --no-install-recommends \ + ccache \ cmake \ libavcodec-dev \ libavformat-dev \ @@ -13,17 +14,32 @@ RUN apt-get update \ libswscale-dev \ ninja-build \ pkg-config \ + rsync \ && rm -rf /var/lib/apt/lists/* WORKDIR /src COPY . . -RUN cmake -S . -B /build -G Ninja \ +# Keep source mtimes stable only when contents match; restored/older checkouts must +# still rebuild changed inputs. Package versions isolate toolchain/dependency changes. +# Lock the mutable Ninja tree and copy deliverables out of the transient cache mount. +RUN --mount=type=cache,id=ninfer-build,target=/build,sharing=locked \ + --mount=type=cache,target=/ccache \ + export CCACHE_DIR=/ccache CCACHE_MAXSIZE=20G \ + && build_dir="/build/$(dpkg-query -W | sha256sum | cut -d ' ' -f 1)" \ + && rsync --recursive --links --checksum --delete /src/ /build/src/ \ + && cmake -S /build/src -B "$build_dir" -G Ninja \ -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_C_COMPILER_LAUNCHER=ccache \ + -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ + -DCMAKE_CUDA_COMPILER_LAUNCHER=ccache \ -DNINFER_BUILD_APPS=ON \ -DBUILD_TESTING=OFF \ -DNINFER_BUILD_BENCHMARKS=OFF \ - && cmake --build /build --parallel --target ninfer ninfer-serve + && cmake --build "$build_dir" --parallel --target ninfer ninfer-serve \ + && mkdir -p /out \ + && cp "$build_dir/apps/ninfer" "$build_dir/apps/ninfer-serve" /out/ \ + && ccache --show-stats FROM nvidia/cuda:13.1.2-runtime-ubuntu24.04 @@ -38,8 +54,8 @@ RUN apt-get update \ libswscale7 \ && rm -rf /var/lib/apt/lists/* -COPY --from=build /build/apps/ninfer /usr/local/bin/ninfer -COPY --from=build /build/apps/ninfer-serve /usr/local/bin/ninfer-serve +COPY --from=build /out/ninfer /usr/local/bin/ninfer +COPY --from=build /out/ninfer-serve /usr/local/bin/ninfer-serve WORKDIR /workspace EXPOSE 8080 diff --git a/README.md b/README.md index a29ba87670..46574a9666 100644 --- a/README.md +++ b/README.md @@ -174,6 +174,37 @@ GPU residency is fixed at process startup. `--spec` selects speculative decoding `--vision` independently selects Vision residency. Qwen3.6-35B-A3B DFlash can be combined with Vision; it accelerates generated-text decode after multimodal prefill, not Vision encode itself. +## Optional compiler cache + +For repeated source builds, install [ccache](https://ccache.dev/) and configure CMake's +[compiler launchers](https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_COMPILER_LAUNCHER.html): + +```bash +cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_C_COMPILER_LAUNCHER=ccache \ + -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ + -DCMAKE_CUDA_COMPILER_LAUNCHER=ccache +cmake --build build -j +ccache --show-stats +``` + +These commands run directly on the host; no container tooling is required. Keep the `build/` +directory for incremental builds: Ninja skips unchanged targets, while ccache can reuse C, C++, +and CUDA compiler outputs when compilation is needed again. ccache uses its normal per-user +cache; `CCACHE_DIR` and `CCACHE_MAXSIZE` can override its location and size limit. Statistics are +cumulative, and an unchanged Ninja build adds no compiler-cache calls. + +The ordinary build above does not require ccache. To disable it in a build directory previously +configured with these launchers, clear the cached CMake settings: + +```bash +cmake -S . -B build \ + -DCMAKE_C_COMPILER_LAUNCHER= \ + -DCMAKE_CXX_COMPILER_LAUNCHER= \ + -DCMAKE_CUDA_COMPILER_LAUNCHER= +cmake --build build -j +``` + ## Docker Build the runtime image on a host with the NVIDIA Container Toolkit: @@ -182,6 +213,19 @@ Build the runtime image on a host with the NVIDIA Container Toolkit: docker build --tag ninfer:local . ``` +The Dockerfile enables the same compiler launchers automatically and uses +[build cache mounts](https://docs.docker.com/build/cache/optimize/#use-cache-mounts) for both the +CMake/Ninja build tree and ccache (limited to 20 GiB). Use Docker BuildKit or another builder that +supports `RUN --mount=type=cache`. After source edits, Ninja rebuilds only affected targets; ccache +can reuse compiler outputs when compilation is needed again. The build prints cumulative ccache +statistics, which do not count work skipped by Ninja. + +Source synchronization compares contents and removes deleted files, so restored files with older +timestamps still rebuild correctly. The mutable build-tree cache is locked during each build and +uses separate build directories for different installed toolchain/library versions. Missing or +evicted caches cause a normal rebuild. Finished binaries are copied out of the cache into the image; +ccache and the synchronization tool are only installed in the build stage. + Mount the downloaded model and run the same example server profile: ```bash