Skip to main content

Module preprocess

Module preprocess 

Source
Expand description

Source preprocessor for CUDA kernel launch syntax.

CUDA’s kernel<<<grid, block, smem, stream>>>(args) is not a standard C++ syntactic form. Tree-sitter’s C++ parser treats the triple-angle sequences as repeated comparison operators and fails to produce a meaningful AST for them.

Instead of writing a CUDA-specific grammar, we run a single targeted preprocessing pass that replaces every kernel launch with a synthetic ordinary function call to __decuda_launch(...). The call carries the kernel name and its launch configuration as ordinary arguments and is perfectly parseable by tree-sitter-cpp. The actual launch syntax can then be re-emitted per target backend.

Structs§

LaunchSite
MarkerOffset
PreprocessedSource
The result of running the preprocessor: a transformed source and a list of the original kernel launches that we captured.

Functions§

balanced_parens
Given that source[i] == '(', walk forward and return the byte position of the matching ) and the substring between them (exclusive of the parens).
preprocess
Run the kernel-launch preprocessor on raw CUDA source.
split_call_args_pub
Split a C/C++-style comma-separated argument list, respecting nested parens, brackets, and string literals.