Skip to content

a kernel which accepts a reference to an application struct seems to cause illegal memory access #29

Closed

Description

@mutantbob

I blithely attempted to pass a reference to a custom structure into a #[kernel] function.

#[kernel]
pub fn julia(mut dst: DisjointSlice<u32>, grid: &JuliaGrid) {

I can build and run the application, but it fails at run-time with
DriverError(700, "an illegal memory access was encountered")

Also, I can change the cuda_launch! from

args: [ slice_mut(c_dev),&grid] //matches

to

args: [ slice_mut(c_dev),] // argument mismatch

and the app still builds, but fails at runtime with

Failed with exit code: None

Arguments which can not effectively be passed to a kernel should ideally cause a compile-time error.

Likewise, if the args passed to cuda_launch! do not match the arguments declared in the kernel, it should ideally cause a compile-time error.

One solution to explore is for #[kernel] to generate a Rust wrapper function that can be called directly instead of cuda_launch!

Activity

  1. added
    bug
    codegen
    on Jun 10, 2026
  2. nihalpasham commented on Jun 12, 2026

    @nihalpasham
    Collaborator

    Closing as fixed on main. Both reported failure modes are now compile-time errors instead of runtime error 700:

    • under #[cuda_module], a grid: &JuliaGrid param is rejected with an actionable diagnostic (slice references, DisjointSlice, raw pointers, or by-value KernelScalar are the supported shapes), and argument-count mismatches on the typed path are ordinary errors
    • the typed-wrapper approach you suggested is what #[cuda_module] generates; for this kernel the migration is grid: JuliaGrid by value (Copy struct, lowered to a byval kernel param) or a device pointer
    • feat(cuda-macros): make cuda_launch\! a caller-unsafe API #171 made the remaining bare cuda_launch! niche caller-unsafe, so the originally reported code no longer compiles silently

    Transparent &T struct params on the typed path (marshal by value, reconstruct the reference device-side, mirroring slice scalarization) could be a separate feature request.

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