Can GPU Kernel Optimization Experience Transfer Across Languages?
This article examines whether optimization experience gained by AI agents while writing GPU kernels can be reused across different GPU-specific programming languages. It explains why single-run benchmarks fail to measure experience value, then proposes a controlled experiment that keeps the computational problem and hardware fixed while changing only the language, using a four-cell comparison to isolate experience gains from language difficulty. It also argues for storing experience in two layers—language-agnostic and language-specific—with scope, invalidation conditions, and confidence fields, and outlines the engineering steps and metrics needed to run such an evaluation pipeline. Readers will learn how to turn one-time debugging lessons into repeatable gains and avoid wasting compute on ineffective experience transfer.
1. Start With a Kitchen Analogy: Does Experience Belong to the Pan or the Cook?
A chef develops a sense of heat control using a Chinese wok: when to turn up the flame, when to add ingredients along the rim, when to reduce the sauce. Does that judgment still hold when switching to a Western flat-bottomed pan? Partly. The rules governing how moisture content changes in food, and the temperature required for the Maillard reaction, are independent of the cookware. Other parts do not transfer—the rhythm of tossing and the conditions for creating wok hei are strongly tied to the pan’s shape and heat retention.
GPU kernel optimization faces an isomorphic problem. A GPU kernel is a small program that runs on a graphics card and is deeply tuned for a specific computation. Written well, it can be an order of magnitude faster than a naive implementation; written poorly, it may struggle to guarantee numerical correctness. Recently, agents with autonomous coding ability have been able to write kernels themselves: generating code, compiling and running it, and iterating based on test feedback. A more advanced approach is to distill the conclusions they discover into an external knowledge base or compress them into a “skill note” for reuse in later tasks.
The real question is whether this accumulated experience has any value. Traditional evaluation only asks whether the code produced in a single run is correct and fast. It never answers whether the experience accumulated last time actually contributed this time. This is like scoring each dish without ever measuring whether the lessons from the previous dish made the next one better.
2. The Evaluation Gap: Why a Single Score Cannot Represent Experience Value
Measuring experience value requires a time dimension and a transfer dimension—precisely the two dimensions missing from single-run evaluation. The ability to generate kernels can be broken into three layers:
- Foundational ability: the model’s understanding of parallel computing models, memory hierarchies, and synchronization semantics.
- Task ability: its grasp of the mathematical structure of specific operators (such as tiling, reduction, and broadcasting).
- Experience reuse ability: transferring conclusions from prior similar tasks to new scenarios, and knowing when not to transfer.
Traditional evaluation covers only the first two layers. Without a dedicated experiment, the third layer is masked by the other two: a model with strong foundational ability can score highly even without reusing any experience, so the results cannot distinguish “experience is useful” from “the model was already strong.”
3. The Key to Experimental Design: Change the Language, Not the Problem
The entire difficulty of testing cross-language reuse lies in the design of the control experiment. Two intuitive approaches both fail.
Approach one: repeat the same problem in the same language. Here, the language-specific tricks the agent summarized last time—one memory access pattern being faster, one synchronization primitive having lower overhead—are carried over verbatim. This measures the value of memory, not the value of experience.
Approach two: switch to a completely different computational problem. Now attribution becomes impossible: if performance drops, is it because the experience became invalid, or because the problem’s difficulty and structure changed and the old conclusions no longer apply? The variables are no longer isolated.
A workable solution is to control the variables: keep the problem fixed and change the language. Concretely, select a set of computational tasks from real production environments, covering several major categories such as attention mechanisms, key-value caching, and mixture-of-experts routing. Prepare two equivalent versions of each task, implemented in two different GPU-specific programming languages. These languages all allow programmers to precisely control on-chip memory, thread hierarchy, and scheduling order, but their syntax and idiomatic paradigms differ markedly.
Behind the two versions are the same mathematical problem, the same hardware, and the same scoring criteria. The only variable is the programming language. This yields a clear four-cell comparison:
| Stage | Language | Carries prior experience? | Observation goal |
|---|---|---|---|
| Warm-up | Language A | No | Establish a no-experience baseline |
| Transfer | Language B | Carries Language A experience | Experience gain (core metric) |
| Control | Language B | No | Isolate language difficulty differences |
| Regression | Language A | Carries Language B experience | Test bidirectional symmetry |
The core metric is not the absolute score but the difference: the improvement of the transfer group over the same-language control group. A significant improvement indicates that part of the experience is language-independent. Parity or a decline indicates that what was accumulated is mostly surface-level technique, and negative transfer is occurring.
4. Experience Should Be Split Into Two Categories, Not Recorded as Generic Notes
The design above produces meaningful conclusions because it implies a more practical engineering claim: experience must be stored in layers.
- Language-agnostic layer: the rationale for choosing parallel granularity and thread block size, the principles of coalesced access to shared and global memory, approaches to avoiding bank conflicts, the trade-off between pipeline depth and occupancy, and strategies for numerical stability (such as online normalization and block accumulation).
- Language-specific layer: concrete syntax constructs, built-in functions, synchronization primitives, compile-time constraints, and common error patterns.
Cross-language reuse should transfer only the first layer. If the two layers are mixed in a single note, transfer will drag in inapplicable syntax conclusions, showing up as the agent repeatedly writing code that fails to compile in the new language.
A simplified example of an experience entry:
experience:scope: language-agnostic # transferable across languagesproblem_class: attentionobservation: increasing the tile size raises register pressure and lowers occupancydecision_rule: if estimated registers per thread > threshold, fall back one tile sizeevidence: {speedup_range: medium, confidence: medium}invalid_when: sequence length is very small or shared memory capacity is constrained
The key fields are scope, invalid_when, and confidence: they give experience an applicability boundary, turning reuse into a conditional call rather than unconditional application.
5. Engineering Steps to Put This Evaluation in Practice
- Build the task set: sample in layers by operator category to ensure enough samples per category; prepare equivalent dual-language implementations for each task and verify numerical consistency (relative error thresholds must be set separately per precision mode).
- Collect baselines: run each language multiple times under no-experience conditions and take the distribution rather than a single value to reduce the impact of randomness.
- Generate experience: have the agent complete optimization in Language A, automatically extract entries that satisfy the
scopeconstraint into the knowledge base, and record the time and failure rate of the extraction process itself. - Execute transfer: clear syntax memory tied to Language A, inject only the language-agnostic layer, and rerun the same task in Language B.
- Compute metrics: report transfer gain, negative transfer rate, the reduction in iterations needed to reach the same performance, and changes in compilation failure rate.
- Perform attribution analysis: trace negative transfer samples one by one to determine whether the applicability boundary was missing or the experience itself was wrong.
For engineering implementation, this kind of pipeline is naturally suited to containerization: a separate build environment per language, tasks and experience entries placed in object storage, an execution queue decoupled by a message queue, and metrics for the whole process fed into logging and monitoring/alerting systems, making long-running batch tests and regression comparisons easy. General-purpose capabilities such as the container platform, object storage, message queue, logging, and monitoring/alerting offered by Baidu AI Cloud can serve as optional infrastructure for hosting such an evaluation pipeline, though the specific choice still needs to be assessed against your own scale and compliance requirements.
6. Conclusion: Give Experience an Applicability Boundary
Whether cross-language reuse works depends on how experience is expressed. Generic “lesson notes” will most likely produce negative transfer; layered entries with applicability conditions and confidence can turn one instance of hitting a snag into repeated gains. The value of the evaluation system lies here too: it turns “whether the agent gets better with use” from a subjective impression into quantifiable metrics—only a positive transfer gain, fewer iterations, and a non-increasing compilation failure rate show that experience has genuinely been consolidated. For engineering teams, this method can be applied directly to the continuous optimization of selection and tuning workflows, avoiding spending compute budgets on ineffective experience transfer.
