feat(godbolt): add Compiler Explorer integration for rust-cuda kernels#394
feat(godbolt): add Compiler Explorer integration for rust-cuda kernels#394g-ampo wants to merge 4 commits into
Conversation
LegNeato
left a comment
There was a problem hiding this comment.
Thanks for working on this! I am not super familiar with compiler explorer, so apologies if my review questions are dumb.
|
Thinking about this some more, instead of shell perhaps it would be better to write this tool in rust (a normal binary that can compile with any version of rust). Then we can add tests and such to our CI to make sure we don't inadvertently break the integration. As it is I am worried that we land something and don't know it breaks until we go to update the version in compiler explorer. Thoughts? |
|
Yes would make sense. The main thing the Rust binary would still do is shell out to cargo build under the hood, so the breakage surface is similar to shell (for the glue parts)... but if it imports cuda_std or hooks into the build logic directly, that gives compile-time detection when APIs change, which shell can't do :) Would be (very) happy to rewrite it in Rust. |
|
Up to you! |
| /// Rustflags applied on every build. These mirror the flags `cuda_builder` | ||
| /// passes when invoking rustc directly, so PTX produced through the wrapper | ||
| /// matches what a normal rust-cuda build would emit. | ||
| const STATIC_RUSTFLAGS: [&str; 6] = [ |
There was a problem hiding this comment.
Can the wrapper just use cuda_builder directly so these can't get out of sync? It looks like you can set DEP_RUSTC_CODEGEN_NVVM_OUT_DIR or put it in the proper place expected by
rust-cuda/crates/cuda_builder/src/lib.rs
Line 494 in 103a8d5
There was a problem hiding this comment.
There is some drift risk but unfortunatelly a direct cuda_builder dependency doesn't work here:
- cuda_builder -> nvvm -> cust_raw, and cust_raw (links = "cuda") requires a CUDA SDK at build time. The wrapper would no longer build without a full toolchain which is the thing the Rust rewrite was meant to avoid...
- CudaBuilder::build() writes cargo: lines to stdout (it's a build.rs API); the wrapper needs stdout to be PTX only for CE. The flag logic in invoke_rustc is private anyway. DEP_RUSTC_CODEGEN_NVVM_OUT_DIR only changes where the backend .so is found, not either blocker.
here the real fix would be to extract the flag-building from invoke_rustc into a small dep-free crate that both cuda_builder and the wrapper call so there would be one source of truth. If thats fine with you I would just do this here in this PR.
Summary
Add Compiler Explorer integration so users can compile rust-cuda kernels to PTX in the browser.
Closes #177, partially addresses #353.
Building on the discussion between @LegNeato and @Forsworns .This takes the "wrapper script that replicates cuda_builder's rustc invocation" route that @LegNeato suggested (to avoiding the need for cargo on the CE side)
Changes
contrib/godbolt/rust-cuda-wrapper.sh- wrapper that creates a temp Cargo project with the same rustflags ascuda_builder::invoke_rustc(), builds to PTX, extracts output from cargo JSONcontrib/godbolt/install.sh- installs pinned nightly, buildsrustc_codegen_nvvm, lays out a self-contained prefixcontrib/godbolt/rust-cuda.defaults.properties- CE language/compiler configcontrib/godbolt/test-kernel.rs- sample kernels for smoke-testingcontrib/godbolt/README.md- local testing and upstream submission stepsTesting
cargo checkpassescargo clippy --workspacepasses