Repository navigation
codegen: harden the standalone experimental backend (follow-up to #314) - #357
alejandro-soto-franco wants to merge 1 commit into
Conversation
Follow-up to NVIDIA#314's cuda-oxide-codegen extraction. Fixes from a full review of the merged PR: - Compiler::compile no longer leaks the cloned IR if compile_clone panics; the erase now runs from an RAII guard instead of a plain post-call. - Add Compiler::compile_owned for single-use callers, so the module clone Compiler::compile always pays for is opt-in rather than unconditional. - Target/feature-floor validation failures from the standalone API no longer reference the legacy CUDA_OXIDE_TARGET env var they never touched, and are classified as CompilationStage::Input instead of Codegen. BackendOptions carries a target_arch_source label so both the env-driven rustc pipeline and the standalone API describe their own provenance. - The explicit-Toolchain compile path no longer discards pipeline diagnostics; CompileOptions gains with_verbose/verbose so the standalone API can actually request them (previously unreachable through the public surface). Toolchain::from_paths now also reports what it selected instead of always returning empty diagnostics. - ScratchDirectory is now backed by tempfile::Builder instead of a hand-rolled RAII implementation. The workspace tempfile floor is raised from 3.3 to 3.9, the first release exposing Builder::permissions, which the 0o700 scratch-dir mode relies on; 3.3-3.8 would fail to compile. - Deduplicate the module-liveness check shared by mark_kernel_entry and Compiler::compile into one helper. - Document (rather than attempt) the double LLVM-IR-render on the libdevice path: the preview and final renders are of genuinely different module states through different export configs, so caching one for the other would be unsound; a real fix needs feature detection to move off rendered text entirely. Signed-off-by: Alejandro Soto Franco <[email protected]>
3599012 to
33b7268
Compare
|
Closing in favour of three smaller PRs. This one bundled eight unrelated fixes across 12 files, which put the small ones behind a dependency discussion and made the whole thing awkward to review in a sitting.
The three are independent. Each applies cleanly to The split also picked up review fixes that were not in this PR: the reclassification here routed feature-floor rejections through |
Follow-up to #314 (the
cuda-oxide-codegenrustc-independent MIR→PTX extraction, now merged). This gathers the fixes from a full review of that merged PR. No behaviour change for the existing env-driven rustc pipeline; the work hardens the standalone experimentalCompiler/CompileOptionsAPI and its diagnostics.Correctness
Compiler::compileclones the caller's module and runs the destructive pipeline on the clone. The previous "compile, then erase" sequence skipped the erase ifcompile_clonepanicked, permanently leaking the clone in the sharedContextarena. The erase now runs from an RAIIEraseGuard, so it fires on every exit path including an unwinding panic. Covered by a new unit test.tempfilefloor.ScratchDirectorynow usestempfile::Builderwith a0o700mode viaBuilder::permissions, which first shipped in tempfile 3.9. The workspace floor is raised3.3 → 3.9accordingly; a downstream consumer resolving 3.3–3.8 would otherwise fail to compile.Diagnostics and error provenance
CUDA_OXIDE_TARGET, which those callers never touch, and were classified asCompilationStage::Codegen. They now carry the caller's own provenance and are classified as input errors.BackendOptionsgains atarget_arch_sourcelabel so the env-driven rustc pipeline and the standalone API each describe where their target came from; a newPipelineError::TargetSelectiondistinguishes "bad requested target" from "llcfailed".Toolchainpath keeps its diagnostics. The explicit-toolchain compile path discarded pipeline diagnostics, andCompileOptionshad no way to request verbose output through the public surface.CompileOptionsgainswith_verbose/verbose, andToolchain::from_pathsnow reports the tools it selected instead of always returning empty diagnostics.API and cleanup
Compiler::compile_owned. Single-use callers can now consume the module and skip the defensive clone thatcompilealways pays for, running passes directly on the owned IR. Useful for large, one-shot modules.mark_kernel_entryandCompiler::compileinto one helper.Testing
cargo test -p cuda-oxide-codegen— 75 passed across 5 suites, including new tests for the panic-safe erase guard and the source-label threading inresolve_ptx_target.cargo clippy -p cuda-oxide-codegen --all-targets— clean.