You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
device codegen fails if you iterate over an array.iter() #138
The for x in a construct causes codegen to fail. here is an example kernel:
use cuda_device::cuda_module;
#[cuda_module]
mod kernels {
use cuda_device::{DisjointSlice, kernel, thread};
#[kernel]
pub fn asplode(mut dst: DisjointSlice<u32>) {
let idx = thread::index_1d();
let mut sum = 0;
let a: [u32; 4] = [1, 2, 3, 4];
for x in a {
sum += x;
}
/* for i in 0..4 {
sum += a[i];
}*/
}
}
The error this produces is
error: [rustc_codegen_cuda] Device codegen failed: PTX generation failed: Translation failed: asplode: [name: "Span { id: 23, repr: "codegen-explosion-5/src/main.rs:15:9: 15:10" }", loc: (?)] Compilation error: invalid input program.
Unsupported construct: drop of `RigidTy(Adt(AdtDef(DefId { id: 3, name: "std::array::IntoIter" }), GenericArgs([Type(Ty { id: 1, kind: RigidTy(Uint(U32)) }), Const(TyConst { kind: Value(Ty { id: 5, kind: RigidTy(Uint(Usize)) }, Allocation { bytes: [Some(4), Some(0), Some(0), Some(0), Some(0), Some(0), Some(0), Some(0)], provenance: ProvenanceMap { ptrs: [] }, align: 8, mutability: Mut }), id: TyConstId(0, ThreadLocalIndex) })])))` is not supported on the device; cuda-oxide does not yet emit device-side `drop_in_place` calls. Restructure the kernel to use only `Copy` types, or wrap the value in `core::mem::ManuallyDrop` to suppress drop glue.
It is possible to work around this problem by using for i in 0..4 and indexing the array instead. This code is slightly less idiomatic and can expend significant porting effort. I do not know if it would be easier to solve the problem, or adjust the error message to guide the programmer to adjust the troublesome source lines until the problem can be fully solved.
The for i in 0..a.len() also triggers the warning for clippy::needless_range_loop so I am adding #![allow(clippy::needless_range_loop)] to the module for now.
Activity
mutantbob commentedon Jun 8, 2026
The
for i in 0..a.len()also triggers the warning forclippy::needless_range_loopso I am adding#![allow(clippy::needless_range_loop)]to the module for now.fix(mir-importer): compile `for x in arr` by accepting no-op drop glu…
Merge origin/main into fix/issue138-noop-drop-glue-v2
fix: skip no-op drop glue for types with trivially droppable fields
fix: skip no-op drop glue for types with trivially droppable fields
fix: skip no-op drop glue for types with trivially droppable fields
fix: skip no-op drop glue for types with trivially droppable fields
Merge branch 'main' into feature/partition-index-schedules (NVIDIA#138)