[Bug][TIR] VectorizeLoop silently miscompiles lane-private AllocBuffer inside a vectorized loop by splitting producer/consumer into separate scalar loops
Los mantenedores suelen responder en 3 días
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 49/100
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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).
- Lenguaje dominante
- Python
- Estrellas
- 13.9k
- Forks
- 4.1k
- Merge medio
- 4 d 22 h
- PR fusionados (30 d)
- 22
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de apache/tvm
-
[Bug] [Relax] `relax.op.unique(return_inverse=True)` returns an input-shaped inverse for N-D input when `axis` is NonePosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 3 días
-
[Bug][TOPI] `topi.scanop` (`cumsum` / `cumprod`) performs out-of-bounds write/read on empty tensorsAbiertoneeds-triage type: bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
Los mantenedores suelen responder en 3 días
-
[Bug] [Relax] take_backward does not normalize negative axis causing heap OOB write and wrong gradientsPosiblemente ocupada @pierceluu10 la tomó hace 4 días. Abiertoneeds-triage type: bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 3 días
-
[Bug][Relax][ONNX] NonZero returns the wrong output shape for scalar inputsPosiblemente ocupada @tandede la tomó hace 9 días. Abiertoneeds-triage type: bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
Los mantenedores suelen responder en 3 días
-
needs-triage type: bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
apache/tvm#21043 · 1 comentario ·
Los mantenedores suelen responder en 3 días
Todos los issues de apache/tvm
Issues similares
-
Dificultad 1/5 1-3 horas Aptitud para principiantes 78/100
web-push-libs/pywebpush#216 · 1 comentario ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
AgriciDaniel/claude-seo#572 ·
Los mantenedores suelen responder en 5 días
-
area:print-dispatch
Dificultad 2/5 1-3 horas Aptitud para principiantes 92/100
Los mantenedores suelen responder en 1 día
-
area: docs domain: technical-writing good first issue type: documentation
Dificultad 2/5 1-3 horas Aptitud para principiantes 80/100
Deepak3699/Ai_Mentor#919 ·
Los mantenedores suelen responder en 2 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día