[BUG]: DLPack tensors may be released before async launch work is finished
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 52/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 静か
- 領域
- backend, performance
調査の方向性
cext/tile_kernel.cpp で arrayrepr_dlpack() を arrayrepr_dlpack_common() 経由で launch() まで追跡し、カプセルが削除されるタイミングと cuLaunchKernelEx() が呼び出されるタイミングを比較することから始めます。最後の Owner を解放するか、メモリをプールに返す Deleter を持つ Producer を使って、ライフタイムの挙動を検証します。完了条件は、非同期の launch 作業がその使用を安全に終えるまで managed tensor が保持されることと、汎用 DLPack パスをカバーすることです。
索引モデルが issue の本文から書いたものです。
説明
Version
current main checkout (0477a34 locally); this code path appears to date back to the initial public import as well
CUDA Toolkit Version
not pinned yet; this came from source review rather than a runtime repro on a specific toolkit version
Which installation method(s) does this occur on?
Source
Describe the bug
I think the generic DLPack launch path is releasing consumed DLManagedTensor objects too early.
In cext/tile_kernel.cpp, arrayrepr_dlpack_common() renames the capsule to "used_dltensor" and then immediately calls tensor->deleter(tensor). That happens while kernel arguments are still being prepared, before prepare_launch() returns, and before cuLaunchKernelEx() is called.
For generic __dlpack__ objects, arrayrepr_dlpack() also calls __dlpack__(stream=-1), so the producer is explicitly being told not to synchronize.
My understanding of the DLPack ownership/lifetime contract is that once the consumer takes ownership of the capsule, it should keep the managed tensor alive until the consumer is actually done with it. Releasing it during argument parsing looks wrong on its own, and in the async CUDA launch path it seems like it could become a stale-pointer / premature-release problem for producers that rely on the deleter to hold the export alive until consumer work has safely passed.
What made me look twice is that there is already a comment in the code saying this is "technically an incorrect implementation" and suggesting an event-based deferred release after launch.
The control flow I am looking at is:
arrayrepr_dlpack()calls__dlpack__(stream=-1)arrayrepr_dlpack_common()reads the pointer, renames the capsule, and immediately calls the deleter- the actual kernel enqueue happens later in
launch()viacuLaunchKernelEx()
Minimum reproducible example
I do not have a clean runtime repro yet. I found this during code review because the control flow itself looks off:
1. producer returns a DLPack capsule
2. cuTile reads the exported pointer
3. cuTile immediately calls the DLPack deleter
4. the CUDA kernel launch happens afterwards, asynchronously
The repro shape I would expect to fail is a producer whose deleter drops the last owner or returns memory to a pool before the launched kernel has actually finished using the pointer.
Relevant log output
none yet
Full env printout
not available yet
Other/Misc.
Code pointers on current main:
cext/tile_kernel.cpp:arrayrepr_dlpack_common()cext/tile_kernel.cpp:arrayrepr_dlpack()cext/tile_kernel.cpp:launch()
If I am reading the intent correctly, it seems like the managed tensor probably needs to stay alive until launch work on the relevant stream is safely past the point where the producer can release it, rather than being deleted during argument extraction.
Happy to help with a repro if that would be useful.
- 主要言語
- Python
- スター
- 2.2k
- フォーク
- 155
- PR マージ指標
- 30日以内にマージされた PR はありません
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
NVIDIA/cutile-python のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
NVIDIA/cutile-python#105 · コメント 2 件 ·
-
bug status: needs-triage
難易度 3/5 1〜2日 初心者へのやさしさ 68/100
NVIDIA/cutile-python#102 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 68/100
NVIDIA/cutile-python#101 ·
-
bug
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
NVIDIA/cutile-python#97 · コメント 1 件 ·
-
bug
難易度 4/5 3〜5日 初心者へのやさしさ 52/100
NVIDIA/cutile-python#96 · コメント 1 件 ·
NVIDIA/cutile-python の issue をすべて見る
似ている issue
-
essnmx good first issue
難易度 1/5 1時間未満 初心者へのやさしさ 95/100
-
[Feature] 奇物选择添加优先级 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
syfoud/Simulated_Scepter#174 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
Giskard-AI/giskard-oss#2840 · コメント 1 件 ·
-
A claim comment carrying the issue number is silently declined while the workflow reports success オープンarea: repo bug perceived difficulty: 2
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
yeti-platform/yeti#1380 ·