srdatalog.ir.codegen.cuda.build.compiler¶
C++ compiler wrapper — turns the on-disk .cpp tree from Phase 7
into a loadable .so.
Nim offloads compilation to its C++ backend via {.compile:} pragmas;
that backend shells out to the system compiler. Python has no such
backend, so we invoke a compiler (clang++/g++/nvcc) directly via
subprocess.
Design notes:
CompilerConfigcarries the full toolchain + flag set. All command assembly flows through_build_compile_cmd/_build_link_cmd— unit tests can verify argv without invoking a real compiler.Per-batch
.cppcompilations run in parallel (ThreadPoolExecutor — subprocess bottleneck is I/O, threads are fine).Hash-based build cache: we sha256 the source + the CLI flags and write a
.stampsidecar file alongside each object file. If the stamp matches, compile is a no-op. Independent of the source mtime-guard incache.py(content didn’t change → no rewrite → no mtime bump) but works even when the source file is touched.SRDATALOG_JIT_COMPILE_JOBS=Noverrides parallelism (0 = cpu_count).SRDATALOG_JIT_SKIP_COMPILE=1skips compile+link entirely — the stamp cache is trusted. MirrorsSRDATALOG_SKIP_JIT_REGENon the cache side.
Default include paths / link flags for generalized_datalog are
supplied by srdatalog.runtime.runtime_include_paths() etc. — this
module just consumes a CompilerConfig.
Module Contents¶
Classes¶
Full |
|
One compile invocation (source → object or link) |
|
Compile + link configuration. |
Functions¶
Compile one |
|
Compile the |
|
Link objects + extra_sources into a shared library. |
API¶
- class srdatalog.ir.codegen.cuda.build.compiler.BuildResult[source]¶
Full
compile_jit_projectoutcome.- compile_results: list[srdatalog.ir.codegen.cuda.build.compiler.CompileResult]¶
‘field(…)’
- link_result: srdatalog.ir.codegen.cuda.build.compiler.CompileResult | None¶
None
- class srdatalog.ir.codegen.cuda.build.compiler.CompileResult[source]¶
One compile invocation (source → object or link)
- class srdatalog.ir.codegen.cuda.build.compiler.CompilerConfig[source]¶
Compile + link configuration.
Defaults are minimal —
cxx_std=c++23is what the runtime headers require. Callers add include/link/libs via the list fields.extra_sourcesis for object files / shared libs to feed into the final link (e.g., pre-built runtime artifacts).True
- srdatalog.ir.codegen.cuda.build.compiler.compile_cpp(source: str, output: str, config: srdatalog.ir.codegen.cuda.build.compiler.CompilerConfig) srdatalog.ir.codegen.cuda.build.compiler.CompileResult[source]¶
Compile one
.cpp→.o. Short-circuits via stamp cache when the source + argv haven’t changed. Never raises on compile error — returns aCompileResultwithreturncode != 0so the caller can aggregate.
- srdatalog.ir.codegen.cuda.build.compiler.compile_jit_project(project_result: srdatalog.ir.codegen.cuda.build.cache.JitProjectLayout, config: srdatalog.ir.codegen.cuda.build.compiler.CompilerConfig | None = None, *, use_ninja: bool | None = None) srdatalog.ir.codegen.cuda.build.compiler.BuildResult[source]¶
Compile the
.cpptree written bycache.write_jit_projectinto a shared library.project_resultis the dict returned by that function — we pullmainandbatchesout and feed them in.Returns a
BuildResult. The caller inspects.ok()and.compile_results/.link_resultfor errors — this function never raises on a compile/link error.use_ninjaselects the backend:True / None (default): emit a build.ninja + PCH rule and invoke the ninja binary (from the
ninjaPyPI wheel). Best wall time on multi-TU projects becausesrdatalog.his precompiled once and reused across every shard.False: fall through to the ThreadPoolExecutor path below (one subprocess per TU, no PCH). Useful on hosts without ninja or for debugging a single TU’s compile command.
SRDATALOG_JIT_NO_NINJA=1forces use_ninja=False regardless of the argument.
Link objects + extra_sources into a shared library.