[BUG][Ascend][PTO] ptodsl_compile.py crashes merge_jit_modules on multi-launch PrimFuncs containing a mixed Cube+Vector kernel
Maintainers usually reply within 3 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 43/100
Research direction
Start with tilelang/contrib/ptodsl_compile.py around the multi-kernel merge at line 68, then read tilelang/contrib/ptodsl/mixed_kernel.py around lines 60–63 to understand how mixed kernels are emitted. Reproduce the failure with the supplied clear_then_mixed_gemm example and inspect how vpto-split-cv-module handles flat modules before merging. Done means both Mixed + Vector/Cube and Mixed + Mixed multi-launch functions compile without module-style or init_core symbol errors.
Written by the indexing model from the issue text.
Description
Required prerequisites
- I have read the documentation https://tilelang.com.
- I have searched the Issue Tracker that this hasn't already been reported. (comment there if it has.)
What version of TileLang are you using?
0.1.16+gite4f18319 (main @ e4f18319, built from source with USE_ASCEND=ON USE_CUDA=OFF)
System information
- OS: Linux x86_64 (Ubuntu 24.04)
- Python:
3.12.3 - PyTorch:
2.15.0 - TileLang:
0.1.16+gite4f18319
Problem description
In CodeGenTileLangPTO, pure Vector or pure Cube T.Kernel launches emit @pto.jit(..., kernel_kind="vector"|"cube") (ModuleStyle.BACKEND_PARTITIONED), whereas mixed Cube+Vector kernels call tl.finalize_mixed_kernel(kernel) (tilelang/contrib/ptodsl/mixed_kernel.py:60-63), setting ModuleStyle.FLAT_AICORE.
When a single @T.prim_func contains two or more kernel launches (len(kernels) > 1) and at least one is a mixed kernel, tilelang/contrib/ptodsl_compile.py:68 unconditionally calls pto.merge_jit_modules(*kernels), which crashes in both cases:
- Mixed + Vector/Cube:
ValueError: merge_jit_modules() cannot mix flat and backend-partitioned PTODSL modules. - Mixed + Mixed: Each flat module defines
func.func private @init_core(), raisingValueError: merge_jit_modules() cannot merge duplicate function symbols in a flat module; assign distinct @pto.jit(name=...) values: ['"init_core"'].
Reproducible example code
import tempfile
from pathlib import Path
import tilelang
from tilelang.ascend import language as T
from tilelang.ascend.target import normalize_pto_target
from tilelang.contrib.pto_toolchain import compile_ptodsl_to_pto, parse_pto_kernel_names
@T.prim_func
def clear_then_mixed_gemm(
a: T.Tensor((16, 32), T.bfloat16),
b: T.Tensor((16, 32), T.bfloat16),
c: T.Tensor((16, 16), T.float32),
):
with T.Kernel(1), T.SimtVF(threads=16):
for i in T.Parallel(16):
c[i, 0] = 0.0
with T.Kernel(1):
acc = T.alloc_l0c((16, 16), T.float32)
a_l1 = T.alloc_l1((16, 32), T.bfloat16)
b_l1 = T.alloc_l1((16, 32), T.bfloat16)
ub = T.alloc_shared((8, 16), T.float32)
with T.Cube():
T.copy(a, a_l1)
T.copy(b, b_l1)
T.ascend_set_flag("MTE2_MTE1", 0)
T.ascend_wait_flag("MTE2_MTE1", 0)
T.gemm(a_l1, b_l1, acc, transpose_B=True, clear_accum=True)
T.ascend_set_flag("M_FIX", 0)
T.ascend_wait_flag("M_FIX", 0)
T.dual_copy(acc, ub)
T.ascend_cross_core_set_flag(4, "PIPE_FIX", 6)
T.ascend_cross_core_set_flag(4, "PIPE_FIX", 22)
with T.Vector() as sid:
T.ascend_cross_core_wait_flag(4, "PIPE_MTE3", 6)
T.copy(ub, c[sid * 8 : (sid + 1) * 8, :])
target = normalize_pto_target("pto")
with target, tilelang.tvm.transform.PassContext(config={tilelang.PassConfigKey.TL_ENABLE_AUTO_SCHEDULE: False}):
src = tilelang.lower(clear_then_mixed_gemm, target=target).kernel_source
with tempfile.TemporaryDirectory() as td:
compile_ptodsl_to_pto(src, parse_pto_kernel_names(src), Path(td) / "k.py", Path(td) / "k.pto")
Traceback
ValueError: merge_jit_modules() cannot mix flat and backend-partitioned PTODSL modules
Expected behavior
ptodsl_compile.py should partition flat mixed modules into backend-partitioned child builtin.modules (via builtin.module(vpto-split-cv-module)) before merging multi-kernel modules, so both Mixed + Vector/Cube and Mixed + Mixed multi-launch functions compile cleanly without module-style or @init_core symbol collisions.
Additional context
Running vpto-split-cv-module on flat modules before cloning child builtin.module ops isolates private helper symbols per sub-module and verifies cleanly in MLIR.
- Dominant language
- Python
- Stars
- 9.1k
- Forks
- 1k
- Avg merge
- 4d 21h
- Merged PRs (30d)
- 67
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from tile-ai/tilelang
-
arith ascend bug
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
tile-ai/tilelang#5173 · 2 comments · 1 reaction ·
Maintainers usually reply within 3 days
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
Maintainers usually reply within 3 days
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
Maintainers usually reply within 3 days
-
ascend bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
tile-ai/tilelang#5140 · 3 comments · 1 reaction ·
Maintainers usually reply within 3 days
-
ascend bug python
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
tile-ai/tilelang#5139 · 3 comments · 1 reaction ·
Maintainers usually reply within 3 days
All issues in tile-ai/tilelang
Similar issues
-
[Bug]: streaming_end_of_stream_only guardrails rescan the whole stream on every chunk - blocks event loopPossibly taken A pull request linked to this issue is open or already merged. Openbug llm translation
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
lanl/text-fetch#92 ·
Maintainers usually reply within 1 day
-
kind: for-triage
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
monumental-archive/.github#2284 ·
Maintainers usually reply within 1 day
-
good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 87/100
TanbirRamim/open-source-radar#761 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
ktwu01/benchmark-radar#1450 ·
Maintainers usually reply within 1 day