Can GPU Kernel Optimization Experience Transfer Across Languages?

    This article examines whether optimization knowledge accumulated by AI agents on one GPU programming language can be reused on another. It explains why a controlled "same problem, different language" design is required to rule out memory effects and problem drift, outlines a reproducible evaluation framework (MetaKernelBench-style) built from task, dual-language, experience, and metric layers, and shows how the abstraction level of stored experience determines its reuse radius. It closes with four principles for building reusable experience libraries and three practical actions for engineering teams.

    1. Start With a Kitchen Analogy: What Optimization Experience Really Is

    A chef who has mastered the heat control and tossing rhythm of a Chinese wok switches to a Western flat pan. Which judgments still hold? Decisions like “when to turn the heat up” or “when to reduce the sauce” do not depend on the shape of the pan. They depend on the moisture content of the ingredients, the degree of caramelization, and the rate of heat transfer. What transfers is the underlying causal model; what does not transfer is the hand technique for holding the pan.

    GPU kernel optimization is highly analogous. A GPU kernel is a small program that runs on a graphics processor and is deeply customized for a specific computation. Written well, it can be an order of magnitude faster than a naive implementation; written poorly, it may not even guarantee numerical correctness. In recent years, agents with autonomous coding ability have been able to write kernels independently: they produce candidate implementations, run tests, read feedback, iterate on fixes, and distill the conclusions they discover along the way into an external knowledge base or structured “skill notes” for later tasks.

    The problem is that the industry has long lacked a way to measure whether this accumulated experience actually has value. Traditional evaluation answers only one question: is the code produced this time correct and fast? It is like scoring each dish without ever tracking whether the experience from the previous dish made the next one better. This leaves us with an untested assumption: pitfalls we have already hit will not be hit again. That assumption needs to be verified by experiment, not accepted by default.

    2. The Core Difficulty in Evaluation Design: Controlling Two Confounding Variables

    Testing whether experience transfers across languages requires suppressing two kinds of interference at the same time.

    The first is the memory effect. If an agent is asked to solve the same problem repeatedly in the same language, it will carry over language-specific tricks verbatim — a particular way of writing a memory access pattern, a habitual way of calling a certain synchronization primitive. Any performance gain then comes from “remembering the answer” rather than “understanding the problem,” which measures memory instead of experience.

    The second is problem drift. If the task is swapped for a completely different computation, the relevance of prior knowledge to the new task becomes uncontrollable. When performance does not improve, you cannot tell whether the experience was ineffective or whether the task itself changed and the experience simply had nothing to apply to.

    The only clean design, therefore, is: keep the problem fixed, change the language. Control of variables here is not rhetoric; it is a precondition for the conclusion to hold at all.

    3. A Reproducible Evaluation System: The Structure of a MetaKernelBench-Style Approach

    An evaluation system proposed by a university team offers a reference skeleton. Its construction logic can be abstracted into four layers.

    Task layer. More than seventy computation tasks are drawn from real production environments, covering six categories including attention computation, key-value cache management, and mixture-of-experts routing. Choosing real workloads rather than toy samples gives optimization experience an engineering context and keeps conclusions from holding only in simplified settings.

    Dual-language layer. Each task has two equivalent implementation versions written in two different GPU-specific programming languages. These languages share the trait of letting programmers control on-chip memory hierarchy and thread scheduling in fine detail, but their syntax paradigms, abstraction levels, and compilation paths differ sharply. Behind the two versions are the same mathematical definition, the same hardware platform, and the same scoring criteria; the only variable is the programming language.

    Experience layer. After the agent completes a task in language A, its accumulated knowledge is made explicit as retrievable entries. The agent then faces the same problem in language B, and we observe whether those entries are invoked and whether they produce a benefit.

    Metric layer. Scoring includes at least three dimensions: numerical correctness (error against a reference implementation), performance (speedup relative to a baseline), and cross-language transfer gain (the difference in language B performance between a group with knowledge and a group without). The third dimension is the one this article actually cares about.

    A schematic main evaluation loop can be written as the following pseudocode; the point is the two comparison groups, not a single run’s score:

    1. for task in benchmark.tasks:
    2. # Control group: language B, no prior experience
    3. base = run_agent(lang="B", task=task, memory=None)
    4. # Treatment group: accumulate in language A, then transfer to language B
    5. src = run_agent(lang="A", task=task, memory=None)
    6. memory = distill(src.trace) # distill into structured experience entries
    7. tgt = run_agent(lang="B", task=task, memory=memory)
    8. record(task,
    9. correctness(base), correctness(tgt),
    10. speedup(base), speedup(tgt),
    11. transfer_gain = speedup(tgt) - speedup(base))

    4. Why Experience May Transfer: Abstraction Level Determines Reuse Radius

    Whether cross-language reuse works depends on the abstraction level at which experience is stored. It can be roughly divided into three levels.

    The surface level is syntax and API memory — for example, which form of a certain call is shorter. This kind of knowledge has a very small reuse radius: it fails as soon as the language changes, and can even cause negative transfer, with the agent forcing old idioms into the new language and wasting iteration budget.

    The middle level is resource management strategy — for example, reusing data in on-chip memory as much as possible, coalescing memory accesses to improve continuity, and balancing the workload within a thread block. These strategies are bound to the hardware execution model rather than to the syntax of any one language, so they survive across languages fairly well.

    The deep level is problem-structure understanding — for example, recognizing which intermediate results in a computation graph need not be written back to main memory, which reductions can be done in layers, and which branches are constant for a given shape and can therefore be specialized. This kind of understanding is closest to the mathematical essence and transfers most strongly.

    One engineering principle follows: the value of an experience library correlates positively with its abstraction level. If the accumulated entries are full of language-proprietary terms, they are closer to a cache than to knowledge.

    5. Four Principles for Making Experience Actually Reusable

    Structured, not narrative. An entry should include applicable conditions, problem characteristics, the action, the expected benefit, and counter-examples. Experience without applicable conditions cannot be retrieved, nor can it be applied safely.

    1. {
    2. "condition": "Chained element-wise operations exist and intermediate tensors are large",
    3. "pattern": "Operator fusion to avoid round-tripping intermediate results to main memory",
    4. "expected": "Fewer memory accesses; significant gains in bandwidth-bound cases",
    5. "counter_example": "Benefit reverses when register pressure is too high and occupancy drops"
    6. }

    Include counter-examples and boundaries. A library that records only success paths induces overconfidence. Explicitly writing down failure conditions is the most economical way to suppress negative transfer.

    Retrievable, with conflict resolution. When multiple entries give contradictory advice, the conflict must be adjudicated based on task characteristics and hardware parameters rather than resolved by simply concatenating them.

    Bound to a verification loop. Experience must be empirically validated before it enters the library, and after entry you should track its success rate and gain distribution when invoked; low-gain entries should be down-weighted or retired. This follows the same logic as general cloud engineering practice such as monitoring and alerting, log services, and metrics dashboards: no measurement, no iteration.

    6. Implications for Engineering Practice

    For teams using AI coding tools or building their own agents, this methodology translates into three concrete actions. First, upgrade evaluation from a “single-run pass rate” to “incremental gain,” and fix a set of tasks in the regression suite to measure experience-library quality. Second, require experience entries to be language-agnostic: in review, if an entry cannot be expressed without referring to a specific syntax, send it back for rewriting. Third, set up controlled experiments for transfer: any newly introduced knowledge source should first be validated for gain on a small dual-language sample before being enabled at full scale.

    7. Conclusion

    Cross-language reuse is not mysticism; it is a proposition that can be settled experimentally. As long as you hold to the controlled design of “same problem, different language” and store experience at the level of hardware and problem structure rather than syntax, optimization knowledge can keep appreciating across programming language boundaries. Conversely, if the experience library is just a pile of fragments from historical code, its hollowness will be exposed the moment the language changes. The real value of an evaluation system is turning the self-perception that “we learned something” into a report card that can be reviewed.