Skip to content

feat(amdgpu): add hipep backend selected via profile=llm#1

Open
zz002 wants to merge 12 commits into
mainfrom
feat/rocm-llm-backend
Open

feat(amdgpu): add hipep backend selected via profile=llm#1
zz002 wants to merge 12 commits into
mainfrom
feat/rocm-llm-backend

Conversation

@zz002

@zz002 zz002 commented Jun 16, 2026

Copy link
Copy Markdown
Owner

Summary

Add the hipep backend to the AMD GPU umbrella EP, selected via the profile=llm provider option. The hipep plugin EP (hipep-backend.dll) is loaded as a third backend alongside DirectML and MIGraphX, reusing the existing dynamic-backend pattern.

What

  1. Profile::Llm (gpu_info) accepts "llm" / "3".
  2. ProviderFactory::CreateHipepBackend loads hipep-backend, forwards CreateEp / ReleaseEp, mirroring the DirectML/MIGraphX backends. hipep is a pre-built plugin EP DLL loaded at runtime, so no ROCm SDK is required to build amdgpu-ep.
  3. gpu_ep.cc routes profile=llm to CreateHipepBackend.
  4. CreateEp forwards the ORT-selected hardware device(s) + ep_metadata to the backend. Unlike DirectML/MIGraphX, hipeps CreateEprejectsnum_devices == 0`, so the umbrella must pass the selected device.

DirectML and MIGraphX paths are unchanged. No CMake changes - hipep is a pure code addition, always compiled into amdgpu-ep.

Test plan

Validated on gfx1151 (with the stacked build PR so DirectML/MIGraphX are off): a MatMul model run through AMDExecutionProvider with profile=llm compiles via hip-compiler and executes through hipBLASLt; output matches the CPU reference (max abs diff 0), no fallback or crash. Requires the companion hipdnn-ep factory fix (ROCm/MorphiZen#234).

Notes for reviewers

  • amdgpu-ep as-is still requires DirectML + MIGraphX to build (USE_AMDGPU forces both on, migraphx-ep needs the MIGraphX SDK). Building/running with only hipep uses the stacked build-scaffolding PR (not for merge).
  • Deployment: the loaded DLL is hipep-backend.dll; the hipdnn-ep build currently produces onnxruntime_morphizen_ep.dll, so the output name needs to be aligned (rename the build target or ship a renamed copy).

onnxruntime#21)

Add a declarative pattern-matching fusion engine to the DirectML plugin EP
that detects raw ONNX operator sequences and fuses them into optimized DML
kernels without depending on ORT internal C++ classes.

Key changes:
- pattern_matcher: PNode tree DSL with greedy longest-match semantics and
  anchor-indexed O(nodes + matches) traversal
- ep_fusion_manager: anchor-indexed rule registry; FusionMatchMap keyed by
  node ID hash eliminates re-detection at CompileImpl time
- quick_gelu_ep_fusion: detects Sigmoid+Mul (2-node) or Mul+Sigmoid+Mul
  (3-node); compiles via IDMLDevice1::CompileGraph with lazy init
- bias_gelu_ep_fusion: detects raw 6-node Gelu expansion Add+Div+Erf+Add+Mul+Mul;
  uploads bias to GPU once at session init; compiles DML_ELEMENT_WISE_ADD1
  with fused GELU activation
- Shape changes recompile a temporary kernel per call, matching ORT DML EP behavior
@zz002 zz002 force-pushed the feat/rocm-llm-backend branch from ff40ecc to 01e7cb3 Compare June 17, 2026 01:39
@zz002 zz002 changed the title feat(amdgpu): add ROCm (MorphiZen) backend selected via profile=llm feat(amdgpu): add MorphiZen backend selected via profile=llm Jun 17, 2026
@zz002 zz002 force-pushed the feat/rocm-llm-backend branch 3 times, most recently from 2f32dad to e78f4b1 Compare June 17, 2026 02:25
@zz002 zz002 changed the title feat(amdgpu): add MorphiZen backend selected via profile=llm feat(amdgpu): add hipep backend selected via profile=llm Jun 17, 2026
Zhaeong and others added 11 commits June 17, 2026 12:04
* Add mlss_use_specific_ops as EP option

* Add putenv for getenv compatibility

* Add exhaustive_tune ep option to amdgpu ep to match migraphx ep
…attern matcher (onnxruntime#27)

The BiasGelu pattern tree matched nodes it couldn't compile — the rank-1
bias check ran in Compile() after nodes were already claimed via
AddNodesToFuse, causing ORT_EP_FAIL and session abort.

Add a Predicate input constraint kind to the pattern matching engine that
runs caller-provided lambda checks inline during graph traversal. This
allows semantic validation (rank, shape, initializer membership) at
pattern-match time alongside structural matching.

Changes:
- pattern_matcher.h: Add Predicate kind with PredicateFn accepting node
  pointer for cross-input validation. Add PInitializerWithMaxRank helper.
- pattern_matcher.cc: Pre-fetch OrtValueInfo map per node, handle
  Predicate in both fixed-index and scan-all branches.
- bias_gelu_ep_fusion.cc: Replace post-match validation with PBiasInput
  predicate (rank-1 check, last-dim match). Compile reads bias name from
  pattern capture. Guard deferred compilation when shapes are unknown.
- ep_fusion_manager.cc: Move MatchesResult before AddNodesToFuse to
  prevent claiming nodes no rule owns.
Add the hipep backend to the AMD GPU umbrella EP: load the pre-built
hipep-backend plugin EP DLL as a third backend (alongside DirectML and
MIGraphX) and route to it when the user selects profile=llm.

- Profile::Llm parses "llm" / "3"; gpu_ep.cc routes profile=llm to
  ProviderFactory::CreateHipepBackend.
- ProviderFactory loads hipep-backend and forwards CreateEp / ReleaseEp to it,
  mirroring the DirectML/MIGraphX backend pattern. hipep is a pre-built plugin
  EP DLL loaded at runtime, so no ROCm SDK is required to build amdgpu-ep.
- CreateEp forwards the ORT-selected hardware device(s) + ep_metadata to the
  backend's CreateEp. Unlike DirectML/MIGraphX, hipep's CreateEp rejects
  num_devices == 0, so the umbrella must pass the selected device.

DirectML and MIGraphX paths are unchanged.

Co-authored-by: Cursor <cursoragent@cursor.com>
…ctML/MIGraphX

The hipep backend no longer requires the umbrella to forward the ORT-selected
device: its CreateEp now tolerates a null device array / num_devices == 0
(ROCm/MorphiZen#234). Drop the devices/ep_metadata parameters from
ProviderFactory::CreateHipepBackend and the ExecutionProvider constructor and
pass nullptr/nullptr/0, so the hipep path matches the DirectML and MIGraphX
backends and the EP constructor keeps the same signature as the sibling EPs.

Co-authored-by: Cursor <cursoragent@cursor.com>
Add src/hipep parallel to directml/migraphx. It builds hipep-backend.dll, a thin pass-through OrtEpFactory that loads hipep.dll, forwards CreateEpFactories, and returns the HIP EP's factory unchanged so the AMD GPU umbrella forwards to it directly. ReleaseEpFactory forwards to the HIP EP and unloads the DLL. Only a single factory is supported.

Wired via a new USE_HIPEP option (forced on by USE_AMDGPU) and add_subdirectory(hipep).

Co-authored-by: Cursor <cursoragent@cursor.com>
CreateEpFactories can be invoked more than once (e.g. a real session plus the device-init session in OGA). The previous single-handle logic reloaded the DLL on each call (leaking the earlier handle) and unloaded it on the first ReleaseEpFactory while later factories were still live. Load on the first factory and unload only after the last is released; roll back the refcount if the load fails so a retry re-attempts it.

Co-authored-by: Cursor <cursoragent@cursor.com>

Co-authored-by: Cursor <cursoragent@cursor.com>
Address PR review: the backend name must not contain "ep". Rename the
umbrella backend shim from hipep to hip (src/hip/, hip-ep target,
hip-backend.dll, USE_HIP option, and all C++ identifiers). The shim now
loads the HIP EP DLL as hipgpu (hipgpu.dll / libhipgpu.so), to be renamed
on the onnx-hipdnn-ep side in a follow-up.

Co-authored-by: Cursor <cursoragent@cursor.com>
@zz002 zz002 force-pushed the feat/rocm-llm-backend branch from 4e9aa28 to 71c00fb Compare June 24, 2026 10:55
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.

5 participants