[Bug][TIR] `s_tir.Schedule.cache_read` omits domain bounds predicate on shifted conditional reads, causing negative-index heap buffer underflow (`SIGABRT`/`SIGSEGV`)

Abierto
#21,124 0 comentarios 0 reacciones 0 asignados Ver en GitHub

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
57/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
cpp, python
Área
compilers

Línea de trabajo

Start in src/s_tir/schedule/primitive/cache_read_write.cc, in MakeCacheStage, and compare its cache block predicate with predicate generation in ComputeAt. Use the supplied reproduction to inspect the scheduled B_local block and confirm the missing bounds predicate causes the negative index. Done means the cache copy preserves bounds safety and the reproduction exits successfully with the expected results.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

needs-triage type: bug
Expected behavior

Applying valid S-TIR primitives (split, compute_at, cache_read) to a producer-consumer PrimFunc where the consumer conditionally reads a shifted index (T.if_then_else(4 <= v0, B[v0 - 4, v1], A[v0, v1])) must preserve bounds safety and produce identical results (sum=12288.0, exit code 0).

Actual behavior

s_tir.Schedule.cache_read generates an unguarded B_local cache-copy block with v0 = T.axis.spatial(2, ax0 - 4 + ax0_1) and predicate = true (missing T.where(4 <= ax0)), even though the adjacent compute_at producer block in the same loop correctly carries T.where(4 <= ax0).
After CompactBufferAllocation, B and B_local are compacted to (1024,) and unconditionally accessed at negative indices -4096..-1 for ax0 in 0..3:

B_local[ax0 * 1024 + ax1 - T.max(0, ax0 - 4) * 1024 - 4096] = B[...]

At runtime this underflows the heap allocation, corrupting TVM's WorkspacePool and glibc heap metadata and crashing with SIGABRT (corrupted double-linked list / double free or corruption (out)) or SIGSEGV depending on heap layout.

Environment
  • TVM: 0.27.0 (7b5acb32bd271342a24130f4ef439ff6c2e52c6c)
  • Upstream status: verified still unfixed on apache/tvm main (84657c01e5d3672cfd299bd3d5c77bff3888a1a9, 2026-12-02)
  • 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 slice_then_concat(
    X: T.Buffer((T.int64(5), T.int64(2048)), "float32"),
    A: T.Buffer((T.int64(4), T.int64(2048)), "float32"),
    C: T.Buffer((T.int64(6), T.int64(2048)), "float32"),
):
    B = T.sblock_alloc_buffer((T.int64(2), T.int64(2048)), "float32")
    for ax0, ax1 in T.grid(T.int64(2), T.int64(2048)):
        with T.sblock("slice"):
            v0, v1 = T.axis.remap("SS", [ax0, ax1])
            B[v0, v1] = X[v0 + T.int64(3), v1]
    for ax0, ax1 in T.grid(T.int64(6), T.int64(2048)):
        with T.sblock("concat"):
            v0, v1 = T.axis.remap("SS", [ax0, ax1])
            C[v0, v1] = T.if_then_else(T.int64(4) <= v0, B[v0 - T.int64(4), v1], A[v0, v1])
sch = s_tir.Schedule(slice_then_concat)
blk_s = sch.get_sblock("slice")
blk_c = sch.get_sblock("concat")
_, l1 = sch.get_loops(blk_c)
l1_o, _ = sch.split(l1, factors=[None, 1024])
sch.compute_at(blk_s, l1_o, preserve_unit_loops=True)
sch.cache_read(blk_c, 0, "local")
f = tvm.compile(sch.mod, target="llvm")
f(
    tvm.runtime.tensor(np.ones((5, 2048), "float32")),
    tvm.runtime.tensor(np.ones((4, 2048), "float32")),
    tvm.runtime.tensor(np.zeros((6, 2048), "float32")),
)
# Crashes with SIGABRT (e.g. corrupted double-linked list / double free or corruption) or SIGSEGV
Suggested fix

In src/s_tir/schedule/primitive/cache_read_write.cc (MakeCacheStage), derive the SBlockRealize predicate from the domain bounds of each cache block iter var (0 <= iter_value < dom->extent, matching compute_at / ComputeAt predicate generation) rather than hardcoding IntImm::Bool(true).

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

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de apache/tvm

Todos los issues de apache/tvm

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.