Skip to content

[FEAT][kernels]: implement Prefix-Shared Fused Attention for GRPO LogProb computation #65

Closed

Description

@Flink-ddd

Motivation

In GRPO and PPO pipelines, the log probability computation phase often involves processing batches where multiple generated responses ($G$) share the exact same prompt prefix.
Standard SDPA backends (like CuDNN or native FlashAttention) treat these as independent sequences, resulting in redundant global memory reads for the prompt's KV cache. This creates a severe Memory-Bound bottleneck for Long Context RL tasks.

Proposed Solution

We need to implement a highly optimized, hardware-aware Prefix-Shared Fused Attention kernel. By leveraging manual asynchronous pipelines and shared memory swizzling, we can load the shared prompt KV tiles into SRAM once and broadcast them across the $G$ queries in the registers.

We will base this implementation on a 5-stage evolutionary pipeline design, specifically targeting the efficiency of the v5 architecture:

  1. Shared Memory Swizzling: Implement XOR-based swizzling to eliminate bank conflicts during ldmatrix.x4 instructions.
  2. Asynchronous Pipelining: Utilize cp.async for global-to-shared data movement.
  3. Asymmetric Buffering: Implement double buffering for K tiles (BLOCK_KV * 2) and single buffering for V tiles to maximize SRAM utilization without stalling the MMA compute.
  4. Grouped Query MMA: Route the $G$ queries corresponding to the same prompt through the register files while the shared KV remains resident in SRAM.

Target Performance

Aiming for > 90% Hardware SOL on A100/Hopper architectures for high-group-size ($G \ge 64$) GRPO logprob forward passes.

Activity

  1. added
    component: kernels
    component: alignment
    type: performance
    priority: high
    on Jun 2, 2026
  2. self-assigned this
    on Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

component: alignmentcomponent: kernelspriority: hightype: performance

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions