Can GPU Kernel Optimization Experience Transfer Across Languages?

    This article examines whether optimization experience accumulated during GPU kernel generation can be reused across different programming languages. It explains why conventional single-run evaluation cannot measure the value of accumulated experience, and how a controlled design that holds the problem, hardware, and scoring criteria fixed while swapping only the implementation language isolates transferable gains from mere memory recall. The article covers the evaluation setup, including task selection, dual-language versions, three-dimensional scoring, and control groups, then analyzes which types of experience transfer and which cause negative transfer. It closes with practical engineering recommendations for structuring memory entries, retrieval, negative-transfer safeguards, and statistical rigor.

    1. Where the Problem Starts: Experience Is Stored, but Never Validated

    AI agents have made clear progress in GPU kernel generation over the past couple of years. The typical workflow is a closed iterative loop: the model writes a first version of the kernel, compiles and runs it, uses test feedback as a compass, and repeatedly fixes issues such as out-of-bounds access, missing synchronization, and underutilized bandwidth until the kernel clears correctness and performance thresholds.

    To keep costs from growing linearly with each task, engineering practice commonly adds a layer of “memory”: successful paths and lessons from failures are written into a knowledge base, or distilled into a reusable skill note that later tasks can retrieve. Intuitively, this makes sense — there is no need to step into the same pit twice.

    But one critical piece has long been missing: how much gain does this accumulated experience actually deliver? Traditional evaluation only answers whether the code generated in a single run is correct and fast. That is a point-in-time measurement of results. It cannot answer whether the experience accumulated last time genuinely helped this time. It is like scoring a chef on each individual dish without ever measuring whether what he learned from the previous dish made the next one better.

    What is needed, then, is a new evaluation target: not the kernel itself, but the transfer value of experience across tasks and across languages.

    2. The Core Difficulty: Separating “Experience Value” from “Memory Value”

    Measuring experience reuse requires a clean controlled experiment. Two naive approaches both contaminate the conclusion:

    • Repeating the same problem in the same language: the model simply replays language-specific techniques verbatim, such as the fixed calling conventions of a particular specialized programming interface or a specific combination of synchronization primitives. What gets measured here is a memory hit, not the abstract value of the experience.
    • Switching to a completely different computational problem: too many variables. Performance differences may stem from the change in problem structure naturally invalidating old experience, making it impossible to distinguish “the experience was useless” from “the problem changed.”

    A more rigorous solution is to keep the problem fixed and change the language.

    That is, hold the mathematical semantics, the hardware environment, and the scoring criteria fixed, and replace only the implementation language. This forces language-specific details to become invalid, so the model must rely on the transferable parts — understanding of problem structure, methods for locating bottlenecks, and judgment about optimization ordering — to achieve any gain. Cross-language transfer gain therefore becomes an attributable observable.

    3. Building the Evaluation System: Task Set, Dual-Language Versions, and Scoring Criteria

    A reproducible evaluation system contains at least four elements.

    1. The task set covers real workloads. It consists of dozens of computational tasks drawn from production environments, spanning six major categories such as attention computation, key-value cache management, and mixture-of-experts routing, and covering both memory-bound and compute-bound cases, so conclusions do not hold only for a single operator shape.

    2. Each task has two language versions. Both languages are specialized programming paradigms that allow fine-grained control over on-chip memory hierarchy and thread scheduling, but they differ markedly in syntax, abstraction level, and default behavior. Both versions share the same reference implementation and the same numerical tolerance.

    3. Scoring is three-dimensional:

      • Correctness: agreement with the reference implementation within the given tolerance, including boundary and extreme-shape cases;
      • Performance: speedup relative to the baseline, requiring multiple runs for robust statistics, with cold starts and scheduling jitter excluded;
      • Process cost: number of iterations, number of compilation failures, and time required to reach the threshold.
    4. Grouped controls. At least three groups are set up: a no-memory group, a same-language memory group, and a cross-language memory group. Cross-language gain is defined as the improvement of the cross-language group over the no-memory group, while the same-language group serves as a reference for the “memory upper bound.”

    A schematic main evaluation loop:

    1. def evaluate(task, lang, memory=None):
    2. best = None
    3. for step in range(max_steps):
    4. kernel = agent.generate(task, lang, memory) # memory is injected as retrieved snippets or skill entries
    5. r = run_and_profile(kernel, task.spec) # correctness + performance + elapsed time
    6. if r.passed and (best is None or r.speedup > best.speedup):
    7. best = r
    8. memory = memory.update(task, lang, r) if memory else None
    9. return best

    4. Why Experience Does or Does Not Transfer Across Languages: A Mechanism-Level Explanation

    Whether cross-language reuse holds depends on the abstraction level at which the experience sits.

    Transferable experience is usually judgment about problem structure and hardware behavior: the bottleneck for this kind of operator is bandwidth rather than compute; the tile size needs to trade off against cache line size and occupancy; the reduction needs to be layered to lower synchronization overhead; the key to mixture-of-experts routing is load balancing and locality of index memory access. These conclusions do not depend on specific syntax.

    Non-transferable experience is bound to language details: the parameter layout of a particular interface, the way a certain synchronization primitive is written, the compiler’s default vectorization behavior. After switching languages, these are not merely ineffective; they can also misdirect the search, showing up as negative transfer.

    So the value of the evaluation is not just a score. It reveals the distribution of abstraction levels in memory — the closer a skill note is to a causal “bottleneck → remedy” description, the more stable the cross-language gain; the closer it is to copied code snippets, the more fragile the gain.

    5. Engineering Recommendations

    • Structure memory entries: suggested fields include the applicable problem category, the observed bottleneck, the validation method, the failure conditions, and a language-agnostic label.
    • Retrieve rather than inject everything: recall by task category and bottleneck label to control context length and noise.
    • Add negative-transfer safeguards: when the memory-augmented group performs significantly worse than the no-memory group in iteration count or success rate, automatically downweight or isolate that entry.
    • Prioritize statistical significance: speedup ratios fluctuate widely with small samples, so fix random seeds, warm up, and repeat sampling.
    • Combine with general-purpose cloud capabilities: a container platform hosts a reproducible compilation environment, object storage keeps kernel artifacts and memory base snapshots, and logging and monitoring with alerting track success rate and speedup regressions.

    6. Conclusion

    Moving the evaluation focus from “how good was this attempt” to “did what was learned last time help this time” is a necessary step toward engineering GPU kernel automation. The design of fixing the problem and swapping the language makes the value of experience separately measurable, and the engineering implication is direct: what is worth accumulating is causal understanding of bottlenecks and optimization ordering, not copyable code snippets. On a general-purpose compute platform, combined with structured memory, robust statistics, and a reproducible environment, cross-language experience reuse can genuinely translate into stable gains in generation efficiency.