Can GPU Kernel Optimization Experience Transfer Across Languages?

    This article examines whether optimization experience accumulated by AI agents for GPU kernels can be reused across different programming languages. It explains why evaluation must hold the problem, hardware, and scoring criteria fixed while varying only the language, and outlines a reproducible evaluation system built on a task suite, dual-language mirrors, scoring rules, and process control. It also proposes a four-layer knowledge representation, three typical transfer outcomes, and a six-step engineering loop for building an experience-reuse pipeline.

    1. A Kitchen Analogy That Exposes the Real Question

    A chef trains a sense of heat control with a Chinese wok: when to turn up the flame, when to drizzle sauce along the rim, when to reduce the liquid immediately. Move to a Western flat pan and cook the same dish, and how many of those judgments still hold? The cookware has changed, and so have the heat conduction curve, the oil film distribution, and the resistance to tossing. But the underlying rule that a ingredient’s water content determines when to start reducing the sauce has not changed.

    Replace the “pan” with a GPU and the “dish” with a compute workload, and you have the hardest engineering problem in AI agents (Agents) generating high-performance kernels today. A GPU kernel is a small program that runs on the graphics card and is hand-tuned for a specific compute pattern. Written to fit the hardware, it can be several times faster end to end; written carelessly, it may fail to guarantee numerical correctness at all.

    Over the past two years, AI coding tools have been able to write and test in a loop: generate a kernel, compile it, run a correctness check, measure performance, and feed errors and performance data back to the model for iteration. A more advanced approach distills the findings into a searchable experience library or structured “skill notes” for reuse in later tasks. The logic is appealing: the second person does not have to fall into the pit the first person already fell into.

    But one key question has long gone unmeasured: does this accumulated experience actually produce a gain? Traditional evaluation only answers whether the code produced this time is correct and fast. It never answers whether the knowledge accumulated last time was actually used this time, or whether it actually delivered an improvement. It is like scoring every dish while never tracking whether the lessons from the previous dish made the next one better.

    2. The Real Difficulty in Evaluation Design: Removing “Memory” and “Problem Drift”

    To test whether experience transfers across languages, the experiment must first eliminate two groups of confounding variables.

    The first is the memory effect. If an agent repeatedly solves the same problem in the same language, it will carry over language-specific tricks verbatim, such as the calling convention of a particular built-in function or the fixed form of a certain class of synchronization primitive. Any improvement then comes from “remembering the answer” rather than “understanding the rule,” and what you measure is the value of memory.

    The second is problem drift. If you switch to a completely different compute task, the relevance of prior experience is diluted, and in the end you cannot tell whether the experience failed or whether the task itself changed and left the experience with nowhere to apply.

    There is only one workable solution: keep the problem fixed and change the language. Fix the mathematical semantics, fix the hardware environment, and fix the scoring criteria, and let the programming language be the only variable. If the experience still produces a gain, what it carries must be the underlying logic that spans languages, such as “do not repeatedly write intermediate results back to global memory,” “match the amount of data each thread block handles to the shared memory capacity,” and “make the stride of the reduction tree an aligned power of two,” rather than some syntactic sugar.

    3. What a Reproducible Evaluation System Should Contain

    Following common industry practice for kernel generation evaluation, a complete system needs at least four layers.

    Task suite. Select workloads from real production scenarios, covering categories such as attention computation, key-value cache management, routing and dispatch in mixture-of-experts models, normalization and element-wise fusion, and sparse or irregular memory access. Each category needs a clear input size range and numerical tolerance.

    Dual-language mirror. Provide two equivalent implementations of the same task, each based on a different high-performance kernel development language. Such languages typically let developers explicitly control the memory hierarchy (registers, shared memory, global memory) and the thread hierarchy (threads, thread blocks, thread block clusters), but their syntax and abstraction boundaries differ markedly. Both implementations share the same reference implementation and the same test vectors.

    Scoring criteria. Correctness comes first: agreement with the reference implementation within the given tolerance, otherwise performance is recorded as zero. Performance comes second: report relative efficiency against the hardware’s achievable peak, and also record absolute elapsed time, so that noise on small workloads does not dominate the conclusions.

    Process control. Compilation, execution, timing, and cleanup must be scripted with a fixed random seed, repeated multiple times, and summarized with the median, with the initialization overhead of the first run excluded.

    A schematic main evaluation loop can be written as:

    1. def evaluate(agent, task, source_lang, target_lang, k=3):
    2. # Phase 1: accumulate experience in the source language; produce experience only, not counted in the final score
    3. exp = agent.solve(task, lang=source_lang, budget=k)
    4. knowledge = distill(exp) # distill into language-agnostic points
    5. # Phase 2: switch to the target language; problem semantics and scoring criteria stay exactly the same
    6. results = []
    7. for _ in range(k):
    8. code = agent.solve(task, lang=target_lang, knowledge=knowledge)
    9. results.append(harness.run(code, task)) # correctness + performance
    10. return aggregate(results) # take the median; record accuracy and relative efficiency

    4. What Form Should Experience Take

    Whether cross-language reuse succeeds depends largely on the granularity of the knowledge representation. Too specific (“a certain function is faster under a particular version”) and it cannot transfer; too abstract (“optimize memory access”) and it is not actionable. A reasonably safe layered scheme is as follows.

    The first layer is problem invariants: mathematically equivalent transformations, parallelizable dimensions, and numerical stability constraints. This layer is completely language-agnostic.

    The second layer is the hardware cost model: the order-of-magnitude differences in bandwidth and latency across the memory hierarchy, the trade-off between occupancy and register pressure, and the cost of synchronization and atomic operations. This layer is language-agnostic and only weakly coupled to the hardware generation.

    The third layer is strategy patterns: tiling, double-buffered pipelining, reduction trees, online normalization, and operator fusion. This layer transfers across languages, but the way it is implemented differs.

    Only the fourth layer is language idioms: concrete syntax and built-in capabilities. This layer should be explicitly marked as non-transferable to avoid contaminating the reuse process.

    In cross-language scenarios, the correct approach is to transfer only the first two layers and the strategy descriptions of the third, discard the fourth, and require the agent to experiment again in the target language. Without this isolation, evaluation results get drowned out by language-detail noise.

    5. How to Interpret the Results

    Cross-language transfer usually takes one of three typical forms, each requiring different handling.

    Positive transfer. Both accuracy and relative efficiency improve in the target language, which shows the experience captured common rules at the hardware and algorithm level. Such experience should be promoted to high-priority knowledge entries.

    Neutral transfer. Accuracy improves but performance does not change significantly, which often means the experience only helped the agent avoid compile errors and common pitfalls and has not yet touched the performance bottleneck. In this case, add performance attribution data, such as comparisons of memory access efficiency, occupancy, and instruction issue efficiency.

    Negative transfer. Performance in the target language actually gets worse. A common cause is mistaking the idioms of the source language for universal rules, for example forcing a certain synchronization pattern onto a language that lacks an equivalent primitive, which adds overhead or creates correctness risk. These cases are the most valuable evaluation output and should flow back into a “counter-example library” used to suppress reuse of wrong experience.

    It is worth stressing that negative transfer does not negate the value of accumulating experience; it precisely characterizes the boundaries within which experience applies. What is truly dangerous in engineering is not that experience fails, but that you cannot tell when it will fail.

    6. Putting It into Engineering Practice: Building Your Own Experience-Reuse Loop

    To validate a similar proposition on your own platform, proceed in the following order.

    Step 1: Fix the baseline. Prepare a trusted reference implementation and test vectors for each task category, and first run a “no experience” control group to obtain the achievable efficiency ceiling on the target hardware. Report all later gains relative to this baseline.

    Step 2: Build the dual-language mirror. Choose two kernel development approaches that differ markedly in abstraction level and syntax, ensuring semantic equivalence and consistent scoring. Language choice does not need to chase popularity; what matters is that the difference is large enough to form a valid comparison.

    Step 3: Distill and label experience. After the agent completes the task in the source language, force it to output structured points and label the transferable layer. Experience without labels does not enter the library.

    Step 4: Isolated reuse. When transferring, inject only the transferable layers, forbid carrying over language idioms, and keep a separate exploration budget in the target language.

    Step 5: Metric-based acceptance. Track accuracy, relative efficiency, the number of iterations needed to reach the target performance, and the experience hit rate. A drop in the number of iterations is often the most sensitive signal that experience is working, and says more than a single-point performance gain.

    Step 6: Continuously maintain the counter-example library. Archive negative transfer cases in a structured way and run a pre-check before each later reuse, which can significantly reduce ineffective attempts.

    In terms of deployment, this loop does not demand much of the infrastructure: tasks and vectors can live in object storage, evaluation jobs can be launched in batch on a container platform to keep the environment consistent, execution logs and performance metrics can go into logging and monitoring/alerting services, and the experience library and counter-example library can be hosted on an ordinary database or a vector retrieval service. What matters is consistent criteria and a reproducible environment, not the choice of components.

    7. Conclusion

    “Can experience transfer across languages” is essentially asking whether what an agent learns is the answer to a task or the structure of a problem. Narrowing the variables down to the programming language alone is the only way to make this question measurable. For engineering teams, the value goes beyond an evaluation score: it is a method for judging whether knowledge assets are genuine, that is, which experience is worth keeping as a high-priority asset, which is only an accidental success under a specific syntax, and which must be written into a counter-example list. On hardware as sensitive to the memory hierarchy and parallelism granularity as GPUs, this ability to distinguish often determines the long-term pace of performance evolution more than writing a few more kernels does.