Skip to content

[DLight][CUDA] Fix undefined TX in GEMV broadcast epilogue#19970

Open
Nanmur wants to merge 1 commit into
apache:mainfrom
Nanmur:codex/fix-dlight-gemv-tx
Open

[DLight][CUDA] Fix undefined TX in GEMV broadcast epilogue#19970
Nanmur wants to merge 1 commit into
apache:mainfrom
Nanmur:codex/fix-dlight-gemv-tx

Conversation

@Nanmur

@Nanmur Nanmur commented Jul 9, 2026

Copy link
Copy Markdown

This PR fixes an undefined TX reference in the DLight GPU GEMV inner-reduction schedule.

The broadcast epilogue path splits fused epilogue loops and binds the inner loop to threadIdx.x, but it referenced TX, which is not defined in the surrounding scope or passed into the helper. This PR uses the existing TR tile factor, which is already used for the threadIdx.x direction in this schedule.

A regression test is added to cover the GEMV broadcast epilogue path.

Fixes #19969

Tests:

  • python -m pytest tests/python/s_tir/dlight/test_gpu_gemv.py -q
  • python -m pytest tests/python/s_tir/dlight/test_gpu_low_batch_gemv.py -q
  • python -m pytest tests/python/s_tir/dlight/test_gpu_reduction.py -q

Note: The branch is based on apache/tvm:main. Local main-branch test execution on this Windows machine could not be completed because the available compiled TVM library is from a v0.25 build and does not match the latest Python sources; the same tests passed in the matching local v0.25 environment before rebasing the patch to main.

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request updates the GPU GEMV schedule in python/tvm/s_tir/dlight/gpu/gemv.py by changing the split factor for the epilogue block from TX to TR. It also adds a new unit test test_gemv_broadcast_epilogue in tests/python/s_tir/dlight/test_gpu_gemv.py to validate this scheduling behavior. There are no review comments, so I have no feedback to provide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@tlopex tlopex left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for fixing this! The same undefined TX reference still exists in the LowBatchGEMV broadcast-epilogue path:

if is_broadcast_epilogue(sch, block, epilogue):
sch.reverse_compute_at(epilogue, bx)
sch.set_scope(block, 0, "shared")
_, _, _, *s = sch.get_loops(epilogue) # pylint: disable=invalid-name
_, tx = sch.split(sch.fuse(*s), factors=[None, TX])
sch.bind(tx, TAG_S)

TX is not defined anywhere in that file either, so this branch will fail with the same runtime error when reached. Since the resulting loop is bound to TAG_S, the corresponding existing tile factor appears to be TS:

_, ts = sch.split(sch.fuse(*s), factors=[None, TS])
sch.bind(ts, TAG_S)

The existing LowBatchGEMV tests do not trigger this broadcast-epilogue branch. Could we fix this occurrence as well and add a regression test for it?

@Nanmur Nanmur force-pushed the codex/fix-dlight-gemv-tx branch from 9837463 to 8e01616 Compare July 10, 2026 05:34
The GEMV and LowBatchGEMV inner-reduction schedules handle broadcast epilogues by splitting fused epilogue loops and binding the inner loop to a CUDA thread axis. These paths referenced TX, but TX is not defined in either schedule scope or passed into the inner scheduling helpers.

Use the existing tile factors for the corresponding bound axes: TR for GEMV's threadIdx.x path and TS for LowBatchGEMV's TAG_S path. Add regression tests covering both broadcast epilogue branches.
@Nanmur Nanmur force-pushed the codex/fix-dlight-gemv-tx branch from 8e01616 to e3738a7 Compare July 10, 2026 05:36
@Nanmur

Nanmur commented Jul 10, 2026

Copy link
Copy Markdown
Author

Thanks for catching this. I updated the PR to fix the LowBatchGEMV broadcast-epilogue path as well, replacing the undefined TX with TS for the loop bound to TAG_S, and added a regression test that covers this branch.

@yongwww yongwww closed this Jul 11, 2026
@yongwww yongwww reopened this Jul 11, 2026
@Nanmur

Nanmur commented Jul 11, 2026

Copy link
Copy Markdown
Author

@yongwww The current wasm/pr-head build checked out the latest commit e3738a7 after the brief close/reopen event. Its prepare stage completed successfully, and the build reached the Emscripten (emcc) step before the Jenkins EC2 worker went offline with ChannelClosedException; the job was aborted without a compilation or test failure. Could you please re-run the WASM check when convenient?

The LowBatchGEMV follow-up and regression test requested by @tlopex are included in e3738a7.

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][Dlight]DLight GPU GEMV fails with undefined TX in broadcast epilogue path

3 participants