[Bug] [TIRx] CompactBufferAllocation leaves a stale double_buffer_scope reference and causes InjectDoubleBuffer to fail
メンテナーはふだん 3 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
Start with CompactBufferAllocation and trace how it remaps the double_buffer_scope annotation in the provided PrimFunc. Compare its output with the buffer association after FlattenBuffer, then inspect InjectDoubleBuffer and the existing test in tests/python/s_tir/transform/test_s_tir_transform_inject_double_buffer.py. Done means default CPU compilation preserves the annotation's association with its allocated buffer and the reproducer compiles.
索引モデルが issue の本文から書いたものです。
説明
Expected behavior
Buffer-rebuilding passes should keep double_buffer_scope attached to the allocated buffer that its body actually accesses. The PrimFunc below should compile through the default CPU TIR pipeline without leaving a dangling annotation reference.
The input IR matches the unmodified shape, dtype, and computation in the official test_double_buffer_transform test in tests/python/s_tir/transform/test_s_tir_transform_inject_double_buffer.py: A is float32[16,32], B is float32[16], and the local cache has 32 elements. The official test applies InjectDoubleBuffer directly and checks the transformation; the reproducer below exercises that same input through the default compilation pipeline.
Actual behavior
Compilation fails in InjectDoubleBuffer:
File "src/s_tir/transform/inject_double_buffer.cc", line 265,
in DoubleBufferInjector::GetRemappedBuffer
TVM_FFI_ICHECK(stride.defined());
tvm.error.InternalError:
Check failed: (stride.defined()) is false:
A pass-by-pass trace identifies s_tir.CompactBufferAllocation as the first pass after which the annotation no longer refers to the allocated buffer. Its output has the following structure:
cache = T.alloc_buffer((32,))
cache_1 = T.Buffer((32,))
with T.attr(cache_1.data, "double_buffer_scope", 1):
for j in range(32):
cache[j] = A[i, j]
B[i] = T.float32(0.0)
for j in range(32):
B[i] = B[i] + cache[j]
The allocation and accesses use cache, while the annotation uses a distinct buffer variable cache_1 with no corresponding allocation. This was checked using both structural comparison of the attribute's data expression and object identity of its underlying buffer variable; it is not just a difference in printed names.
The stale reference survives until InjectDoubleBuffer. That pass obtains the double-buffer half-size from the associated AllocBuffer.shape[0]; the missing association leaves its internal stride undefined. This is not an unspecified input-tensor stride.
The following controls were reproduced in two fresh Python processes:
| Input A | Default compilation | First broken association | Local association control |
|---|---|---|---|
| float32[16,32], original official shape | Fails with the assertion above | CompactBufferAllocation | Target transformation and subsequent compilation succeed; output checks pass |
| float32[16,33] | Same failure | CompactBufferAllocation | Same successful control |
In both processes, applying FlattenBuffer directly to the original input, followed by InjectDoubleBuffer, succeeds and retains the correct buffer association. Thus the later FlattenBuffer snapshot should not be mistaken for the first point of failure.
For the local control, I captured the actual input immediately before InjectDoubleBuffer and, only in this one-allocation/one-annotation reproducer, rebound the annotation node to the actual allocation's data expression. I then applied InjectDoubleBuffer and compiled its result with further applications of that pass disabled. Random and exactly representable input checks passed, including different initial values of B. No shape, indexing, arithmetic, or tensor strides were changed.
Reassociating the annotation with the allocation eliminates the assertion in this reproducer, supporting the stale-reference diagnosis.
Environment
- TVM:
0.26.dev0+source.8f328e8 - Build-reported source revision:
8f328e802cfe5e41fcc8f5c17e7582b1c28bfce4 - LLVM:
15.0.7 - OS: Ubuntu 22.04.5 LTS, Linux
6.8.0-52-generic, x86_64 - CPU: Intel Core i9-13900K
- Python:
3.11.16 - Target:
{"kind": "llvm", "mtriple": "x86_64-pc-linux-gnu"} opt_level=2,tir_pipeline="default"- No disabled passes in the failing default compilation
- No GPU is required. The failure occurs during compilation, before any input arrays are needed.
Steps to reproduce
Save the following as repro.py and run python repro.py in the recorded TVM environment. This standalone script requires only TVM and uses the original official shape.
import tvm
from tvm.script import ir as I, tirx as T
@I.ir_module
class Module:
@T.prim_func(s_tir=True)
def main(
A: T.Buffer((16, 32), "float32"),
B: T.Buffer((16,), "float32"),
):
for i in range(16):
cache = T.alloc_buffer((32,), "float32")
with T.attr(cache.data, "double_buffer_scope", 1):
for j in range(32):
cache[j] = A[i, j]
B[i] = T.float32(0.0)
for j in range(32):
B[i] = B[i] + cache[j]
target = tvm.target.Target(
{"kind": "llvm", "mtriple": "x86_64-pc-linux-gnu"}
)
with tvm.transform.PassContext(opt_level=2):
tvm.compile(Module, target=target, tir_pipeline="default")
The exact script above was also executed separately and produced the expected stride.defined() failure. Changing the width and all corresponding loop/cache extents from 32 to 33 reproduces the same failure.
Triage
- needs-triage
- 主要言語
- Python
- スター
- 13.9k
- フォーク
- 4.1k
- 平均マージ
- 4日 22時間
- マージ済み PR(30日)
- 22
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
apache/tvm のほかの issue
-
[Bug] [Relax] `relax.op.unique(return_inverse=True)` returns an input-shaped inverse for N-D input when `axis` is None対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 3 日以内に返信
-
[Bug][TOPI] `topi.scanop` (`cumsum` / `cumprod`) performs out-of-bounds write/read on empty tensorsオープンneeds-triage type: bug
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 3 日以内に返信
-
[Bug] [Relax] take_backward does not normalize negative axis causing heap OOB write and wrong gradients対応中かも @pierceluu10 が 4 日前に担当しました。 オープンneeds-triage type: bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 3 日以内に返信
-
[Bug][Relax][ONNX] NonZero returns the wrong output shape for scalar inputs対応中かも @tandede が 9 日前に担当しました。 オープンneeds-triage type: bug
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
メンテナーはふだん 3 日以内に返信
-
needs-triage type: bug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 3 日以内に返信
似ている issue
-
難易度 1/5 1〜3時間 初心者へのやさしさ 78/100
web-push-libs/pywebpush#216 · コメント 1 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
AgriciDaniel/claude-seo#572 ·
メンテナーはふだん 5 日以内に返信
-
area:print-dispatch
難易度 2/5 1〜3時間 初心者へのやさしさ 92/100
メンテナーはふだん 1 日以内に返信
-
area: docs domain: technical-writing good first issue type: documentation
難易度 2/5 1〜3時間 初心者へのやさしさ 80/100
Deepak3699/Ai_Mentor#919 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信