Skip to content

Commit 4ad33b9

Browse files
committed
[ET-VK] Avoid the near-square local work group for the tiled linear on Adreno
Adreno drivers miscompute linear_tiled for 8x8x1 and 4x16x1 local work groups: entire work groups intermittently write garbage while every other block is bit-exact. The shader has no shared memory and no barriers and its invocations are independent, so the result cannot legitimately depend on the group shape. Use a 2:1 x:y shape (16x4x1 at the default 64 threads) on Adreno and keep the square shape elsewhere. Fixes #22327
1 parent c27baa8 commit 4ad33b9

1 file changed

Lines changed: 29 additions & 1 deletion

File tree

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

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,34 @@ vkapi::ShaderInfo pick_linear_shader(
6565
return VK_KERNEL_FROM_STR(kernel_name);
6666
}
6767

68+
// Adreno drivers miscompute this shader for some local work group shapes. With
69+
// the default 8x8x1 group (and with 4x16x1), entire work groups intermittently
70+
// write garbage: at M = 1500, K = N = 384 roughly 10-20% of executions produce
71+
// a handful of wholly corrupted 32x32 output blocks while every other block is
72+
// bit-exact. The shader has no shared memory and no barriers and its
73+
// invocations are independent, so its result cannot legitimately depend on the
74+
// group shape. 16x4x1, 32x2x1, 64x1x1, 2x32x1 and 1x64x1 were all correct over
75+
// 60 executions each; only the two near-square shapes fail. See #22327.
76+
//
77+
// A 2:1 x:y shape yields 16x4x1 at the default 64 threads and costs ~1.5% on a
78+
// Whisper encoder compared to 8x8x1, far less than the wider shapes (64x1x1 is
79+
// +34%). Non-Adreno devices keep the square shape.
80+
LocalWorkGroup pick_linear_lwg(
81+
ComputeGraph* graph,
82+
const vkapi::ShaderInfo& shader,
83+
const GlobalWorkGrid& gwg,
84+
const std::vector<ArgGroup>& args,
85+
const std::vector<ValueRef>& resize_args) {
86+
if (!graph->device_is_adreno()) {
87+
return pick_xy_square_lwg(graph, shader, gwg, args, resize_args);
88+
}
89+
LocalWorkGroup lwg(
90+
LwgShape(2u, 1u, 0u),
91+
graph->context()->adapter_ptr()->recommended_lwg_nthreads());
92+
lwg.fit_to_global(gwg);
93+
return lwg;
94+
}
95+
6896
GlobalWorkGrid pick_linear_gwg(
6997
ComputeGraph* graph,
7098
const vkapi::ShaderInfo& shader,
@@ -124,7 +152,7 @@ void add_linear_tiled_node(
124152
graph,
125153
pick_linear_shader,
126154
pick_linear_gwg,
127-
pick_xy_square_lwg,
155+
pick_linear_lwg,
128156
// Inputs and Outputs
129157
{{out, vkapi::kWrite}, {read_inputs, vkapi::kRead}},
130158
// Shader params buffers

0 commit comments

Comments
 (0)