Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Rust PTX Linker
LLVM NVPTX bitcode linker for Rust 🔥 without any external dependencies 🔥!
Purpose
It is definitely possible to create CUDA (PTX) kernels written with Rust even without the linker.
You could emit PTX code with --emit asm
flag.
Unfortunately, --emit asm
can't link couple modules into a single PTX.
Problems comes up when you need to write more or less complex kernels, which use functions from external crates.
From discussion another solution revealed: use of LLVM api.
The linker does the magic without any external dependency installed though. How could it be? you may ask. Thanks to rustc-llvm-proxy we avoid dependency on external LLVM lib and use rustc own one.
Issues
According to Rust NVPTX metabug it's quite realistic to solve part of bugs within this repo:
- Non-inlined functions can't be used cross crate - rust#38787
- No "undefined reference" error is raised when it should be - rust#38786
Approach
The trick is to build a kernels crate as "dylib" and let the linker handle "linking".
For that, you need a special target definition json and to specify crate type in Cargo.toml
:
[]
= ["dylib"]
Convinient usage
The easiest would be to rely on ptx-builder to handle device crate building.
It will run xargo
(which will invoke the linker after) and set all needed environment variables for comfortable development flow.
You can also refer to a tutorial about using CUDA kernels written in Rust.
Advanced usage
Alternatively, you can use the linker solo. First you need to install tools:
$ cargo install ptx-linker
$ cargo install xargo
Then, create a nvptx64-nvidia-cuda
definition:
$ cd /path/to/kernels/crate
$ ptx-linker --print-target-json nvptx64-nvidia-cuda > nvptx64-nvidia-cuda.json
And finally, run a build with proper environment vars:
$ export RUST_TARGET_PATH="/path/to/kernels/crate"
$ xargo build --target nvptx64-nvidia-cuda --release
Eventually the linker will be used to produce a PTX assembly, that can be usually found at target/nvptx64-nvidia-cuda/release/KERNELS_CRATE_NAME.ptx
.
Target definition
The common definition for nvptx64-nvidia-cuda
looks like:
Especially, the most important for the linker are the properties:
"linker"
- the linker executable name inPATH
."linker-flavor"
- currently the linker supports parsing ofld
-style arguments."linker-is-gnu"
- needed to betrue
for Rust to pass optimisation flags."dll-suffix"
- specifies a correct assembly file extension."dynamic-linking"
- allows Rust to create dylib for the target."obj-is-bitcode"
- store bitcode instead of object files, it's significantly easier to work with them.