Repository navigation
Closed
Labels
bugSomething isn't workingintrinsicsDevice intrinsics and libdevice math mappingsllvm-exportTextual LLVM/NVVM IR exporter (llvm-export crate)maintainer-ownedneeds-implementation
Description
nvvmCompileProgram fails with "parse expected type" when libdevice calls trigger NVVM IR mode
Environment
| Component | Version |
|---|---|
| Rust | 1.96.0-nightly (55e86c996 2026-04-02) |
| LLVM | 22.1.2 |
| CUDA Toolkit | 13.2 (V13.2.78) |
| GPU Driver | 595.58.03 (Open Kernel Module) |
| GPU | NVIDIA GeForce RTX 3050 Ti Laptop GPU (sm_86) |
| OS | Linux 6.19.10-arch1-1 x86_64 |
| cuda-oxide commit | 396c76a (NVlabs/cuda-oxide) |
cargo oxide doctor
cargo-oxide environment check
==============================
Rust nightly toolchain... ✓ rustc 1.96.0-nightly (55e86c996 2026-04-02)
rust-toolchain.toml... ✓ present
Codegen backend... ✓ /home/moyi/.cargo/cuda-oxide/librustc_codegen_cuda.so
CUDA toolkit (nvcc)... ✓ Cuda compilation tools, release 13.2, V13.2.78
libNVVM (libnvvm.so)... ✓ libNVVM 2.0
nvJitLink (libnvJitLink.so)... ✓ nvJitLink 13.2
libdevice (libdevice.10.bc)... ✓ /opt/cuda/nvvm/libdevice/libdevice.10.bc
llc (LLVM)... ✓ LLVM version 22.1.2 (llc)
clang / libclang resource dir... ✓ /usr/lib/clang/22
cuda-gdb (optional)... ✓ exec: /opt/cuda/bin/cuda-gdb-minimal --version
✅ Environment looks good!
Minimal Reproduction
crates/rustc-codegen-cuda/examples/libdevice_ir_compat/
Cargo.toml:
[package]
name = "libdevice_ir_compat"
version = "0.1.0"
edition = "2024"
[workspace]
[dependencies]
cuda-device = { git = "https://github.com/NVlabs/cuda-oxide.git" }
cuda-host = { git = "https://github.com/NVlabs/cuda-oxide.git" }
cuda-core = { git = "https://github.com/NVlabs/cuda-oxide.git" }src/main.rs:
use cuda_core::{CudaContext, DeviceBuffer, LaunchConfig};
use cuda_device::{cuda_module, kernel, thread, DisjointSlice};
#[cuda_module]
mod kernels {
use super::*;
#[kernel]
pub fn swiglu_libdevice(x: &[f32], y: &[f32], mut out: DisjointSlice<f32>) {
let idx = thread::index_1d();
let i = idx.get();
if let Some(out_elem) = out.get_mut(idx) {
let xi = x[i];
let yi = y[i];
let sigmoid = 1.0f32 / (1.0f32 + (-xi).exp());
*out_elem = xi * sigmoid * yi;
}
}
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
let ctx = CudaContext::new(0)?;
let stream = ctx.default_stream();
let module = kernels::load(&ctx)?;
let host_x = vec![-2.0f32; 4];
let host_y = vec![1.0f32; 4];
let dev_x = DeviceBuffer::from_host(&stream, &host_x)?;
let dev_y = DeviceBuffer::from_host(&stream, &host_y)?;
let mut dev_out = DeviceBuffer::from_host(&stream, &vec![0.0f32; 4])?;
module.swiglu_libdevice(
&stream,
LaunchConfig::for_num_elems(4),
&dev_x,
&dev_y,
&mut dev_out,
)?;
let actual = dev_out.to_host_vec(&stream)?;
let expected: Vec<f32> = host_x
.iter()
.zip(host_y.iter())
.map(|(&x, &y)| {
let s = 1.0f32 / (1.0f32 + (-x).exp());
x * s * y
})
.collect();
for i in 0..4 {
assert!((actual[i] - expected[i]).abs() < 1e-5);
}
println!("PASS");
Ok(())
}expect output: PASS
actually:
Error: ModuleNotFound { name: "test" }
Failed with exit code: Some(1)
Workaround
Avoid Rust float-math intrinsics that trigger libdevice calls. Use only basic arithmetic and manual branching in GPU kernels:
// ❌
let sigmoid = 1.0 / (1.0 + (-xi).exp());
let abs_xi = xi.abs();
// ✅
let abs_xi = if xi >= 0.0 { xi } else { -xi };
let sigmoid = xi / (1.0 + abs_xi);I am relatively unfamiliar with CUDA and nvvm. Can someone tell me why I can't write it this way? Is it an issue with my environment, or am I not supposed to write it this way?
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingintrinsicsDevice intrinsics and libdevice math mappingsllvm-exportTextual LLVM/NVVM IR exporter (llvm-export crate)maintainer-ownedneeds-implementation
Activity
mohamedsamirx commentedon May 29, 2026
I reproduced this on current
mainusing the existingmanual_launch_libdeviceexample.The issue is not your CUDA installation. The current cuda-oxide NVVM IR path emits the modern LLVM 20 / opaque-pointer NVVM IR dialect. NVIDIA's NVVM IR docs say that this modern dialect is only supported for Blackwell and later targets (
compute_100+). Your GPU issm_86, so when libdevice math such asf32::exp()auto-switches cuda-oxide into NVVM IR mode, libNVVM ends up parsing opaque-pointer IR for a pre-Blackwell target and reports errors likeparse expected type.I opened a small fix locally that makes this fail earlier with a cuda-oxide diagnostic instead of the low-level libNVVM parser error. The longer-term feature needed for this to actually run on
sm_86is a typed-pointer / LLVM 7 NVVM IR export path for pre-Blackwell targets, or another libdevice lowering strategy for those targets.feat(cargo-oxide): add `emit-ltoir` to build a crate's LTOIR in one step
feat(cargo-oxide): add `emit-ltoir` to build a crate's LTOIR in one step
feat(cargo-oxide): add `emit-ltoir` to build a crate's LTOIR in one step
feat(cargo-oxide): add `emit-ltoir` to build a crate's LTOIR in one step
fix(nvvm): support legacy typed-pointer IR
Support typed NVVM IR for pre-Blackwell libNVVM targets (#101)