[BUG][Ascend][PTO] ptodsl_compile.py crashes merge_jit_modules on multi-launch PrimFuncs containing a mixed Cube+Vector kernel

Open
#5,145 3 comments 1 reaction 0 assignees View on GitHub

Maintainers usually reply within 3 days

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
43/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
backend, compilers

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

ascend bug
Required prerequisites
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:

  1. Mixed + Vector/Cube: ValueError: merge_jit_modules() cannot mix flat and backend-partitioned PTODSL modules.
  2. Mixed + Mixed: Each flat module defines func.func private @init_core(), raising ValueError: 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

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from tile-ai/tilelang

All issues in tile-ai/tilelang

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.