#3911·graphify

[Bug]: .cu/.cuh: CUDA kernel files trip the syntax-error warning on file-scope macro invocations, and macro-defined kernel bodies are never extracted

Author: vitichenkoCreated Sep 28, 2026Updated Sep 28, 2026

Symptom

.cu / .cuh sit in the native family next to .cpp/.metal and are extracted with extract_cpp (extract.py: ".cu": "native", ".cuh": "native" in the extension-family table, ".cu": extract_cpp, ".cuh": extract_cpp in the extension→extractor table), so the standard shape of a hand-written CUDA kernel file — file-scope invocations of a macro, with the kernel body living inside the macro definition — lands in the syntax-error bucket:

  warning: 10 file(s) had syntax errors and may be partially extracted: crates/candle-kernels/src/affine.cu (first error at line 32, no symbols extracted), crates/candle-kernels/src/binary.cu (first error at line 1, no symbols extracted), crates/candle-kernels/src/cast.cu (first error at line 5, 5 symbol(s) extracted), crates/candle-kernels/src/conv.cu (first error at line 6, 12 symbol(s) extracted), crates/candle-kernels/src/fill.cu (first error at line 5, 14 symbol(s) extracted) (+5 more)

What the trigger actually is (reduced)

A file-scope macro invocation is not a valid C++ statement, and that is the whole trigger:

$ cat a_invoke_only.cu
OP(float, k_f32)
$ cat b_macro_def.cu
#define OP(T, NAME) extern "C" __global__ void NAME(const T* in) {}
OP(float, k_f32)
$ cat c_arch_guard.cu
#define OP(T, NAME) extern "C" __global__ void NAME(const T* in) {}
#if __CUDA_ARCH__ >= 800
OP(float, k_f32)
#endif
$ cat d_launch.cu
void run(float* d) { my_kernel<<<1, 256>>>(d); }

$ graphify update .
  warning: 3 file(s) had syntax errors and may be partially extracted: a_invoke_only.cu (first error at line 1, no symbols extracted), b_macro_def.cu (first error at line 2, no symbols extracted), c_arch_guard.cu (first error at line 3, no symbols extracted)
[graphify watch] Rebuilt: 5 nodes, 1 edges, 4 communities
  • d_launch.cu — <<<1, 256>>> launch syntax plus a __global__-kernel call — parses cleanly and yields run(). The launch syntax is not the trigger.
  • c_arch_guard.cu — the #if __CUDA_ARCH__ >= 800 guard is not the trigger either; the reported line is the invocation.

Also reduced separately: .cuh files that contain only #defines yield their file node and nothing else.

Impact, measured on a real repo

tessella/crates/candle-kernels/src — 14 files (11 .cu, 3 .cuh), 0.9.67: they contribute 273 nodes and 812 links, so the warning overstates the damage — 10 of the 14 do yield symbols:

quantized.cu 186   cuda_utils.cuh 24   reduce.cu 13   conv.cu 11   fill.cu 10
unary.cu 8         compatibility.cuh 6 indexing.cu 5  cast.cu 3    sort.cu 3

(The 259 symbol nodes above come from those 10 files; the remaining 4 files contribute their file node and nothing else, so they are the only real losses — and the second item is the one that matters.)

  • affine.cu (7 file-scope invocations), binary.cu (84), ternary.cu (21) — the invocation is the only content, so 112 kernel names exist in the sources and none of them is a node.
  • binary_op_macros.cuh — the file that defines BINARY_OP / BINARY_OP_OUT, i.e. where a large part of the kernels' bodies actually live. No C++ AST walk can see a body inside a #define, so the graph cannot answer "what does badd_bf16 call" or "which kernel lists exist".

So a repo asking GPU-path questions reads the syntax-error line as "these files are missing", when the truth is "these files are present, 10 of them are extracted, and the kernel bodies defined through macros are outside the AST".

Ask

  1. Do not report the CUDA macro-invocation idiom as a syntax error: either treat .cu/.cuh as a language with its own handling (at minimum stop counting file-scope macro invocations as parse failures), or put the truth in the warning ("no symbols extracted; the file may define its kernels through macros").
  2. Consider extracting file-scope macro invocations as symbol evidence — BINARY_OP(__nv_bfloat16, badd_bf16, x + y) names a kernel that exists in the compiled artifact, and for many of these names it is the only place the name appears.
  3. Minor and unreduced: binary.cu reports first error at line 1 while its first invocation is at line 5 (our other files report the correct line — i_nospace_include.cu 4, j_many_invokes.cu 5, k_cmp_arg.cu 2). Flagging it in case it points at something in error recovery.