Repository navigation
Description
We found this with Volta, a verifier we develop for PTX kernels: it symbolically executes a kernel's compiled PTX for a concrete launch and checks the recorded execution for data races, out-of-bounds accesses and synchronization errors, and can prove a kernel's outputs equal to a specification. This report comes from that analysis of the sm_100a PTX of TensorRT OSS main at 7fe18f0, not from a GPU run. It may be the cause of #4005.
Description
GatherAddGatherTransposeAddMul_fused (disentangledKernel.cu:84) has no bounds check, but DisentangledAttentionPlugin::enqueueType rounds its grid up to whole 64 x 64 tiles (disentangledAttentionPlugin.cpp:250):
dim3 gridOptimized(
(dimResult.z - 1) / kDISENTANGLED_TILESIZE + 1, (dimResult.y - 1) / kDISENTANGLED_TILESIZE + 1, dimResult.x);Every thread of a tile gathers data2 into the shared tile (:161), reads data0/data1 (:211) and writes result[IND(i, j + ty, k, dimResult)] (:245), where IND(i, j, k) = (i * S + j) * S + k, for every j and k up to the end of the tile. When the sequence length S is not a multiple of 64:
- a thread with
k >= Swrites element(j + 1, k - S), which the thread that owns it also writes, with a different value; which write lands depends on scheduling, so the result changes from run to run; - a thread with
j >= Swrites into the next head's rows, or past the end ofresultfor the last head, and readsdata0/data1/data2past their rows the same way.
The plugin accepts any S: configurePlugin and supportsFormatCombination check only types, formats and ranks.
What Volta reports, for the fp32 kernel, block (64, 4), span 128 (every relative distance in the preserved region):
BH = 2, S = 40, block (0, 0, 0): a write-write conflict onresult[40]between thread 40 (j = 0, k = 40) and thread 64 (j = 1, k = 0), and the same on the elements 40 apart after it.BH = 1, S = 40: the run stops at an out-of-bounds read ofdata2(row 40 of 40).S = 64(one full tile): race free, and proved equal to(c2c + c2p + p2c) * factoron all 4,096 outputs.
Suggested fix
Skip the out-of-range threads, e.g. guard the data2 gather and tile store by j + ty < dimData2.y && k < dimResult.y, and in the second loop continue when j + ty >= dimResult.y || k >= dimResult.z before the data0/data1 reads and the result write. With that change, Volta proves the kernel equal to the formula at S = 40 (all 1,600 outputs) and finds it race free at S = 40 with two heads and at S = 100.
Environment
TensorRT Version: OSS main at 7fe18f0 (TensorRT 11.5 OSS release)
NVIDIA GPU: none (static analysis of the sm_100a PTX)
CUDA Version: nvcc 13.2, -arch=sm_100a -O3 -std=c++20
Steps To Reproduce
Run the plugin with inputs [BH, S, S], [BH, S, 2 * span], [BH, S, 2 * span] for an S that is not a multiple of 64 (e.g. S = 40, or the 4059 of #4005): result should differ between runs and from the unfused computation, and compute-sanitizer --tool memcheck should report the last head's out-of-bounds accesses.
We are investigating further and will update this issue.
Activity
Check 37 TensorRT plugin kernel launches with Volta and report three …