Repository navigation
Closed
Description
Description
Using DisjointSlice::from_raw_parts gives a device codgen error. This could be related to using the DisjointSlice from a separate #[device] method, as this was required for my repro.
Minimal reproducer
use cuda_core::{CudaContext, DeviceBuffer, LaunchConfig};
use cuda_device::{DisjointSlice, device, kernel, thread};
use cuda_host::cuda_module;
#[cuda_module]
mod kernels {
use super::*;
#[device]
fn increment_device<'a>(vector: &mut DisjointSlice<'a, f32>) {
if let Some(value) = vector.get_mut(thread::index_1d()) {
*value += 1.0;
}
}
#[kernel]
pub fn disjoint_from_raw_parts_repro(ptr: *mut f32, len: usize) {
let mut view = unsafe { DisjointSlice::from_raw_parts(ptr, len) };
increment_device(&mut view);
}
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
let context = CudaContext::new(0)?;
let stream = context.default_stream();
let output = DeviceBuffer::<f32>::zeroed(&stream, 1)?;
let module = kernels::load(&context)?;
unsafe {
module.disjoint_from_raw_parts_repro(
&stream,
LaunchConfig::for_num_elems(1),
output.cu_deviceptr() as *mut f32,
output.len(),
)?;
}
Ok(())
}Expected behavior
compiles ok
Actual behavior
error: [rustc_codegen_cuda] Device codegen failed: PTX generation failed: Translation failed: disjoint_from_raw_parts_repro: ["/home/mrobins/.cargo/git/checkouts/cuda-oxide-6d394bb007f5e114/e28248c/crates/cuda-device/src/disjoint.rs": line: 179, column: 9] Compilation error: invalid input program.
Unsupported construct: Scalar-lowered ADT expected exactly one runtime field, found 0
Environment
- GPU: A40
- CUDA driver version: 580.173.02
rustc --version --verbose:
rustc 1.96.0-nightly (55e86c996 2026-04-02)
binary: rustc
commit-hash: 55e86c996809902e8bbad512cfb4d2c18be446d9
commit-date: 2026-04-02
host: x86_64-unknown-linux-gnu
release: 1.96.0-nightly
LLVM version: 22.1.2
llc --version(orllc-22 --version):
❯ llc-21 --version
Ubuntu LLVM version 21.1.8
Optimized build.
Default target: x86_64-pc-linux-gnu
Host CPU: znver3
Registered Targets:
aarch64 - AArch64 (little endian)
aarch64_32 - AArch64 (little endian ILP32)
aarch64_be - AArch64 (big endian)
amdgcn - AMD GCN GPUs
arm - ARM
arm64 - ARM64 (little endian)
arm64_32 - ARM64 (little endian ILP32)
armeb - ARM (big endian)
avr - Atmel AVR Microcontroller
bpf - BPF (host endian)
bpfeb - BPF (big endian)
bpfel - BPF (little endian)
hexagon - Hexagon
lanai - Lanai
loongarch32 - 32-bit LoongArch
loongarch64 - 64-bit LoongArch
m68k - Motorola 68000 family
mips - MIPS (32-bit big endian)
mips64 - MIPS (64-bit big endian)
mips64el - MIPS (64-bit little endian)
mipsel - MIPS (32-bit little endian)
msp430 - MSP430 [experimental]
nvptx - NVIDIA PTX 32-bit
nvptx64 - NVIDIA PTX 64-bit
ppc32 - PowerPC 32
ppc32le - PowerPC 32 LE
ppc64 - PowerPC 64
ppc64le - PowerPC 64 LE
r600 - AMD GPUs HD2XXX-HD6XXX
riscv32 - 32-bit RISC-V
riscv64 - 64-bit RISC-V
sparc - Sparc
sparcel - Sparc LE
sparcv9 - Sparc V9
spirv - SPIR-V Logical
spirv32 - SPIR-V 32-bit
spirv64 - SPIR-V 64-bit
systemz - SystemZ
thumb - Thumb
thumbeb - Thumb (big endian)
ve - VE
wasm32 - WebAssembly 32-bit
wasm64 - WebAssembly 64-bit
x86 - 32-bit X86: Pentium-Pro and above
x86-64 - 64-bit X86: EM64T and AMD64
xcore - XCore
xtensa - Xtensa 32
Activity
Construct a disjoint slice when a kernel builds one (NVIDIA#670)