Skip to content

Insert match::opaque into deep matchers to fix large symbol names on windows and debug gcc builds - #5124

Open
pfultz2 wants to merge 14 commits into
developfrom
opaque-matcher
Open

Insert match::opaque into deep matchers to fix large symbol names on windows and debug gcc builds#5124
pfultz2 wants to merge 14 commits into
developfrom
opaque-matcher

Conversation

@pfultz2

@pfultz2 pfultz2 commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

Motivation

Rather than type erasing every matcher which can slow matching way down. We insert match::opaque in certain places to reduce the symbol name. On platforms(like unix-based) that do not create such large symbol names the match::opaque is a no-op.

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.

Follow the LLVM AI Tool Use Policy for contributions using AI.

@pfultz2
pfultz2 requested a review from causten as a code owner August 7, 2026 22:50
Copilot AI lite review requested due to automatic review settings August 7, 2026 22:50
@pfultz2
pfultz2 marked this pull request as draft August 7, 2026 22:50

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 introduces a targeted way to reduce C++ template symbol size by selectively type-erasing “deep” matchers via a new match::opaque wrapper, primarily to address Windows and debug-build toolchain limitations, while keeping matcher performance on platforms that don’t require it.

Changes:

  • Added MIGRAPHX_USE_TYPE_ERASED_OPAQUE and match::opaque() to optionally type-erase specific matchers.
  • Wrapped several deeply-nested matchers (algebra simplification, GELU rewrites, attention fusion) with match::opaque to reduce instantiation depth/symbol size.
  • Switched Windows/CIs compile definitions from full matcher type-erasure to opaque-only type-erasure.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/include/migraphx/matcher.hpp Adds MIGRAPHX_USE_TYPE_ERASED_OPAQUE and match::opaque() helper for selective type-erasure.
src/simplify_algebra.cpp Inserts match::opaque in several complex algebraic matchers to reduce type depth.
src/rewrite_gelu.cpp Wraps GELU matchers with match::opaque to reduce symbol size.
src/include/migraphx/match/gelu_tanh.hpp Applies opaque() to internal GELU-tanh matcher subexpressions.
src/include/migraphx/match/gelu_erf.hpp Applies opaque() to internal GELU-erf matcher subexpressions.
src/fuse_attention.cpp Applies match::opaque to deep attention-pattern matchers.
src/CMakeLists.txt Enables opaque type-erasure for Windows builds via compile definition.
.github/workflows/ci.yaml Enables opaque type-erasure for a debug CI build via CXXFLAGS.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +276 to +284
template <class M>
auto opaque(M m)
{
#ifdef MIGRAPHX_USE_TYPE_ERASED_OPAQUE
return any_matcher{m};
#else
return m;
#endif
}
Comment thread src/CMakeLists.txt Outdated
Comment on lines 161 to 164
if(WIN32)
# Due to compilation crashing, we need to use type-erased matchers on Windows.
target_compile_definitions(migraphx PUBLIC MIGRAPHX_USE_TYPE_ERASED_MATCHERS=1)
target_compile_definitions(migraphx PUBLIC MIGRAPHX_USE_TYPE_ERASED_OPAQUE=1)
endif()
@codecov

codecov Bot commented Aug 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.01961% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/rewrite_gelu.cpp 66.67% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #5124   +/-   ##
========================================
  Coverage    93.12%   93.12%           
========================================
  Files          625      625           
  Lines        33162    33171    +9     
========================================
+ Hits         30879    30889   +10     
+ Misses        2283     2282    -1     
Files with missing lines Coverage Δ
src/fuse_attention.cpp 97.52% <100.00%> (+0.02%) ⬆️
src/include/migraphx/match/gelu_erf.hpp 100.00% <100.00%> (ø)
src/include/migraphx/match/gelu_tanh.hpp 100.00% <100.00%> (ø)
src/include/migraphx/matcher.hpp 88.19% <100.00%> (+0.33%) ⬆️
src/simplify_algebra.cpp 97.52% <100.00%> (-0.01%) ⬇️
src/rewrite_gelu.cpp 87.10% <66.67%> (-2.56%) ⬇️

... and 8 files with indirect coverage changes

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

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

gh-app-migraphx-bot-pr-write Bot commented Aug 8, 2026

Copy link
Copy Markdown
Test Batch New Rate (222e61) Old Rate (3a503c)* Diff Status
torchvision-resnet50 64 3,327.06 3,264.92 1.90%
torchvision-resnet50_fp16 64 7,882.21 7,548.67 4.42%
torchvision-densenet121 32 2,489.30 2,483.99 0.21%
torchvision-densenet121_fp16 32 5,010.03 5,004.24 0.12%
torchvision-inceptionv3 32 2,075.91 2,058.51 0.85%
torchvision-inceptionv3_fp16 32 4,494.80 4,416.99 1.76%
cadene-inceptionv4 16 819.19 820.61 -0.17%
cadene-resnext64x4 16 782.66 782.78 -0.02%
slim-mobilenet 64 8,356.97 8,386.36 -0.35%
slim-nasnetalarge 64 229.46 228.86 0.26%
slim-resnet50v2 64 3,240.51 3,180.91 1.87%
bert-mrpc-onnx 8 1,168.58 1,168.84 -0.02%
bert-mrpc-tf 1 490.75 498.63 -1.58%
pytorch-examples-wlang-gru 1 479.31 473.35 1.26%
pytorch-examples-wlang-lstm 1 396.22 384.83 2.96%
torchvision-resnet50_1 1 1,049.95 1,046.63 0.32%
cadene-dpn92_1 1 443.62 437.32 1.44%
cadene-resnext101_1 1 365.47 365.89 -0.11%
onnx-taau-downsample 1 843.43 844.09 -0.08%
dlrm-criteoterabyte 1 32.53 32.42 0.33%
dlrm-criteoterabyte_fp16 1 52.07 51.80 0.51%
agentmodel 1 9,284.79 9,209.12 0.82%
unet_fp16 2 58.92 58.80 0.20%
resnet50v1_fp16 1 1,516.66 1,366.11 11.02% 🔆
resnet50v1_int8 1 1,672.39 1,883.96 -11.23% 🔴
bert_base_cased_fp16 64 1,099.34 1,098.16 0.11%
bert_large_uncased_fp16 32 344.53 345.59 -0.31%
bert_large_fp16 1 207.47 206.59 0.43%
distilgpt2_fp16 16 2,082.29 2,092.89 -0.51%
yolov5s 1 559.76 558.33 0.26%
tinyllama 1 45.77 45.83 -0.13%
vicuna-fastchat 1 44.15 44.20 -0.12%
whisper-tiny-encoder 1 412.60 411.87 0.18%
whisper-tiny-decoder 1 413.81 408.48 1.30%
llama2_7b 1 20.84 20.84 0.01%
qwen1.5-7b 1 23.56 23.58 -0.09%
phi3-3.8b 1 26.72 26.72 0.01%
llama3-8b 1 21.69 21.80 -0.50%
whisper-large-encoder 1 10.18 10.18 -0.00%
whisper-large-decoder 1 104.90 105.30 -0.38%
mistral-7b 1 23.75 23.78 -0.12%
FLUX.1-schnell 1 758.86 755.22 0.48%

Regressions detected 🔴

* No develop baseline was found for this PR's branch point; compared against the latest available develop run instead.

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

gh-app-migraphx-bot-pr-write Bot commented Aug 8, 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
distilgpt2_fp16 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

@pfultz2
pfultz2 marked this pull request as ready for review August 16, 2026 01:50
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.

2 participants