[Bug][TIR] VectorizeLoop silently miscompiles lane-private AllocBuffer inside a vectorized loop by splitting producer/consumer into separate scalar loops
I maintainer di solito rispondono entro 3 giorni
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 49/100
Direzione di ricerca
Start with src/tirx/transform/vectorize_loop.cc, especially the Vectorizer handling of AllocBufferNode and Scalarize around line 1114. Use the provided S-TIR schedule and reproduction script to confirm the incorrect output, then inspect nearby vectorization tests for coverage. Done means compilation preserves the unscheduled function’s output for this case and the regression is covered by a test.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Expected behavior
Compiling a valid S-TIR schedule (cache_write("local") -> reverse_compute_at -> split -> vectorize) with default tvm.compile(mod, target="llvm") must preserve the semantics of the unscheduled PrimFunc, outputting [1, 2, 3, ..., 18].
Actual behavior
tirx.transform.VectorizeLoop (src/tirx/transform/vectorize_loop.cc) silently miscompiles the function to output [4, 4, 4, 4, 8, 8, 8, 8, 12, 12, 12, 12, 16, 16, 16, 16, 18, 18].
Immediately before VectorizeLoop, PlanAndUpdateBufferAllocationLocation + CompactBufferAllocation legally place a lane-private scalar buffer B_local = T.alloc_local((1,)) inside for ax0_1 in T.vectorized(4):. Because Vectorizer does not handle AllocBufferNode (neither expanding its allocation by var_lanes_ nor forcing the enclosing SeqStmt to scalarize as a unit), each predicated IfThenElse independently calls Scalarize(stmt) (vectorize_loop.cc:1114). This fissions the body into two separate for ax0_1_s in range(4) loops that share the single size-1 B_local[0] slot: all 4 lanes overwrite B_local[0] in the first loop, and all 4 lanes read back only the final lane's value in the second loop.
Environment
- TVM:
0.27.0(7b5acb32bd271342a24130f4ef439ff6c2e52c6c) - Upstream status: verified still unfixed on
apache/tvmmain(84657c01e5d3672cfd299bd3d5c77bff3888a1a9, 2026-12-02) / submoduleapache/tvm-tirx(f43b3030d33196d3a5f21e56b37549a6d3a5c70b, path3rdparty/tvm-tirx/src/tirx/transform/vectorize_loop.cc) - OS: Linux x86_64
Steps to reproduce
import numpy as np
import tvm
from tvm import s_tir
from tvm.script import tirx as T
@T.prim_func(s_tir=True)
def copy18_1d(A: T.Buffer((1, 18), "float32"), B: T.Buffer((1, 18), "float32")):
for ax0 in range(18):
with T.sblock("copy"):
v0 = T.axis.spatial(18, ax0)
B[0, v0] = A[0, v0]
sch = s_tir.Schedule(copy18_1d)
blk = sch.get_sblock("copy")
(loop,) = sch.get_loops(blk)
cw = sch.cache_write(blk, 0, "local")
sch.reverse_compute_at(cw, loop, preserve_unit_loops=True)
_, inner = sch.split(sch.get_loops(blk)[-1], factors=[None, 4])
sch.vectorize(inner)
x = np.arange(1, 19, dtype=np.float32).reshape(1, 18)
out = tvm.runtime.tensor(np.zeros_like(x))
tvm.compile(sch.mod, target="llvm")(tvm.runtime.tensor(x), out)
print(out.numpy()[0])
# Actual: [ 4. 4. 4. 4. 8. 8. 8. 8. 12. 12. 12. 12. 16. 16. 16. 16. 18. 18.]
# Expected: [ 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18.]
Suggested fix
In src/tirx/transform/vectorize_loop.cc, either:
- When a
SeqStmtinside aForKind::kVectorizedloop contains anAllocBufferwhose buffer is written/read across child statements, scalarize the entireAllocBufferscope together (instead of fissioning individual child statements around a shared size-1 buffer), OR - Expand lane-private
AllocBufferallocations inside a vectorized loop byvar_lanes_(or rejectvectorizeins_tir.Schedulewhen a loop body contains lane-private local buffers that cannot be widened).
- Lingua principale
- Python
- Stelle
- 13.9k
- Fork
- 4.1k
- Merge medio
- 4g 22h
- PR unite (30g)
- 22
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di apache/tvm
-
[Bug] [Relax] `relax.op.unique(return_inverse=True)` returns an input-shaped inverse for N-D input when `axis` is NoneForse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 3 giorni
-
[Bug][TOPI] `topi.scanop` (`cumsum` / `cumprod`) performs out-of-bounds write/read on empty tensorsApertaneeds-triage type: bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 3 giorni
-
[Bug] [Relax] take_backward does not normalize negative axis causing heap OOB write and wrong gradientsForse già presa @pierceluu10 l’ha presa 4 giorni fa. Apertaneeds-triage type: bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 3 giorni
-
[Bug][Relax][ONNX] NonZero returns the wrong output shape for scalar inputsForse già presa @tandede l’ha presa 9 giorni fa. Apertaneeds-triage type: bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
I maintainer di solito rispondono entro 3 giorni
-
needs-triage type: bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
apache/tvm#21043 · 1 commento ·
I maintainer di solito rispondono entro 3 giorni
Issue simili
-
Difficoltà 1/5 1-3 ore Idoneità per principianti 78/100
web-push-libs/pywebpush#216 · 1 commento ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
AgriciDaniel/claude-seo#572 ·
I maintainer di solito rispondono entro 5 giorni
-
area:print-dispatch
Difficoltà 2/5 1-3 ore Idoneità per principianti 92/100
I maintainer di solito rispondono entro 1 giorno
-
area: docs domain: technical-writing good first issue type: documentation
Difficoltà 2/5 1-3 ore Idoneità per principianti 80/100
Deepak3699/Ai_Mentor#919 ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno