srdatalog.ir.codegen.cuda.build.compiler_ninja

Ninja + PCH compile orchestrator.

Emits a build.ninja in the cache dir that:

  1. Precompiles srdatalog.h into a .pch once per build (srdatalog.h pulls in boost/hana/mp11/RMM/spdlog — ~4s per TU to parse cold, so one PCH saves ~(N-1) * 4s on N-shard projects like doop).

  2. Compiles every project .cpp with -include-pch srdatalog.pch.

  3. Links the resulting objects + extra_sources into a shared library.

Invokes ninja via the ninja PyPI wheel so we don’t need a system binary — pip install srdatalog pulls the ninja wheel as a transitive dep (~500 KB).

Contract matches compile_jit_project in compiler.py:

  • Input: project_result dict from cache.write_jit_project, plus a CompilerConfig.

  • Output: BuildResult with compile + link results.

The ThreadPoolExecutor orchestrator in compiler.py remains as a fallback (env SRDATALOG_JIT_NO_NINJA=1 or use_ninja=False) for contributors without ninja installed or for debugging a single-TU compile path.

Module Contents

Functions

compile_jit_project_ninja

Drop-in replacement for compile_jit_project that goes through ninja + PCH. Returns the same BuildResult shape so callers don’t need to change.

emit_build_ninja

Write <cache_dir>/build.ninja from project_result + config.

API

srdatalog.ir.codegen.cuda.build.compiler_ninja.compile_jit_project_ninja(project_result: srdatalog.ir.codegen.cuda.build.cache.JitProjectLayout, config: srdatalog.ir.codegen.cuda.build.compiler.CompilerConfig | None = None, *, use_pch: bool = False) srdatalog.ir.codegen.cuda.build.compiler.BuildResult[source]

Drop-in replacement for compile_jit_project that goes through ninja + PCH. Returns the same BuildResult shape so callers don’t need to change.

Compile-failure reporting: on non-zero ninja exit, we return a single synthetic CompileResult holding ninja’s captured output — we don’t parse per-TU diagnostics out of ninja’s stream (ninja already shows them verbatim to stderr). Callers can still read .stderr + exit code.

srdatalog.ir.codegen.cuda.build.compiler_ninja.emit_build_ninja(project_result: srdatalog.ir.codegen.cuda.build.cache.JitProjectLayout, config: srdatalog.ir.codegen.cuda.build.compiler.CompilerConfig, *, use_pch: bool = False, use_ccache: bool | None = None) str[source]

Write <cache_dir>/build.ninja from project_result + config.

Returns the absolute path to the emitted ninja file.

Args: use_pch: opt-in split host/device PCH. Disabled by default because clang’s CUDA + PCH pipeline is fragile on our runtime headers (ptxas chokes when -Xclang -emit-pch runs with --cuda-*-only on headers that transitively pull CUDA intrinsics via gpu/search.h). Keep the code path so future runtime-header cleanups can flip it on with use_pch=True. use_ccache: prepend ccache to the compile command when it’s on PATH. Defaults to True iff ccache is found. Warm rebuilds after rm -rf build/ go from ~97s → ~5s on doop with ccache. Override via SRDATALOG_JIT_NO_CCACHE=1.