Skip to content

[S-TIR] Fix Segfault when applying Parallel during TIR schedule rewriting#19403

Open
cchung100m wants to merge 3 commits intoapache:mainfrom
cchung100m:issue-18424
Open

[S-TIR] Fix Segfault when applying Parallel during TIR schedule rewriting#19403
cchung100m wants to merge 3 commits intoapache:mainfrom
cchung100m:issue-18424

Conversation

@cchung100m
Copy link
Copy Markdown
Contributor

@cchung100m cchung100m commented Apr 14, 2026

Hi Commiters,

This PR is trying to fix issues #18424. Any suggestions would be appreciated if you are available.

Root Cause

Unsafe dynamic-shape dereferences in AdjustParallelVectorize The code assumed IntImm for buffer shape / loop extent and dereferenced directly. With dynamic shapes, as() can be null, which can segfault before any try/catch handles it.

Solution

Replaced unsafe IntImm assumptions with null checks and GetLoopIntExtent(...); if contiguous analysis is not possible, conservatively disables that path instead of dereferencing null.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request wraps the logic within the Apply method in a try-catch block to handle runtime::Error. Feedback indicates that AdjustParallelVectorize contains unsafe dereferences that could lead to segmentation faults when encountering dynamic shapes, which would not be caught by this block. Additionally, the new try-catch block is considered redundant with the caller's error handling and should include logging to avoid suppressing error messages.

@cchung100m
Copy link
Copy Markdown
Contributor Author

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces safety checks for non-integer buffer shapes and loop extents within the AdjustParallelVectorize function, preventing potential crashes when dealing with dynamic shapes. The code now correctly identifies when contiguous memory access cannot be statically analyzed and resets the fusion count. A review comment suggests optimizing the buffer access loop by breaking early once a non-analyzable access is encountered, as the minimum fusion count is already reached.

@cchung100m cchung100m marked this pull request as ready for review April 14, 2026 15:49
@cchung100m
Copy link
Copy Markdown
Contributor Author

Hi @tlopex @mshr-h ,

This PR is trying to fix issues #18424. Any suggestions would be appreciated if you are available. 😄

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