Skip to content

HSA decode: define the scratchpad as a variable instead of baking it in - #178

Merged
erwei-xilinx merged 1 commit into
worktree-hsa-hsaco-dispatchfrom
hsa-scratchpad-variable
Oct 27, 2026
Merged

erwei-xilinx merged 1 commit into
worktree-hsa-hsaco-dispatchfrom
hsa-scratchpad-variable

Conversation

@erwei-xilinx

Copy link
Copy Markdown
Collaborator

Follow-up to #158; based on its branch, so the diff is only this change. Retarget to main once #158 merges.

ROCR now resolves a full ELF's control scratchpad against a variable the application defines before loading (ROCm/rocm-systems#14004), and keys full-ELF PDI placements by section (ROCm/rocm-systems#13908). With both:

  • The HSA decode allocates the scratchpad, loads the cached hsaco with scratch-pad-ctrl defined, and writes L with plain stores.
  • Removed: the ELF relocation rewriting in driver.py, the per-decoder repack and triton_npu_hsa_prepare_bytes, triton_npu_hsa_scratchpad_flush, and the pointer_info probe.
  • Added triton_npu_hsa_prepare_with_variables; triton_npu_hsa_prepare is unchanged.
  • Pin rocm-sdk-core==10.3.0a20261027, the first nightly with both fixes. Without #13908, Switch HSA/ROCR dispatch to hsaco/kernel-object loading #158 gives wrong HSA results on repeated full-ELF dispatches (Llama decode diverges at token 2, matmul_bf16_m64_n64_k64 75% wrong).

Test plan

On Krackan, with the pinned wheel:

  • Llama-3.2-1B HSA decode, 300 tokens: identical to XRT; 63 tok/s (XRT 64).
  • AMD_TRITON_NPU_RUNTIME=hsa: axpy, matmul_bf16_m64_n64_k64, test_softmax pass.
  • examples/llm_q4nx/test_decode_artifact.py passes.
  • scripts/test_hsa_hsaco_pack.py fails in aircc on Switch HSA/ROCR dispatch to hsaco/kernel-object loading #158 as well, unchanged by this PR.

🤖 Generated with Claude Code

ROCR's AIE loader resolves a full ELF's control scratchpad against a
variable defined with hsa_executable_agent_global_variable_define, and
flushes it on every dispatch (ROCm/rocm-systems#14004).

So the decode allocates the scratchpad, loads the cached hsaco with it
defined, and writes L with plain stores. This drops the ELF relocation
rewriting in driver.py, the per-decoder repack and prepare_bytes, the
host-side flush, and the pointer_info probe it needed.

Pin rocm-sdk-core 10.3.0a20261027, the first nightly with both
ROCm/rocm-systems#14004 and #13908. On an older ROCR, repeated full-ELF
dispatches give wrong results and the decode fails to load.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@erwei-xilinx
erwei-xilinx merged commit 3e6f163 into worktree-hsa-hsaco-dispatch Oct 27, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant