Skip to content

inscrutable compile error caused by using Vec in a kernel #108

Closed

Description

@mutantbob
use cuda_device::cuda_module;

#[cuda_module]
mod kernels {
    use cuda_device::{DisjointSlice, kernel, thread};

    #[kernel]
    pub fn asplode(mut dst: DisjointSlice<usize>) {
        let x = vec![0u8];
        let idx = thread::index_1d();
        if let Some(a) = dst.get_mut(idx) {
            *a = 42;
        }
    }
}

fn main() {
    println!("Hello, world!");
}

fails to compile. The error I get is

error: [rustc_codegen_cuda] Device codegen failed: PTX generation failed: Translation failed: asplode: [name: "Span { id: 1, repr: "/home/thoth/.rustup/toolchains/nightly-2026-04-03-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/boxed.rs:317:33: 317:83" }", loc: (?)] Compilation error: invalid input program.
       Unsupported construct: Struct constant field 1 has unsupported type. Consider using inline construction instead of const.
       Error backtrace:
          0: mir_importer::translator::rvalue::translate_struct_constant
                    at /home/thoth/vendor/cuda-oxide/crates/mir-importer/src/translator/rvalue.rs:4426:24
          1: mir_importer::translator::rvalue::translate_operand
                    at /home/thoth/vendor/cuda-oxide/crates/mir-importer/src/translator/rvalue.rs:1842:17
          2: mir_importer::translator::terminator::helpers::emit_function_call
                    at /home/thoth/vendor/cuda-oxide/crates/mir-importer/src/translator/terminator/helpers.rs:145:13
          3: mir_importer::translator::terminator::translate_call
                    at /home/thoth/vendor/cuda-oxide/crates/mir-importer/src/translator/terminator/mod.rs:1063:5
          4: mir_importer::translator::terminator::translate_terminator
                    at /home/thoth/vendor/cuda-oxide/crates/mir-importer/src/translator/terminator/mod.rs:142:14
          5: mir_importer::translator::block::translate_block
                    at /home/thoth/vendor/cuda-oxide/crates/mir-importer/src/translator/block.rs:65:24
          6: mir_importer::translator::body::translate_body
                    at /home/thoth/vendor/cuda-oxide/crates/mir-importer/src/translator/body.rs:594:9
          7: mir_importer::pipeline::run_pipeline
                    at /home/thoth/vendor/cuda-oxide/crates/mir-importer/src/pipeline.rs:253:27
          8: rustc_codegen_cuda::device_codegen::generate_device_code::{closure#2}
                    at /home/thoth/vendor/cuda-oxide/crates/rustc-codegen-cuda/src/device_codegen.rs:465:9
          9: rustc_public::rustc_internal::run::<rustc_codegen_cuda::device_codegen::generate_device_code::{closure#2}, core::result::Result<mir_importer::pipeline::CompilationResult, mir_importer::pipeline::PipelineError>>::{closure#0}
                    at /home/thoth/.rustup/toolchains/nightly-2026-04-03-x86_64-unknown-linux-gnu/lib/rustlib/rustc-src/rust/compiler/rustc_public/src/rustc_internal/mod.rs:79:60
         10: rustc_public::compiler_interface::run::<rustc_public::rustc_internal::run<rustc_codegen_cuda::device_codegen::generate_device_code::{closure#2}, core::result::Result<mir_importer::pipeline::CompilationResult, mir_importer::pipeline::PipelineError>>::{closure#0}, core::result::Result<mir_importer::pipeline::CompilationResult, mir_importer::pipeline::PipelineError>>::{closure#0}
                    at /home/thoth/.rustup/toolchains/nightly-2026-04-03-x86_64-unknown-linux-gnu/lib/rustlib/rustc-src/rust/compiler/rustc_public/src/compiler_interface.rs:876:40
         11: <scoped_tls::ScopedKey<core::cell::Cell<*const ()>>>::set::<rustc_public::compiler_interface::run<rustc_public::rustc_internal::run<rustc_codegen_cuda::device_codegen::generate_device_code::{closure#2}, core::result::Result<mir_importer::pipeline::CompilationResult, mir_importer::pipeline::PipelineError>>::{closure#0}, core::result::Result<mir_importer::pipeline::CompilationResult, mir_importer::pipeline::PipelineError>>::{closure#0}, core::result::Result<core::result::Result<mir_importer::pipeline::CompilationResult, mir_importer::pipeline::PipelineError>, rustc_public::error::Error>>
                    at /rust/deps/scoped-tls-1.0.1/src/lib.rs:137:9
         12: rustc_public::compiler_interface::run::<rustc_public::rustc_internal::run<rustc_codegen_cuda::device_codegen::generate_device_code::{closure#2}, core::result::Result<mir_importer::pipeline::CompilationResult, mir_importer::pipeline::PipelineError>>::{closure#0}, core::result::Result<mir_importer::pipeline::CompilationResult, mir_importer::pipeline::PipelineError>>
                    at /home/thoth/.rustup/toolchains/nightly-2026-04-03-x86_64-unknown-linux-gnu/lib/rustlib/rustc-src/rust/compiler/rustc_public/src/compiler_interface.rs:876:13
         13: rustc_public::rustc_internal::run::<rustc_codegen_cuda::device_codegen::generate_device_code::{closure#2}, core::result::Result<mir_importer::pipeline::CompilationResult, mir_importer::pipeline::PipelineError>>
                    at /home/thoth/.rustup/toolchains/nightly-2026-04-03-x86_64-unknown-linux-gnu/lib/rustlib/rustc-src/rust/compiler/rustc_public/src/rustc_internal/mod.rs:79:5
         14: rustc_codegen_cuda::device_codegen::generate_device_code
                    at /home/thoth/vendor/cuda-oxide/crates/rustc-codegen-cuda/src/device_codegen.rs:413:18
         15: <rustc_codegen_cuda::CudaCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate
                    at /home/thoth/vendor/cuda-oxide/crates/rustc-codegen-cuda/src/lib.rs:531:23
         16: <rustc_interface::queries::Linker>::codegen_and_build_linker
         17: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
         18: std::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
         19: <std::thread::lifecycle::spawn_unchecked<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
         20: <std::sys::thread::unix::Thread>::new::thread_start
         21: <unknown>
         22: <unknown>

I also played with code like let x = Box::new(0.4); and it exploded with a different error.

My assumption is that cuda oxide does not yet support dynamic memory allocation (and maybe never will).

It would be helpful if the error message emitted by the compile process were more informative because it can take a while to find where in a codebase the problem is actually coming from. The error that started my investigation did not include any source file or line number. I include a fragment below:

error: [rustc_codegen_cuda] Device codegen failed: PTX generation failed: Translation failed: julia: Compilation error: invalid input program.
       Unsupported construct: Type translation not yet implemented for: RigidTy(Pat(Ty { id: 1, kind: RigidTy(Uint(Usize)) }, Range { start: Some(TyConst { kind: Value(Ty { id: 1, kind: RigidTy(Uint(Usize)) }, Allocation { bytes: [Some(0), 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) }), end: Some(TyConst { kind: Value(Ty { id: 1, kind: RigidTy(Uint(Usize)) }, Allocation { bytes: [Some(255), Some(255), Some(255), Some(255), Some(255), Some(255), Some(255), Some(127)], provenance: ProvenanceMap { ptrs: [] }, align: 8, mutability: Mut }), id: TyConstId(1, ThreadLocalIndex) }), include_end: true }))

Activity

  1. added
    bug
    codegen
    on Jun 6, 2026
  2. added a commit that references this issue on Jun 11, 2026
    4ffce63
  3. added a commit that references this issue on Sep 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcodegen

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions