Repository navigation
feat(cargo-oxide): add emit-ltoir to build a crate's LTOIR in one step - #256
Conversation
`cargo oxide build --emit-nvvm-ir` stops at NVVM IR, leaving the caller to run libNVVM separately to get linkable LTOIR. `emit-ltoir` folds both halves into a single command for the Tile-to-SIMT interop workflow (NVIDIA#96), where cuda-oxide is the SIMT participant: it builds the crate in NVVM IR mode, compiles the emitted `<crate>.ll` with libNVVM `-gen-lto`, and writes `<crate>.ltoir`. `--arch` is required (LTOIR is architecture-specific) and accepts sm_XX, compute_XX, or a bare XX; `-o/--output` overrides the default `<crate>.ltoir` path. The command reuses the existing libnvvm-sys binding and the NVVM IR build path, and rejects metadata interop examples. cuda-oxide exports NVVM IR 2.0 (opaque pointers), which libNVVM only accepts for compute_100 and newer (Blackwell+); older targets reject the module while parsing types, surfacing as a bare `parse expected type` with no hint at the cause. On a libNVVM failure below compute_100, `emit-ltoir` now appends a short explanation pointing at NVIDIA#98 and suggesting sm_100 or newer. The hint is gated on actual failure so it disappears if the floor ever moves. Adds unit tests for the arch normalization and the capability parse, and documents the command and the compute_100 floor in the cargo-oxide README. Part of NVIDIA#96. Signed-off-by: Alejandro Soto Franco <[email protected]>
c8be3d6 to
bc409c1
Compare
|
Thanks for the PR. LGTM 👍🏾 Reviewer note: three fixes layered on our side before merge.
Partially addresses #96 (the Phase 1 emit-ltoir checklist item). Related to #98 (the helpful error hint is wired up; the typed-pointer export root cause remains a separate workstream). |
641af7a to
427e376
Compare
…n README flags table Three correctness and polish fixes layered on alejandro-soto-franco's original: 1. compile_nvvm_to_ltoir now adds libdevice.10.bc before the kernel module, matching the pattern in cuda-host/src/ltoir.rs. Without this, any kernel that calls libdevice math (__nv_expf, __nv_sinf, etc.) would produce LTOIR with unresolved __nv_* symbols, silently breaking the artifact at link time. 2. codegen_build gains a quiet: bool parameter. emit_ltoir passes quiet=true so the intermediate "Build succeeded" line is suppressed; the unified "LTOIR written to ..." line is the single summary the user sees. 3. README flags table merges the two --arch rows into one (the duplicate was introduced by this PR), widens the "Applies to" column uniformly, and adds a one-line note clarifying that --arch is required for emit-ltoir.
427e376 to
b70efaa
Compare
Wrap the bare issue URL in angle brackets and backtick-escape the <crate-dir>/<crate> placeholder to prevent rustdoc -D warnings from treating them as an invalid hyperlink and unclosed HTML tags.
…NVIDIA#225, NVIDIA#185) (NVIDIA#256) Three squash merges landed from branches that had resolved a merge against main by keeping pre-merge copies of files, so each one quietly reverted an earlier, unrelated merge: - NVIDIA#239 (2482cb9) reverted NVIDIA#240 (1216aef): the const raw-pointer surface (as_ptr, program_id/num_programs, the cast_* and get_tensor_base helpers, unsafe on load_ptr_tko/store_ptr_tko), the compiler's const-pointer typing, the two GPU test files and the matching book and tutorial text. - NVIDIA#247 (5f5f4c5) reverted NVIDIA#225 (a2843e7): integer division and remainder serialization (rounding<zero> and inferred signedness on divi/remi) and its test. - NVIDIA#187 (35a9cc2) reverted NVIDIA#185 (cbf52c0): the flake.nix toolkit-assembly hardening and host-arch driver directory derivation. This re-applies all three verbatim as cherry-picks. The only overlapping file, cutile-book/guide/performance.md, merges cleanly with NVIDIA#239's own edits. A per-file scan of the last 60 merges finds no other reversal still missing at HEAD: NVIDIA#249's removal of the About page was deliberate, and the two setup-python flips in .github/workflows/pages.yml were re-applied by the later dependabot bump. Verified: cargo fmt, cargo build, and the restored GPU tests (const_pointers, program_id) plus integer_ops, memory_and_atomic_ops and optimization_hints pass on an RTX 5090 with CUDA 13.3. Signed-off-by: Melih Elibol <[email protected]> Co-authored-by: Gabriel Wu <[email protected]>
What
Adds
cargo oxide emit-ltoir <crate>, which builds a crate's device code to abinary LTOIR artifact in one step.
cargo oxide build --emit-nvvm-irstops at NVVM IR, leaving the caller to runlibNVVM separately to get linkable LTOIR.
emit-ltoirfolds both halves into asingle command for the Tile-to-SIMT interop workflow (#96), where cuda-oxide
is the SIMT participant: it builds the crate in NVVM IR mode, compiles the
emitted
<crate>.llwith libNVVM-gen-lto, and writes<crate>.ltoir.Details
--archis required (LTOIR is architecture-specific) and acceptssm_XX,compute_XX, or a bareXX.-o/--outputoverrides the default<crate>.ltoirpath.libnvvm-sysbinding and the established NVVM IR buildpath (
codegen_build(.., emit_nvvm_ir=true, ..)); rejects metadata-interopexamples (point it at a single SIMT device crate instead).
for
compute_100+ (Blackwell). Below that, libNVVM rejects the module with abare
parse expected typeand no hint at the cause (nvvmCompileProgram fails with "parse expected type" when libdevice calls (__nv_expf) trigger NVVM IR mode #98). On a libNVVMfailure below
compute_100,emit-ltoirappends a short explanation pointingat nvvmCompileProgram fails with "parse expected type" when libdevice calls (__nv_expf) trigger NVVM IR mode #98 and suggesting
sm_100+. The hint is gated on actual failure, so itdisappears automatically if the opaque-pointer floor ever moves (e.g. once
typed-pointer export lands).
Tests
nvvm_compute_arch) and thecapability parse (
compute_capability).compute_100floor in the cargo-oxide README.cargo test -p cargo-oxide(26 passed),cargo fmt --check, andcargo clippy -p cargo-oxideare all clean.Part of #96.