← Back to Pull requests

vxpu/kernels: collapse per-op registration, catalog, and Go equivalence test boilerplate #967

Closed
unknown closed this pull request without merging on Nov 30, 2026 15:04 UTC
View on GitHub
unknown unknown commented on Nov 29, 2026 18:34 UTC
Author

vxpu/kernels: read kernel metadata from canonical kernel_catalog.json

Adding a new kernel previously required duplicating devices, numerics, lowerability, SiteKind, applicability conditions, and preference order across plan.OP_KINDS, Python @implementation/@variant decorators, ops.SELECTION, pyrightconfig.json, and pkg/kernelplan/catalog/kernel_catalog.json.

Makes vxpu/pkg/kernelplan/catalog/kernel_catalog.json the single source of truth shared by Go and Python:

  • Removes plan.OP_KINDS and loads body metadata and preference order directly from kernel_catalog.json in plan.implementation(), validating that any explicit arguments do not contradict the catalog.

  • Copies kernel_catalog.json alongside vxpu/ in vxpu/images/executor/Dockerfile.

  • Strips duplicated metadata kwargs from all catalog-backed @implementation calls in ops.py and @variant calls under vxpu/python/vxpu/kernels/ (including fused_add_rmsnorm, fused_qk_norm_rope, and moe_topk_softmax), and sorts module discovery in kernels.discover().

  • Adds ops.default_context(), ops.context(), and ops.NoTensorContextError so standard activation-first ops derive row counts and <rows>x<K> shape keys generically; removes _int4_linear_context, _int4_moe_context, _int4_moe_swiglu_context, _fused_add_rmsnorm_context, and _moe_topk_softmax_context; lowers any op registered in plan.REGISTRY without requiring a SELECTION entry; and updates kernel_tools/score.py to derive scoring context via ops.context().

  • Broadens pyrightconfig.json to ignore vxpu/kernels/**/_triton_kernel.py and updates the pinned kernel_digest in lower_test.py for the simplified gpu_triton.py decorators.
  • vxpu/kernelplan: extract call-site rows and shapes generically

    Previously segment.go hardcoded vxpu::int4_linear, vxpu::int4_moe, vxpu::int4_moe_swiglu, vxpu::fused_add_rmsnorm, vxpu::fused_qk_norm_rope, and vxpu::moe_topk_softmax to extract row counts and shapes from exported tensor metadata, forcing every new fused op to add another branch.

    Replaces the hardcoded branch with populateCallSiteShapes(), which derives row counts from the leading dimensions of the primary activation tensor (named x or the first tensor input) and records a default <rows>x<K> shape string when not already populated from weight metadata. Only operators with non-standard signatures (rotary, hc_sinkhorn, engram_rows, allreduce, read, fused_qk_norm_rope, moe_experts, and fp8_grouped_linear) keep explicit overrides.

    vxpu/planner: make Go GPU equivalence tests data-driven

    Previously each new lowerable GPU op required a dedicated TestVerifyPlanEquivalence_GPU_<Op> function in equivalence_test.go and a matching grep assertion in dev/ci/gpu/test-vxpu-gpu.

    Replaces the per-op GPU tests with TestVerifyPlanEquivalence_GPU_LowerableOps, which reads call sites from the exported fixture artifact, intersects them with lowerable CUDA bodies in DefaultKernelCatalog(), and verifies reference vs optimized equivalence, observed bodies, and timing for every discovered op. Updates dev/ci/gpu/test-vxpu-gpu to verify the data-driven suite without per-op grep lines, and updates vxpu/docs/design.md with the shared catalog and generic extraction architecture.

    Verified on NVIDIA L4 (driver 580.178.04, 23034 MiB, torch 2.14.1+cu130):

    python -m unittest -v vxpu.moe_topk_softmax_test  # 4 tests OK (including ties and CUDA graphs)
    cd vxpu && go test -v -count=1 -run "^TestVerifyPlanEquivalence_GPU" ./pkg/planner
    
    === RUN   TestVerifyPlanEquivalence_GPU_LowerableOps
    === RUN   TestVerifyPlanEquivalence_GPU_LowerableOps/vxpu::fused_add_rmsnorm
    ... equivalent=true referenceMsPerToken=116.80 optimizedMsPerToken=5.10 speedup=22.90
    === RUN   TestVerifyPlanEquivalence_GPU_LowerableOps/vxpu::fused_qk_norm_rope
    ... equivalent=true referenceMsPerToken=28.35 optimizedMsPerToken=5.10 speedup=5.56
    === RUN   TestVerifyPlanEquivalence_GPU_LowerableOps/vxpu::int4_linear
    ... equivalent=true referenceMsPerToken=28.40 optimizedMsPerToken=5.10 speedup=5.57
    === RUN   TestVerifyPlanEquivalence_GPU_LowerableOps/vxpu::int4_moe
    ... equivalent=true referenceMsPerToken=30.80 optimizedMsPerToken=5.15 speedup=5.98
    === RUN   TestVerifyPlanEquivalence_GPU_LowerableOps/vxpu::int4_moe_swiglu
    ... equivalent=true referenceMsPerToken=29.75 optimizedMsPerToken=5.25 speedup=5.67
    === RUN   TestVerifyPlanEquivalence_GPU_LowerableOps/vxpu::moe_topk_softmax
    ... equivalent=true referenceMsPerToken=27.35 optimizedMsPerToken=4.85 speedup=5.64
    --- PASS: TestVerifyPlanEquivalence_GPU_LowerableOps (82.26s)
        --- PASS: TestVerifyPlanEquivalence_GPU_LowerableOps/vxpu::fused_add_rmsnorm (16.15s)
        --- PASS: TestVerifyPlanEquivalence_GPU_LowerableOps/vxpu::fused_qk_norm_rope (10.67s)
        --- PASS: TestVerifyPlanEquivalence_GPU_LowerableOps/vxpu::int4_linear (10.62s)
        --- PASS: TestVerifyPlanEquivalence_GPU_LowerableOps/vxpu::int4_moe (10.77s)
        --- PASS: TestVerifyPlanEquivalence_GPU_LowerableOps/vxpu::int4_moe_swiglu (10.90s)
        --- PASS: TestVerifyPlanEquivalence_GPU_LowerableOps/vxpu::moe_topk_softmax (10.66s)
    === RUN   TestVerifyPlanEquivalence_GPU_FullPlan
    ... equivalent=true referenceMsPerToken=34.60 optimizedMsPerToken=5.20 speedup=6.65
    --- PASS: TestVerifyPlanEquivalence_GPU_FullPlan (20.82s)
    PASS
    ok  github.com/gke-labs/generation-ai/vxpu/pkg/planner 103.098s
    

    Fixes #966

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: justinsb Review duration: 1229m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #967"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.5% · Safe to merge
    20.5%