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§
- Launch
Site - Marker
Offset - Preprocessed
Source - 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.