Skip to content

Support for kernels with keyword arguments #2718

Open
@gmgunter

Description

@gmgunter

Hi,

Thanks for this nice package. I'm just getting started but ran into an issue when trying to GPU-ize an existing function that takes keyword arguments. Is this possible? I'm getting a syntax error when passing such a function as an argument to the @cuda macro (MWE below).

This simple kernel works fine when I pass a positional argument:

julia> using CUDA: @cuda, @cushow

julia> function kernel1(foo::Integer)
           @cushow foo
           return
       end
kernel1 (generic function with 1 method)

julia> @cuda kernel1(1)
foo = 1
CUDA.HostKernel for kernel1(Int64)

But I get a syntax error when I pass a keyword argument instead:

julia> function kernel2(; foo::Integer)
           @cushow foo
           return
       end
kernel2 (generic function with 1 method)

julia> @cuda kernel2(foo=1)
ERROR: syntax: invalid syntax foo = 1
Stacktrace:
 [1] top-level scope
   @ REPL[5]:1

Version info

julia> versioninfo()
Julia Version 1.11.4
Commit 8561cc3d68d (2025-03-10 11:36 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 256 × AMD EPYC 7713 64-Core Processor
  WORD_SIZE: 64
  LLVM: libLLVM-16.0.6 (ORCJIT, znver3)
Threads: 1 default, 0 interactive, 1 GC (on 256 virtual cores)
julia> CUDA.versioninfo()
CUDA runtime 12.4, local installation
CUDA driver 12.5
NVIDIA driver 555.42.6

CUDA libraries:
- CUBLAS: 12.4.2
- CURAND: 10.3.5
- CUFFT: 11.2.0
- CUSOLVER: 11.6.0
- CUSPARSE: 12.3.0
- CUPTI: 2024.1.0 (API 22.0.0)
- NVML: 12.0.0+555.42.6

Julia packages:
- CUDA: 5.7.0
- CUDA_Driver_jll: 0.12.0+0
- CUDA_Runtime_jll: 0.16.0+0
- CUDA_Runtime_Discovery: 0.3.5

Toolchain:
- Julia: 1.11.4
- LLVM: 16.0.6

Preferences:
- CUDA_Runtime_jll.local: true

1 device:
  0: NVIDIA A800 40GB Active (sm_80, 38.224 GiB / 40.000 GiB available)

Metadata

Metadata

Assignees

No one assigned

    Labels

    cuda kernelsStuff about writing CUDA kernels.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions