Skip to content

Commit b31b709

Browse files
committed
[ET-VK] Avoid the near-square local work group on Adreno
Adreno drivers miscompute the tiled GEMM family of shaders for 8x8x1 and 4x16x1 local work groups: entire work groups intermittently write garbage while every other block is bit-exact. These shaders have no shared memory and no barriers and their invocations are independent, so the result cannot legitimately depend on the group shape. Fix it in pick_xy_square_lwg, which all thirteen affected dispatches share: linear, matmul, conv2d_gemm, the pointwise convs, SDPA and the quantized variants. On Adreno use a 2:1 x:y shape, which yields 16x4x1 at the default 64 threads and is the cheapest correct shape measured; other vendors keep the square shape. Fixes #22327
1 parent c27baa8 commit b31b709

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

‎backends/vulkan/runtime/graph/ops/impl/Common.cpp‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,15 @@ LocalWorkGroup pick_required_lwg(
132132
return gwg.required_lwg_size();
133133
}
134134

135+
// Adreno drivers miscompute the tiled GEMM family of shaders for near-square
136+
// local work groups. With an 8x8x1 group (and with 4x16x1) entire work groups
137+
// intermittently write garbage while every other block is bit-exact. These
138+
// shaders have no shared memory and no barriers and their invocations are
139+
// independent, so the result cannot legitimately depend on the group shape.
140+
// A 2:1 x:y ratio, which yields 16x4x1 at the default 64 threads, is correct
141+
// across every run measured and is the cheapest correct shape. See #22327.
142+
const LwgShape kWideXLwg{2u, 1u, 0u};
143+
135144
LocalWorkGroup pick_xy_square_lwg(
136145
ComputeGraph* graph,
137146
const vkapi::ShaderInfo& shader,
@@ -142,7 +151,8 @@ LocalWorkGroup pick_xy_square_lwg(
142151
(void)args;
143152
(void)resize_args;
144153
LocalWorkGroup lwg(
145-
kSquareLwg, graph->context()->adapter_ptr()->recommended_lwg_nthreads());
154+
graph->device_is_adreno() ? kWideXLwg : kSquareLwg,
155+
graph->context()->adapter_ptr()->recommended_lwg_nthreads());
146156
lwg.fit_to_global(gwg);
147157
return lwg;
148158
}

0 commit comments

Comments
 (0)