TL;DR
Translating old, sequential C code into high-speed GPU (CUDA) code is notoriously hard because simply reading source code doesn’t tell you how variables actually move through memory at runtime. STParOpt bridges this gap by combining static code graphs with actual runtime memory-access "footprints," using predictive uncertainty to decide which view to trust when they disagree. By turning these insights into clear optimization blueprints for an LLM, it generates CUDA code that is not just functionally correct, but dramatically faster.
What Problem Does This Paper Address?
Everywhere in science and engineering, massive amounts of legacy C code need to be ported to GPUs. Doing this manually requires deep expertise in parallel algorithms and GPU memory hierarchies, making automated C-to-CUDA migration a holy grail for high-performance computing.
The roadblock isn’t syntax—it’s a semantic gap. Imagine looking at a loop containing an indirect write like B[idx[i]] = A[i] * scale. Can you run all iterations simultaneously on a GPU? Just reading the text (static analysis), a traditional compiler can’t tell if two values in idx point to the exact same spot in B, which would cause a race condition. Playing it safe, static compilers give up on pointer-heavy or irregular loops. Meanwhile, Large Language Models (LLMs) try to guess directly from the text without real execution evidence, often writing buggy code or missing crucial GPU optimizations (like memory coalescing, where threads read adjacent memory slots simultaneously). To migrate code reliably, an automated system needs to watch the code actually run alongside reading its structure.
Methods
The authors frame migration as a two-stage pipeline—semantic inference followed by constrained generation—illustrated in their system overview:
Here is how the novel pieces fit together alongside standard deep learning blocks:
- Spatio-Temporal Execution-Aware Representation (STER): First, the code is parsed (without needing compilation) into a Multi-dimensional Program Graph (MPG) capturing syntax, control flow, and data hazards, encoded via a Relational Graph Convolutional Network (RGCN). Next, using GDB instrumentation across $K=3$ representative input patterns, a Stride Pattern Encoder (SPE) records memory-address jumps ("strides") over 50 loop iterations, encoding them with a BiLSTM. Cross-attention then injects these runtime stride patterns directly into the static variable nodes.
- Entropy-Guided Fusion: Static structure offers global rules; runtime traces offer concrete but partial examples. When should the model trust which? STParOpt measures the Shannon entropy (uncertainty) of the static branch's prediction. When static code looks ambiguous (high entropy, like pointer chasing), a learned gate automatically shifts weight toward the dynamic runtime representation.
- Hierarchical Decision & Constrained LLM Generation: The fused representation first predicts loop parallelizability (
independent,reduction, orsequential). Using a stop-gradient trick to prevent training tasks from interfering with one another, a secondary head predicts five binary GPU optimizations: memory coalescing, warp reduction, tiling, shared memory, and streaming. Finally, instead of asking an LLM to figure out parallelization from scratch, these predictions are formatted into strict natural-language constraints that guide a standard LLM to write the CUDA code.
Datasets
- OMP_Serial Dataset (Loop Detection & Optimization): 32,570 real-world C/OpenMP loops split 8:1:1. To enable dynamic profiling, the authors newly augmented 4,000 training, 500 dev, and all 3,257 test samples with minimal executable harnesses, $K=3$ input configurations, and verified labels for five CUDA optimization strategies.
- Polybench & Rodinia + Sequential Suite (CUDA Generation): 79 benchmark programs combining 30 regular/affine loops (Polybench), 19 irregular HPC kernels (Rodinia), and 30 non-parallelizable loops from the test split to verify the system knows when not to parallelize.
Key Insights and Ideas
- Uncertainty is the secret to sensor fusion: When static and dynamic signals conflict (occurring in ~25.7% of test loops), static entropy spikes from 0.314 to 0.872. Standalone static or dynamic branches only hit ~72% and ~69% accuracy on these tricky disagreements, whereas entropy-guided fusion resolves them at 87.41% accuracy.
- Decoupling reasoning from coding unlocks LLMs: LLMs are great code generators but shaky dependency analyzers. Across every tested LLM (Qwen, GPT-4.1, Claude), running explicit parallelism detection before generation boosted code correctness by 7.6 to 8.9 percentage points.
- Memory access order matters, not just locations: In ablations, randomly shuffling the temporal sequence of memory strides dropped optimization Macro-F1 by nearly 5 percentage points—proving that how addresses step through time is vital for spotting GPU optimization opportunities.
Key Results
STParOpt outperforms traditional polyhedral compilers (Pluto, PPCG), graph neural networks, and frontier LLMs across both stages of the pipeline.
- Detection & Strategy Inference: STParOpt achieves 96.63% parallel detection accuracy and 84.05% Macro-F1 on optimization strategy prediction, beating the strongest LLM baselines (such as Claude 4.5 Sonnet given both static and dynamic text prompts) by over 2.1 pp in detection and 7.45 pp in optimization F1. It shines brightest on non-affine and pointer-heavy loops where traditional compilers collapse below 0.39 F1.
- End-to-End CUDA Generation: Across the 79 generation benchmarks, STParOpt reaches 86.1% functional correctness (surpassing the best LLM baseline at 74.7%) and correctly leaves 26 out of 30 sequential loops untouched as C code.
- Massive Speedups from Optimization Constraints: As shown in Table 2 above, stripping away STParOpt's five optimization directives (
STParOpt-no-opt) barely changes compilation rates, but causes geometric-mean GPU speedup over serial C code to plummet from 15.50$\times$ down to 5.42$\times$. Knowing that a loop can run in parallel gets you correct code; knowing how memory moves gets you actual GPU speed.
Limitations and Future Work
- Finite traces aren't mathematical proofs: Observing zero memory collisions over 50 iterations across 3 inputs strongly suggests independence, but cannot formally guarantee safety for all unseen inputs.
- Single-loop scope & harness overhead: The evaluation targets isolated loops and single kernels rather than sprawling, multi-file repositories, and requires executable harnesses to gather GDB traces.
- Fixed optimization vocabulary: Advanced techniques like kernel fusion, complex memory-hierarchy tuning, and multi-GPU scheduling fall outside the current five strategies. Future work aims to tackle repository-level migration, inter-procedural analysis, and additional targets like OpenMP and SYCL.
Summary updated