← Back to Pull requests

[Comgr][hotswap] Read source hidden arguments instead of translating them #286

Closed
unknown closed this pull request without merging on Jul 31, 2026 12:18 UTC
View on GitHub
unknown unknown commented on Jul 30, 2026 12:39 UTC
Author

Hidden-argument reads are lowered as ordinary loads of
kernarg_base + source_offset. The kernarg-pointer provenance analysis that
classified those reads, and the synthesis that rebuilt their values, are
removed.

Why this is correct

1. ROCclr sizes the kernarg buffer from the source kernel's metadata and writes
each declared hidden field at its metadata offset
(WriteAqlArgAt(hidden_arguments, value, it.size_, it.offset_),
clr/rocclr/device/rocm/rocvirtual.cpp). The application loaded the source
code object, so those are the source offsets.
2. The dispatch path rewrites kernel_object, private_segment_size, and under
a scaled dispatch workgroup_size_x / grid_size_x. kernarg_address is
untouched (rocr-runtime .../core/runtime/hotswap_aql_patch.h).
3. The lifted kernel declares one byref([N x i8]) blob of the source
.kernarg_segment_size and sets amdgpu-no-implicitarg-ptr, so its segment
is the same size and the backend appends no implicit block.

The byte at kernarg_base + source_offset holds the hidden value regardless of
how the kernel computed the address.

The premise being corrected

Synthesis assumed the target runtime does not populate hidden arguments at the
source offsets, so a hidden read had to be reconstructed from the dispatch
packet or the target ABI's implicit-argument block. Fact 1 contradicts that. The
provenance analysis existed only to decide which reads needed reconstruction, so
it has nothing left to decide.

The analysis was keyed on a register, so it did not recognise a hidden read
through a pointer materialised into a second SGPR pair, e.g. rocSPARSEs
csrmmnn_device_nnz_split_main_256_2 does s_add_nc_u64 s[26:27], s[0:1], 0x88
then s_load_b32 s30, s[26:27], 0x0. Those reads already lowered as ordinary
loads and were already correct.

Removed

  • Kernarg-pointer prepass and dataflow lattice

  • Consumer lattice and intra-BB SGPR constant shadow

  • Two-mode Entry/NonEntry machinery

  • source-hidden-args.{cpp,h}, kernarg-layout.{cpp,h}
  • Added

  • checkLiftedKernargSegment: post-codegen check that the emitted

  • .kernarg_segment_size equals the source's and that the emitted metadata
    declares no hidden_ argument. This is fact 3. A lowering that reintroduces
    llvm.amdgcn.implicitarg.ptr would place a block past the end of the
    runtime's buffer.

    Behaviour changes

  • hidden_private_base / hidden_shared_base no longer refuse; ROCclr writes

  • the target queue's apertures.
  • hidden_global_offset_{x,y,z} no longer needs the HIP zero-offset assumption.

  • ASSUME_HIP_GLOBAL_OFFSET_ZERO has no effect and is kept for source
    compatibility.
  • Scaled dispatch needs no special case. ROCclr fills the geometry fields from

  • the requested block before the packet is scaled, so the buffer holds un-scaled
    source geometry. virtualizeScaledDispatchSize was required because synthesis
    read the scaled packet.

    API

  • The returned executable must be dispatched in place of the source kernel,

  • keeping that dispatch's kernarg_address. Its metadata declares one
    by_value argument and no hidden_
    entries. Documented on the hotswap
    group.
  • A translation requiring a scaled dispatch fails with

  • AMD_COMGR_STATUS_ERROR_INVALID_ARGUMENT when the request cannot receive the
    factor: result == NULL, or an unnamed whole-object request, since the factor
    is per kernel. amd_comgr_hotswap_transpile always passes a null result.
    Named requests with a result are unaffected.
  • raiseToIR now takes a RaiseOptions struct carrying both ISAs. Post-raise

  • retry flags moved to an internal type.

    Models

    Under HSA_HOTSWAP_STRICT=1, hidden-argument reads originally refused outright:
    any load at or above implicitArgsBase through the kernarg pair hit
    cross-arch implicitarg.ptr lowering is unresolved, so vit, gemma3n, llama,
    wav2vec2 and whisper would not translate (the AISE P-1 implicitarg.ptr
    failures). #124 lifted those refusals by synthesizing the values and adding the
    analysis to gate it. This change resolves them by reading the byte, which also
    covers the hidden kinds synthesis had no implementation for.

    All five were re-run on gfx1151 (source gfx1250, STRICT=1, bf16), plus
    Qwen3-0.6B. Llama-3.2-1B-Instruct and Qwen3-0.6B: teacher-forced GPU-vs-CPU
    argmax divergences 0 and coherent generation. whisper-base: max_abs_diff 1.4e-4
    (decoder), 2.3e-4 (encoder). ViT-base-patch16-224: 4.9e-6, argmax match.
    wav2vec2-base-960h faults after the MIOpen Im2d2Col_v2 conv kernel and
    gemma-3n-E2B-it fails in hipblasLtMatmul. Both fail identically with the
    pre-change binary, and neither reaches a numeric comparison.

    Diff: 598 lines (+448 / -150) across 7 files Reviewer: martin-luecke Review duration: 1418m
    All Vouch review confidence checks passed
    Residual risk 0.20 = Change Risk (0.50) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.50 · 598 lines diff across 7 files
    0.50
    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.383
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #286"
    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: 50% (MEDIUM) · Higher = larger blast radius
    50%
    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: 19.8% · Safe to merge
    19.8%