Skip to content

Panic DriverError(500, "named symbol not found") when calling generic kernels from a separate crate #222

Closed

Description

@Karlo-der-dritte

Calling a generic kernel from a seperate crate will cause DriverError(500, "named symbol not found") when using trait bounds involving generic parameters in the kernel definition. This does not happen when the kernels are defined and called from the root crate or when using simpler trait bounds (like the ones in the official examples).

I can reproduce this issue with the code below. The usage of the generics there is a bit nonsensical, however it is just an example.

sub-crate/src/lib.rs

use cuda_device::{kernel, thread, DisjointSlice};
use cuda_host::cuda_module;
use cuda_core::{CudaContext, DeviceBuffer, LaunchConfig, DeviceCopy};

trait MyTrait: Copy + Send  + Default + core::ops::Add<Output = Self> + DeviceCopy {}
impl<T: Copy + Send + Default + core::ops::Add<Output = Self> + DeviceCopy> MyTrait for T {}

trait WrapperTrait<T>: Clone + Default + DeviceCopy + Send {
    fn inner_mut(&mut self) -> &mut T;
    fn inner(&self) -> &T;
}

#[derive(Default, Copy, Clone)]
pub struct WrapperType<T: Clone + MyTrait>(pub T);

impl<T: Clone + MyTrait> WrapperTrait<T> for WrapperType<T> {
    fn inner_mut(&mut self) -> &mut T {
        &mut self.0
    }

    fn inner(&self) -> &T {
        &self.0
    }
}

unsafe impl<T: Clone + MyTrait> DeviceCopy for WrapperType<T> {}

#[cuda_module]
pub mod kernels {
    use super::*;

    #[kernel]
    pub fn removing_this_causes_a_different_panic() {

    }

    #[kernel]
    pub fn vec_add_assign<I, A>(mut a: DisjointSlice<A>, b: &[A])
    where 
        I: MyTrait,
        A: WrapperTrait<I>,
    {
        let idx = thread::index_1d();
        let idx_raw = idx.get();
        if let Some(a_elem) = a.get_mut(idx) {
            *a_elem.inner_mut() = *a_elem.inner() + *b[idx_raw].inner();
        }
    }
}


pub fn run<I, A>() -> Result<(), Box<dyn std::error::Error>>
where 
    I: MyTrait,
    A: WrapperTrait<I>,
{
    let ctx = CudaContext::new(0)?;
    let stream = ctx.default_stream();
    let module = kernels::load(&ctx)?;

    const N: usize = 1024;
    let a_host = vec![A::default(); N];
    let b_host = vec![A::default(); N];

    let mut a_dev = DeviceBuffer::from_host(&stream, &a_host)?;
    let b_dev = DeviceBuffer::from_host(&stream, &b_host)?;
    
    module
        .vec_add_assign::<I, A>(
            &stream,
            LaunchConfig::for_num_elems(N as u32),
            &mut a_dev,
            &b_dev,
        )?;

    Ok(())
}

src/main.rs

use sub_crate::{WrapperType, run};

fn main() {
    run::<f32, WrapperType<f32>>().unwrap();
}

Project structure

├── Cargo.toml
├── src
│   └── main.rs   # calls sub_crate::run()
└── sub-crate
    ├── Cargo.toml
    └── src
        └── lib.rs   # defining and launching kernels

Environment

  • GPU: RTX 5070 ti
  • CUDA driver version: 595.45.04
  • 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 (or llc-22 --version):
    for some reason not available, even using the nix flake in this repo.

latest commit of cuda-oxide is used.

Activity

  1. added
    bug
    TBD
    on Jun 14, 2026
  2. added a commit that references this issue on Jun 18, 2026
  3. added a commit that references this issue on Jun 18, 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

    TBDbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions