Do GPU Kernel Optimization Insights Transfer Across Languages? Lessons from a Targeted Evaluation

    This article examines whether optimization experience accumulated by AI agents when writing GPU kernels represents genuinely transferable knowledge or merely environment-specific memory. It introduces an evaluation design that isolates programming language as the single variable—keeping the computational problem, hardware, and scoring criteria fixed while switching between two GPU domain-specific languages. It also proposes a three-layer knowledge taxonomy for kernel optimization insights and offers practical principles for building experience-reuse systems, including layered annotation, minimal controlled re-testing, layer-aware retrieval, and second-order evaluation metrics.

    1. The Question: Is Accumulated Experience Actually Valuable?

    In GPU programming, a GPU kernel is a small program that runs on the graphics card and is deeply optimized for a specific computational task. A well-written kernel can deliver tens-of-times performance gains; a poorly written one may not even produce correct results. Because the barrier to entry is high and trial-and-error is expensive, having AI agents automatically write and optimize kernels has become a focus of the industry.

    The current mainstream approach is a closed loop of “generate, test, feedback, and revise”: the agent writes a kernel, immediately runs correctness checks and performance benchmarks, and uses failure information as a compass for continuous adjustment. A further refinement is to distill the tricks discovered along the way—storing them in a knowledge base or summarizing them into “skill notes” for reuse in subsequent tasks.

    It sounds perfect: no pit needs to be stepped in twice. But there is a long-avoided question: is the stored experience genuinely transferable knowledge, or merely a memory of the current environment?

    Past evaluations only looked at “whether this generated code is correct and fast,” and never systematically measured “whether the experience accumulated last time actually helped this time.” To use an analogy: it’s like scoring a chef on each individual dish while never tracking whether what they learned from the previous dish made the next one better.

    2. The Core Design Challenge: Isolating “Language” as a Variable

    To verify whether experience transfers across languages, the design of controlled experiments is the biggest challenge. Two intuitive approaches exist, but both are flawed:

    Option 1: Same language, same problem, repeated. The flaw is that language-specific tricks the agent accumulated last time (such as how to call a particular API, or a faster way to use a built-in function) get copied over verbatim. What you measure then is not “the value of experience” but “the value of memory.”

    Option 2: A completely different computational problem. The flaw is that changing the problem itself invalidates old experience. You cannot distinguish between “experience is inherently non-transferable” and “the problem changed, so the experience became irrelevant.”

    The rigorous solution is a third path: keep the problem fixed, change the language.

    Specifically, the evaluation selects dozens of computational tasks drawn from real production environments, covering six major categories of typical scenarios, including attention mechanisms, key-value caching, and Mixture-of-Experts (MoE) routing. Each task has two implementation versions, written in two GPU domain-specific programming languages—both allow programmers fine-grained control over memory layout and thread scheduling, but their syntax and programming paradigms are entirely different.

    Behind the two versions is the same mathematical problem, the same hardware, and the same scoring criteria. The only variable is the programming language. This way, if the experience still works, it can only be because it contains language-agnostic “underlying logic”; if the experience fails, it means the stored content has been “contaminated” by language details.

    3. What Counts as Genuinely Transferable Kernel Optimization Knowledge?

    Behind this evaluation framework lies an important assumption about knowledge layering. We can divide the kernel optimization experience an agent accumulates into three layers:

    1. Language-surface tricks: syntax sugar, API calling conventions, and compiler quirks specific to a language. This layer is tightly bound to the language and becomes invalid as soon as the language changes.
    2. Hardware-layer general principles: for example, “avoid writing intermediate results back to global memory—keep them in on-chip shared memory or registers,” “memory access coalescing takes priority over compute instruction optimization,” and “watch out for bank conflicts and warp divergence.” This layer is language-independent and depends only on the hardware architecture.
    3. Problem-layer algorithmic insights: for example, “attention computation can be pipelined in chunks, trading time for memory,” or “routing can group by expert to reduce irregular memory access.” This layer can even be partially decoupled from the hardware, making it the most abstract and most transferable knowledge.

    A high-quality experience-distillation mechanism should treat layers 2 and 3 as core assets and label layer 1 as “environment-specific, for reference only.” The key criterion for judging whether an experience base is good is its survival rate after a language switch.

    4. Implications for Engineering Practice

    If you are building an experience-accumulation system for GPU kernel optimization—whether for a team or an AI agent—this evaluation approach yields several directly actionable principles:

    1. Enforce layered annotation when recording experience. For each piece of insight, state clearly whether it is a hardware principle, an algorithmic insight, or a language-specific implementation detail. A simple tagging scheme works:

    1. {
    2. "insight": "After tiling a matrix multiplication, threads in the same warp should access consecutive memory addresses",
    3. "level": "hardware", // hardware / algorithm / language-specific
    4. "scope": "general GPU architectures",
    5. "evidence": "validated on attention tasks; bandwidth utilization improved significantly"
    6. }

    2. Validate experience quality with a “minimal controlled” test. Periodically run dual-language (or dual-hardware) re-tests: same problem, different implementation language, and check whether old experience still accelerates convergence. The value of an experience base is not the number of entries but its survival rate across environments.

    3. Filter by layer during retrieval. When facing a new task, retrieve algorithm-layer and hardware-layer experience first; inject language-layer experience into the context only when the language matches, to prevent outdated tricks from misleading the generation process.

    4. Evaluation metrics should cover “second-order effects.” Beyond per-run correctness and speedup, add controlled “with experience vs. without experience” metrics: convergence rounds, number of attempts, and the time required to reach target performance. Only these can quantify the true return of an experience system.

    5. Conclusion

    “Can you still cook a good dish with a different pot?” is essentially a question about the level of abstraction of knowledge. Language is merely the vehicle for expressing optimization; what is truly valuable is the understanding of hardware behavior and algorithmic structure. The evaluation design principle of “fixed problem, changed language” offers a methodology the entire intelligent-programming field can borrow: measure an experience system not by how much it remembers, but by how much survives after the environment changes. For developers, this means asking one more question when writing optimization notes—does this insight still hold in a different language?