Can GPU Kernel Optimization Experience Transfer Across Languages?

    GPU kernel optimization is experience-heavy, and agents can now record lessons from generating, testing, and refining kernels. This article explains why memory is not the same as transfer, and how a same-problem, different-language evaluation can measure whether stored experience actually improves the next kernel. It covers controls, metrics, structured experience records, an engineering loop, governance practices, and current limits.

    1. Background: From One-Off Optimization to Reusable Experience

    A GPU kernel is a device-side program that runs on a GPU and is highly optimized for a specific computation. Its performance depends not only on the algorithm, but also on low-level choices such as memory hierarchy, thread-block partitioning, memory-access coalescing, register usage, shared memory, and pipeline scheduling. A well-written kernel can substantially shorten the computation path; a poor one may not even be correct. GPU kernel optimization has therefore long been an experience-intensive engineering task. Many decisions come less from abstract algorithms than from repeated experiments with hardware behavior, data layout, and scheduling strategy.

    As agent technology advances, agents can automatically write, test, and iteratively optimize GPU kernels. A typical loop is: the agent generates kernel code from a task description, compiles and runs it, reads correctness and performance feedback, and then revises the implementation. It can also record the lessons formed during that process, store them in an experience library, or organize them as skill notes for later retrieval and reuse. Intuitively, this should prevent repeated mistakes: a rule learned while resolving a similar memory-access bottleneck should be useful the next time.

    A key question remains insufficiently answered: does accumulated experience actually improve the quality of the next kernel? Past evaluations often ask only whether the code generated for the current task is correct and fast. They rarely quantify whether experience from the previous task helped the current one. That is like judging only the final taste of each dish without checking whether the cook’s heat judgment from the previous dish transferred to the next. Without that measurement, an experience library can easily become an add-on that looks useful but is hard to verify.

    2. Core Difficulty: The Value of Experience Is Not the Value of Memory

    To test whether experience can be reused, memory must first be distinguished from transfer. If an agent repeatedly solves the same problem in the same language, interface calls, syntax habits, and local tricks remembered from the last attempt can reappear unchanged. Any measured improvement may then be a memory effect rather than generalizable low-level logic contained in the experience.

    The other extreme is to switch directly to a completely different computation. Once the problem changes, the relevance of the old experience itself declines, and the result is hard to interpret: did the experience lack value, or did the changed problem make it inapplicable? Neither design cleanly answers whether experience can transfer across languages.

    A sound controlled experiment therefore keeps the mathematical problem, input and output semantics, hardware environment, and scoring criteria unchanged, while changing only the programming language or domain-specific interface used to implement the kernel. If the agent then achieves better results in the new language with help from experience gained in the old language, that more convincingly shows that the experience contains transferable low-level judgment rather than mere syntax memory.

    3. Controlled Experiment: Same Problem, Different Language

    An evaluation system for cross-language experience reuse can be summarized as two versions, one problem, one hardware environment, and one scoring method. The task set can cover computation patterns from real engineering scenarios, including attention, key-value cache management, and mixture-of-experts routing. Each task has two implementations that use different syntax and abstraction styles, while both still allow fine-grained control of GPU memory and thread scheduling. Behind both versions are the same mathematical problem, hardware environment, and correctness and performance criteria. The only variable is the programming language.

    This design turns the vague intuition of “whether experience transfers” into an observable metric. Evaluation can use three controls: a no-experience baseline, same-language experience injection, and cross-language experience injection. Comparing them on correctness, performance, compilation stability, and iteration count shows whether the gain from experience is real and how much cross-language transfer loses relative to same-language memory.

    4. Metrics: From One-Time Correctness to Transfer Gain

    Cross-language experience evaluation should not look only at whether the final code is fast. It needs several layers of metrics:

    • Correctness: compilation pass rate, functional-test pass rate, and stability under boundary conditions.
    • Performance: speedup relative to the baseline, variation across input sizes, and resource usage.
    • Transfer gain: the improvement after injecting historical experience relative to the no-experience baseline.
    • Negative-transfer rate: the proportion of cases that become worse or introduce errors after experience is injected.
    • Reuse cost: the number of iterations spent retrieving, adapting, and validating experience.
    • Explainability: whether an experience entry states its applicable conditions, so that a rule that merely happened to work is not overgeneralized.

    Together, these metrics answer one question: a larger experience library is not automatically better. It must balance correctness, performance, and reusability. Negative-transfer detection is especially important. During cross-language reuse, a language-specific trick that is incorrectly abstracted as a general rule may cause hidden performance regression or even correctness problems in the new language.

    5. Experience Representation: Split Techniques into Retrievable Entries

    To make experience reusable, entries should not be long natural-language notes. They should be structured descriptions. At minimum, an entry should include the applicable pattern, trigger condition, recommended action, scope, language-agnostic flag, confidence, and verification record. For example:

    1. experience = {
    2. pattern: "repeated global-memory reads",
    3. condition: "the same data block is reused by multiple thread blocks",
    4. action: "first evaluate shared memory or register caching, and check memory-access coalescing",
    5. scope: "kernel_schedule",
    6. language_agnostic: true,
    7. confidence: 0.8,
    8. verified_on: ["task family A", "task family B"]
    9. }

    This representation lets retrieval match task features, language abstraction level, and hardware context at the same time. During injection, only language-agnostic principles need to be given to the agent, while language-specific adaptation is left for validation in the new language. The library should also be layered: hardware-behavior principles at the bottom, task-pattern rules in the middle, and language-specific writing styles at the top. For cross-language reuse, prefer the lower and middle layers; upper-layer writing styles should be hints, not hard rules.

    6. Experiment and Engineering Workflow

    The evaluation workflow can be abstracted as a closed loop: baseline generation, experience retrieval, experience injection, result comparison, and experience write-back.

    1. for task in tasks:
    2. for lang in [A, B]:
    3. baseline = agent.solve(task, lang, experience=None)
    4. retrieved = retrieve(task.features, lang, hardware)
    5. with_exp = agent.solve(task, lang, experience=retrieved)
    6. record(correctness, performance, stability, iterations)
    7. update_experience(task, lang, with_exp.feedback)

    Retrieval should avoid injecting old-language interface names directly into prompts for the new language. Write-back should deduplicate experience, resolve conflicts, and update confidence. Language-agnostic rules validated multiple times should receive higher confidence. Writing styles effective in only one language should be marked as language-related. Entries that cause negative transfer should have their weight reduced or be isolated.

    7. Engineering Implications: Govern the Library Instead of Accumulating It

    First, version the experience library. Changes in hardware, compilers, or the task set can invalidate old experience, and unversioned rules can contaminate later tasks. Second, give every entry an applicability boundary. Unconditional optimization slogans are risky: “use more shared memory,” for example, may increase synchronization overhead when data reuse is insufficient. Third, cross-language transfer needs an adaptation layer. Language-agnostic principles can be reused directly, but concrete memory layouts and thread-scheduling expressions must be revalidated in the new language. Fourth, detect negative transfer early. After injecting experience, run a small correctness and performance regression before the full evaluation. Fifth, quantify the value of experience with controlled experiments rather than judging subjectively whether a knowledge base looks rich.

    8. Limits and Outlook

    Cross-language experience evaluation still has limits. A task set cannot cover every GPU computation pattern; different hardware may respond differently to the same optimization strategy; natural-language descriptions of experience entries can be ambiguous; and changes in the agent’s own capability can affect comparison results. Future work can expand task families and language abstraction layers, introduce finer-grained experience attribution, establish lifecycle management for experience, and include correctness, performance, and negative transfer in continuous regression.

    Overall, GPU kernel optimization experience can transfer across languages, but what should transfer is verifiable low-level logic and conditional rules, not interface syntax itself. A same-problem, different-language controlled evaluation separates the value of experience from the value of memory, so that knowledge accumulated by agents can become an engineering asset that is transferable, measurable, and governable.