[Bug] ThreadStorageSync Pass must be put after MergeSharedMemory Pass #17439
Labels
needs-triage
PRs or issues that need to be investigated by maintainers to find the right assignees to address it
type: bug
In our current lowering pipeline, ThreadSync is placed before the MergeSharedMemoryAllocations Pass, which may lead to unknown behaviors because MergeSharedMemoryAllocations will modify the buffer access region.
https://github.com/apache/tvm/blob/main/src/driver/driver_api.cc#L585-L613
Given a simple matmul schedule pipeline:
The ThreadSync pass will not inject a
tvm_storage_sync
before Store C_shared, that's make sense because C_shared is a non-interfering memory with A_shared and B_shared.However, when we merge shared memory, C_shared will reuse the memory space with
A_shared
andB_shared
.which is supposed to be a tvm_storage_sync statement before
Store C_shared
, otherwise may lead to a unknown behavior (random and small incorrect produce) because the Store C_shared may change the elements in Load A_shared.And the solution is quite simple, put the ThreadStorageSync Pass after MergeSharedMemory Pass.
The text was updated successfully, but these errors were encountered: