Skip to main content

singe_cuda_macros/
lib.rs

1//! Procedural macros for compiling CUDA source and generating typed Singe kernel launch modules.
2
3mod cuda_module;
4
5use proc_macro::TokenStream;
6
7/// Compiles CUDA source with `nvcc` and generates a typed kernel-launch module.
8///
9/// The macro expects a module declaration containing a CUDA source file, exported
10/// kernel names, optional header files, and optional compiler arguments:
11///
12/// ```ignore
13/// cuda_module! {
14///     pub mod kernels {
15///         source: "kernels/add.cu",
16///         exports: [add_kernel],
17///         headers: ["kernels/common.cuh"],
18///         compile: {
19///             nvcc_args: ["--std=c++17"],
20///             nvrtc_args: ["--std=c++17"],
21///         },
22///     }
23/// }
24/// ```
25///
26/// Expansion runs `nvcc`, using the surrounding CUDA environment including
27/// `CUDA_CCBIN` when set, parses the resulting PTX with `singe-ptx`, and emits a
28/// Rust module with a `create` constructor plus typed wrappers for exported
29/// kernels. Syntax errors, missing files, `nvcc` failures, unsupported PTX, and
30/// exports mismatches are reported as compile-time errors.
31#[proc_macro]
32pub fn cuda_module(input: TokenStream) -> TokenStream {
33    match cuda_module::expand_module(input.into()) {
34        Ok(output) => output.into(),
35        Err(err) => err.to_compile_error().into(),
36    }
37}