Skip to content

Add support for HipGraph - #4956

Open
pfultz2 wants to merge 38 commits into
developfrom
hipgraph-pass
Open

Add support for HipGraph#4956
pfultz2 wants to merge 38 commits into
developfrom
hipgraph-pass

Conversation

@pfultz2

@pfultz2 pfultz2 commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

Motivation

Technical Details

Changelog Category

Add a CHANGELOG.md entry for any option other than Not Applicable

    • Added: New functionality.
    • Changed: Changes to existing functionality.
    • Removed: Functionality or support that has been removed. (Compared to a previous release)
    • Optimized: Component performance that has been optimized or improved.
    • Resolved Issues: Known issues from a previous version that have been resolved.
    • Not Applicable: This PR is not to be included in the changelog.

@gh-app-migraphx-bot-pr-write

gh-app-migraphx-bot-pr-write Bot commented Jun 12, 2026

Copy link
Copy Markdown
Test Batch New Rate (eff087) Old Rate (55ca93) Diff Status
torchvision-resnet50 64 3,145.50 3,169.20 -0.75%
torchvision-resnet50_fp16 64 6,657.24 6,721.88 -0.96%
torchvision-densenet121 32 2,694.06 2,712.99 -0.70%
torchvision-densenet121_fp16 32 4,550.11 4,578.90 -0.63%
torchvision-inceptionv3 32 1,794.22 1,805.02 -0.60%
torchvision-inceptionv3_fp16 32 2,838.14 2,855.31 -0.60%
cadene-inceptionv4 16 820.71 824.13 -0.41%
cadene-resnext64x4 16 782.72 785.46 -0.35%
slim-mobilenet 64 8,380.17 8,444.46 -0.76%
slim-nasnetalarge 64 228.81 229.50 -0.30%
slim-resnet50v2 64 1,326.42 3,185.35 -58.36% 🔴
bert-mrpc-onnx 8 440.37 1,173.56 -62.48% 🔴
bert-mrpc-tf 1 491.55 484.20 1.52%
pytorch-examples-wlang-gru 1 457.27 472.27 -3.18%
pytorch-examples-wlang-lstm 1 390.87 386.76 1.06%
torchvision-resnet50_1 1 744.30 754.58 -1.36%
cadene-dpn92_1 1 453.05 444.58 1.90%
cadene-resnext101_1 1 365.23 366.32 -0.30%
onnx-taau-downsample 1 216.45 402.99 -46.29% 🔴
dlrm-criteoterabyte 1 32.36 32.58 -0.68%
dlrm-criteoterabyte_fp16 1 36.80 52.65 -30.09% 🔴
agentmodel 1 9,648.60 7,784.58 23.94% 🔆
unet_fp16 2 49.75 57.48 -13.46% 🔴
resnet50v1_fp16 1 162.67 932.89 -82.56% 🔴
resnet50v1_int8 1 910.99 934.74 -2.54%
bert_base_cased_fp16 64 508.98 1,105.09 -53.94% 🔴
bert_large_uncased_fp16 32 113.33 347.51 -67.39% 🔴
bert_large_fp16 1 199.27 205.61 -3.08%
distilgpt2_fp16 16 1,897.83 2,104.89 -9.84% 🔴
yolov5s 1 543.87 559.63 -2.82%
tinyllama 1 18.48 46.13 -59.94% 🔴
vicuna-fastchat 1 4.25 44.16 -90.37% 🔴
whisper-tiny-encoder 1 328.53 415.45 -20.92% 🔴
whisper-tiny-decoder 1 403.84 412.20 -2.03%
llama2_7b 1 4.24 21.00 -79.80% 🔴
qwen1.5-7b 1 5.69 23.73 -76.03% 🔴
phi3-3.8b 1 6.81 26.83 -74.61% 🔴
llama3-8b 1 4.58 21.87 -79.04% 🔴
whisper-large-encoder 1 6.35 10.23 -37.96% 🔴
whisper-large-decoder 1 10.55 104.89 -89.94% 🔴
mistral-7b 1 16.50 23.89 -30.94% 🔴
FLUX.1-schnell 1 780.90 760.54 2.68%

Regressions detected 🔴

@gh-app-migraphx-bot-pr-write

gh-app-migraphx-bot-pr-write Bot commented Jun 12, 2026

Copy link
Copy Markdown
Test Status Result
bert-mrpc-onnx PASSED: MIGraphX meets tolerance
bert-mrpc-tf PASSED: MIGraphX meets tolerance
pytorch-examples-wlang-gru PASSED: MIGraphX meets tolerance
pytorch-examples-wlang-lstm PASSED: MIGraphX meets tolerance
dlrm-criteoterabyte PASSED: MIGraphX meets tolerance
agentmodel PASSED: MIGraphX meets tolerance
unet PASSED: MIGraphX meets tolerance
resnet50v1 PASSED: MIGraphX meets tolerance
bert_base_cased_fp16 PASSED: MIGraphX meets tolerance
bert_large_uncased_fp16 🔴 FAILED: MIGraphX is not within tolerance - check verbose output
bert_large PASSED: MIGraphX meets tolerance
yolov5s PASSED: MIGraphX meets tolerance
tinyllama PASSED: MIGraphX meets tolerance
vicuna-fastchat PASSED: MIGraphX meets tolerance
whisper-tiny-encoder PASSED: MIGraphX meets tolerance
whisper-tiny-decoder PASSED: MIGraphX meets tolerance
llama2_7b PASSED: MIGraphX meets tolerance
qwen1.5-7b PASSED: MIGraphX meets tolerance
phi3-3.8b PASSED: MIGraphX meets tolerance
llama3-8b PASSED: MIGraphX meets tolerance
whisper-large-encoder PASSED: MIGraphX meets tolerance
whisper-large-decoder PASSED: MIGraphX meets tolerance
mistral-7b PASSED: MIGraphX meets tolerance
FLUX.1-schnell PASSED: MIGraphX meets tolerance

@codecov

codecov Bot commented Jun 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #4956      +/-   ##
===========================================
+ Coverage    92.89%   93.26%   +0.37%     
===========================================
  Files          603      623      +20     
  Lines        32448    33097     +649     
===========================================
+ Hits         30140    30866     +726     
+ Misses        2308     2231      -77     

see 54 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds HIP Graph capture/replay support to the GPU backend by introducing a new hip::graph operation plus a hipgraphify pass that partitions the root module into capturable regions and replaces them with hip::graph submodules. It also adds kernel-launch packing helpers needed to inspect/patch captured kernel node arguments, along with GPU tests covering partitioning and pointer rebinding behavior.

Changes:

  • Add gpu::hipgraphify pass to extract capturable instruction runs into hip::graph submodules (enabled in the default GPU backend pipeline).
  • Introduce hip::graph operation that captures a submodule into a HIP graph and replays it, with pointer-rebind logic for moved inputs.
  • Add kernel config pack/unpack helpers and new GPU tests for both graph partitioning and pointer rebinding.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
test/gpu/pack_args.cpp Adds tests for pack_kernel_config / unpack_kernel_config pointer-slot parsing.
test/gpu/hipgraphify.cpp Adds unit tests validating hipgraphify partitioning behavior and boundaries.
test/gpu/hip_graph.cpp Adds integration tests ensuring captured graphs correctly rebind moved input pointers across runs.
src/targets/gpu/target.cpp Wires hipgraphify{} into the default GPU backend pass pipeline.
src/targets/gpu/kernel.cpp Implements pack_kernel_config / unpack_kernel_config and uses the packed launch config helper in kernel launching.
src/targets/gpu/include/migraphx/gpu/kernel.hpp Declares new kernel config helpers and exposes kernel::get_function() for correlating graph nodes to code objects.
src/targets/gpu/include/migraphx/gpu/hipgraphify.hpp Adds public header for the gpu::hipgraphify pass.
src/targets/gpu/hipgraphify.cpp Implements the graph partitioning/extraction pass.
src/targets/gpu/hip_graph.cpp Implements the hip::graph operation: capture, instantiate, replay, and rebind (patch or re-record).
src/targets/gpu/CMakeLists.txt Adds new HIP graph sources to the GPU target library build.

Comment thread src/targets/gpu/hip_graph.cpp
Comment thread src/targets/gpu/hip_graph.cpp Outdated
Comment on lines +115 to +120
check_hip(hipStreamBeginCapture(stream, hipStreamCaptureModeThreadLocal),
"hipStreamBeginCapture");
f();
hipGraph_t g = nullptr;
check_hip(hipStreamEndCapture(stream, &g), "hipStreamEndCapture");
return hip_graph{share(hip_graph_ptr{g})};
Comment on lines +141 to +142
if(not output_buffer.empty() and output_buffer.size() != outputs.size())
return;
Comment thread test/gpu/pack_args.cpp Outdated
Comment thread test/gpu/pack_args.cpp Outdated
Comment on lines 233 to +235
write_literals{.max_memory = max_memory},
hipgraphify{},
dead_code_elimination{},
pfultz2 and others added 3 commits June 22, 2026 11:42
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@pfultz2

pfultz2 commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator Author

@copilot resolve the merge conflicts in this pull request

Copilot AI commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

@copilot resolve the merge conflicts in this pull request

Resolved. I merged develop into this branch and fixed the conflict in docs/reference/MIGraphX-dev-env-vars.rst in commit e428316b8.

aditya-dl added a commit to aditya-dl/AMDMIGraphX that referenced this pull request Jun 29, 2026
Internal handoff for PR ROCm#5019: thesis, per-file implementation w/ code, verification, architecture note, and the maintainer review (approach superseded by ROCm#4956; fp16/int4 gate is the likely-additive piece). Lives on the non-PR branch only; not for upstream.
@pfultz2
pfultz2 marked this pull request as ready for review July 10, 2026 19:56
@pfultz2
pfultz2 requested review from a team and causten as code owners July 10, 2026 19:56
pfultz2 and others added 15 commits July 10, 2026 18:02
- Bind submodule parameters by sorted name so the binding survives
  save/load of a compiled program (parameter order is not serialized)
- Rebase the cached outputs/result onto moved parameter buffers on the
  patch path instead of returning views of the old buffers
- Follow a code_object kernel's aliased output when collecting patch
  targets so kernels reading an in-place-written parameter are patched
- Fall back to re-recording when movable leaf ranges overlap or a
  captured kernel node's argument buffer cannot be parsed back
- Keep the patched kernarg buffer/config alive in graph_node_patch; HIP
  does not document copying extra at SetParams time
- Serialize evals with a mutex since program copies share graph_state
- Fall back to an uncaptured run under MIGRAPHX_TRACE_EVAL
- Skip capturing a run whose output-backing allocation cannot become a
  submodule input (out-of-bounds alias index in release builds)
- Exclude gpu::quant_gemm (same rocblas path as gpu::gemm) and
  hip::graph itself from capture, making the pass idempotent

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DBSRz3D6A6BaEW1P7ix9Y1
test/gpu/hip_graph.cpp:
- rebind_save_load: save/load round trip of the compiled program before
  the rebind checks, pinning the sorted-name parameter binding
- rebind_output_buffer: input and output buffers move together between
  runs
- multi_output_tuple: two outputs captured as one graph under offload
  copy, returning a tuple unpacked with get_tuple_elem
- rebind_aliased_inputs: one buffer bound to both inputs on the capture
  run, then distinct buffers, pinning the overlap fallback and the
  re-record path
- factor the captured-graph check into captured_hip_graph()

test/gpu/hipgraphify.cpp:
- split_by_quant_gemm: gpu::quant_gemm is a partition boundary
- idempotent: applying the pass twice equals applying it once
- output_root_outside_run: a run whose output roots at an allocation
  reachable only through views of a pre-run value is left uncaptured

All pass on gfx1201; rebind_convolution needs MIGRAPHX_DISABLE_MLIR=1
here due to a pre-existing MLIR no-solutions issue unrelated to this PR.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DBSRz3D6A6BaEW1P7ix9Y1
- rebind_sliced_input: kernels consume a slice of x, so rebinding must
  re-apply the captured nonzero within-leaf pointer offset
- mixed_output_backing: a run mixing allocation-backed and
  non-allocation-backed external outputs is left uncaptured
- unpack_invalid_configs: null extra, unknown tag, missing size entry,
  and a pointer slot past the end of the packed buffer

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DBSRz3D6A6BaEW1P7ix9Y1
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.

3 participants