Skip to content

[FIX][S-TIR] Bind merged shared memory sizes before the merged allocation - #20955

Open
JonSnow1807 wants to merge 1 commit into
apache:mainfrom
JonSnow1807:issue-20870
Open

JonSnow1807 wants to merge 1 commit into
apache:mainfrom
JonSnow1807:issue-20870

Conversation

@JonSnow1807

Copy link
Copy Markdown

MergeSharedMemoryAllocations puts the merged allocation and the tensor views at the start of the launch body, but a shared.dyn shape can use a scalar bound later in the body. The merged size then uses the variable before its binding: check_well_formed fails, and the CUDA compile fails in MakePackedAPI with “variables (cse_v1,) are used, but are not passed in as API arguments”. An access offset that uses a later tensor’s size has the same problem.

This collects the pure scalar bindings of the launch body that always run (not under a condition, loop or assert), and places a copy of each one the merged size, offsets and view shapes need before the merged allocation, in dependency order. The original bindings are unchanged, and copying instead of substituting keeps long binding chains from growing the expressions.

Tests: three new tests, including a CUDA compile-and-run check against numpy. All three fail without the change, and the file passes 10 of 10 with it. s_tir and relax show the same failures as main. Run on an RTX PRO 4000 (sm_120), CUDA 12.8.

Fixes #20870

Code drafted by both human and AI, and reviewed by human.

…tion

MergeSharedMemoryAllocations puts the merged allocation and the tensor
views at the start of the launch body. When a shared.dyn shape uses a
scalar that is bound later in the body, the merged size and the view
type use the variable before its binding. check_well_formed fails, and
tvm.compile for CUDA fails in MakePackedAPI.

An access offset can have the same problem, when it uses the shape of a
tensor that is allocated after the access.

Collect the pure scalar bindings of the launch body that always run
(not under a condition, a loop or an assert). The merged size, the
offsets and the view shapes use copies of these bindings. The copies
are placed before the merged allocation, once each and in dependency
order. The original bindings do not change.

Fixes apache#20870

This branch has not been deployed

No deployments
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.

[Bug] [TIRx][CUDA] MergeSharedMemoryAllocations hoists a dynamic allocation above its size binding

1 participant