Skip to content

Fix seg fault when splitting non-fusible MLIR modules - #5187

Open
justinrosner wants to merge 4 commits into
developfrom
1209-fix-seg-fault
Open

Fix seg fault when splitting non-fusible MLIR modules#5187
justinrosner wants to merge 4 commits into
developfrom
1209-fix-seg-fault

Conversation

@justinrosner

Copy link
Copy Markdown
Contributor

Motivation

When compiling fused gpu::mlir_op modules (gemm/conv + pointwise), MIGraphX checks whether the module can remain fused for a given rocMLIR tuning config via is_module_fusible(). If the config is not fusible, most notably when splitKFactor > 1 + certain output fusions, the compiler falls back to splitting the module at a boundary computed by find_final_split(). When trying to do this split MIGraphX could dereference an invalid iterator that would lead to a seg fault.

Technical Details

find_final_split() could dereference an invalid iterator when:

  • get_output_path() returned fewer than two instructions
  • std::adjacent_find() found no valid split edge and returned end().

This is separate from #5144, which validates the pointwise submodule after a successful split. This PR fixes the crash that occurred during split-point selection.

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.

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

Fixes a GPU compilation crash when rocMLIR reports a fused gpu::mlir_op module as non-fusible and MIGraphX falls back to splitting the fused module. The change hardens split-point selection (find_final_split) to avoid invalid iterator dereferences, and adds a GPU regression test that exercises the previously-crashing split paths.

Changes:

  • Add guards in find_final_split() to handle short output paths and the “no split edge found” case without dereferencing end().
  • Add a new GPU test that compiles fused MLIR modules under a non-fusible split-K tuning configuration to ensure no split-time crash.

Reviewed changes

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

File Description
src/targets/gpu/jit/mlir.cpp Adds defensive handling in split-point selection to prevent iterator invalidation/dereference crashes during MLIR module splitting.
test/gpu/mlir_split_fusion.cpp Adds GPU regression coverage for split-K non-fusible MLIR module splitting paths that previously could segfault.

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

Comment thread test/gpu/mlir_split_fusion.cpp Outdated
Comment thread test/gpu/mlir_split_fusion.cpp Outdated
@gh-app-migraphx-bot-pr-write

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

Copy link
Copy Markdown
Test Batch New Rate (358629) Old Rate (3a503c)* Diff Status
torchvision-resnet50 64 3,299.19 3,264.92 1.05%
torchvision-resnet50_fp16 64 7,885.34 7,548.67 4.46%
torchvision-densenet121 32 2,490.19 2,483.99 0.25%
torchvision-densenet121_fp16 32 5,014.97 5,004.24 0.21%
torchvision-inceptionv3 32 2,059.43 2,058.51 0.04%
torchvision-inceptionv3_fp16 32 4,449.48 4,416.99 0.74%
cadene-inceptionv4 16 818.04 820.61 -0.31%
cadene-resnext64x4 16 784.85 782.78 0.26%
slim-mobilenet 64 8,376.76 8,386.36 -0.11%
slim-nasnetalarge 64 229.30 228.86 0.19%
slim-resnet50v2 64 3,229.71 3,180.91 1.53%
bert-mrpc-onnx 8 1,170.14 1,168.84 0.11%
bert-mrpc-tf 1 496.30 498.63 -0.47%
pytorch-examples-wlang-gru 1 386.53 473.35 -18.34% 🔴
pytorch-examples-wlang-lstm 1 547.82 384.83 42.35% 🔆
torchvision-resnet50_1 1 1,053.97 1,046.63 0.70%
cadene-dpn92_1 1 448.70 437.32 2.60%
cadene-resnext101_1 1 363.70 365.89 -0.60%
onnx-taau-downsample 1 842.47 844.09 -0.19%
dlrm-criteoterabyte 1 32.27 32.42 -0.48%
dlrm-criteoterabyte_fp16 1 51.61 51.80 -0.37%
agentmodel 1 14,863.35 9,209.12 61.40% 🔆
unet_fp16 2 58.36 58.80 -0.74%
resnet50v1_fp16 1 1,432.62 1,366.11 4.87%
resnet50v1_int8 1 1,773.26 1,883.96 -5.88% 🔴
bert_base_cased_fp16 64 1,099.18 1,098.16 0.09%
bert_large_uncased_fp16 32 347.28 345.59 0.49%
bert_large_fp16 1 207.04 206.59 0.22%
distilgpt2_fp16 16 2,099.20 2,092.89 0.30%
yolov5s 1 553.86 558.33 -0.80%
tinyllama 1 45.83 45.83 -0.01%
vicuna-fastchat 1 44.25 44.20 0.11%
whisper-tiny-encoder 1 413.42 411.87 0.37%
whisper-tiny-decoder 1 410.72 408.48 0.55%
llama2_7b 1 20.86 20.84 0.13%
qwen1.5-7b 1 23.64 23.58 0.26%
phi3-3.8b 1 28.33 26.72 6.03% 🔆
llama3-8b 1 22.73 21.80 4.25%
whisper-large-encoder 1 10.17 10.18 -0.08%
whisper-large-decoder 1 106.96 105.30 1.57%
mistral-7b 1 23.81 23.78 0.16%
FLUX.1-schnell 1 792.31 755.22 4.91%

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

Copy link
Copy Markdown
Test Status Result
bert-mrpc-onnx PASSED: MIGraphX meets tolerance
bert-mrpc-tf ERROR - check error output
traceback
Traceback (most recent call last):
File "/src/AMDMIGraphX/tools/accuracy/accuracy_checker.py", line 377, in
main()
File "/src/AMDMIGraphX/tools/accuracy/accuracy_checker.py", line 313, in main
import tensorflow as tf
File "/usr/local/lib/python3.12/dist-packages/tensorflow/init.py", line 40, in
from tensorflow.python import pywrap_tensorflow as _pywrap_tensorflow # pylint: disable=unused-import
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/dist-packages/tensorflow/python/pywrap_tensorflow.py", line 37, in
self_check.preload_check()
File "/usr/local/lib/python3.12/dist-packages/tensorflow/python/platform/self_check.py", line 63, in preload_check
from tensorflow.python.platform import _pywrap_cpu_feature_guard
ImportError: libnuma.so.1: cannot open shared object file: No such file or directory
pytorch-examples-wlang-gru 🔴 FAILED: MIGraphX is not within tolerance - check verbose output
pytorch-examples-wlang-lstm 🔴 FAILED: MIGraphX is not within tolerance - check verbose output
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 🔴 FAILED: MIGraphX is not within tolerance - check verbose output
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 commented Aug 25, 2026

Copy link
Copy Markdown
Collaborator

I dont know about the unit tests, but can you add the verify tests that you had in the other PR? That got us coverage as well for this.

@justinrosner

justinrosner commented Aug 26, 2026

Copy link
Copy Markdown
Contributor Author

I dont know about the unit tests, but can you add the verify tests that you had in the other PR? That got us coverage as well for this.

I assume you are talking about the tests from #5064? I'm not sure if they would actually give us coverage for the fixes in this PR. Those tests cover picking the right split point when one exists, whereas this PR covers the cases where there isn't one.

@pfultz2

pfultz2 commented Aug 26, 2026

Copy link
Copy Markdown
Collaborator

I dont know about the unit tests, but can you add the verify tests that you had in the other PR? That got us coverage as well for this.

I assume you are talking about the tests from #5064? I'm not sure if they would actually give us coverage for the fixes in this PR. Those tests cover picking the right split point when one exists, whereas this PR covers the cases where there isn't one.

OK but I dont see how this would happen as it should always have a gemm or convolution. And the unit tests show cases that are pointwise-only which would never happen.

@justinrosner

Copy link
Copy Markdown
Contributor Author

I dont know about the unit tests, but can you add the verify tests that you had in the other PR? That got us coverage as well for this.

I assume you are talking about the tests from #5064? I'm not sure if they would actually give us coverage for the fixes in this PR. Those tests cover picking the right split point when one exists, whereas this PR covers the cases where there isn't one.

OK but I dont see how this would happen as it should always have a gemm or convolution. And the unit tests show cases that are pointwise-only which would never happen.

The unit tests all have a GEMM (they all call the make_dot_graph helper).

@causten causten added the high priority A PR with high priority for review and merging. label Sep 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

high priority A PR with high priority for review and merging.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants