Skip to content

[ET-VK] Minor dispatch improvement to conv2d dw op to improve performance. #11495

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,26 +60,25 @@ void main() {
const uint div_by_x = gl_GlobalInvocationID.x / out_limits_xy_scaled.x;
ivec3 pos = ivec3(
gl_GlobalInvocationID.x % out_limits_xy_scaled.x,
div_by_x % out_limits_xy_scaled.y,
div_by_x / out_limits_xy_scaled.y);

// scale pos.xy by batch sizes, because that's the top pixel to be processed
pos.x *= BATCH_SIZE_X;
pos.y *= BATCH_SIZE_Y;
div_by_x,
gl_GlobalInvocationID.y);

// do not process if top pixel does not fit within the output range
if (pos.z >= out_limits.z) {
if (pos.y >= out_limits_xy_scaled.y || pos.z >= out_limits.z) {
return;
}

// scale pos.xy by batch sizes, because that's the top pixel to be processed
pos.x *= BATCH_SIZE_X;
pos.y *= BATCH_SIZE_Y;

// Compute the index of the top-left element of the overlay region. Negative
// indices indicate that the top-left element is in a region added by padding.
const ivec2 ipos = pos.xy * stride - padding;

// Compute the start and end of the input indices to load. Padding is assumed
// to be constant 0 padding, so any reads from the padding region is skipped.
const ivec2 start = ipos;
const ivec2 end = ipos + overlay_region.xy;

// sum outputs
VEC4_T sum[BATCH_SIZE_Y * BATCH_SIZE_X];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,11 @@ void main() {
const uint div_by_x = gl_GlobalInvocationID.x / out_limits.x;
const ivec3 pos = ivec3(
gl_GlobalInvocationID.x % out_limits.x,
div_by_x % out_limits.y,
div_by_x / out_limits.y);
div_by_x,
gl_GlobalInvocationID.y);

if (pos.z >= out_limits.z) {
// do not process if top pixel does not fit within the output range
if (pos.y >= out_limits.y || pos.z >= out_limits.z) {
return;
}

Expand All @@ -64,7 +65,6 @@ void main() {
// Compute the start and end of the input indices to load. Padding is assumed
// to be constant 0 padding, so any reads from the padding region is skipped.
const ivec2 start = ipos;
const ivec2 end = ipos + overlay_region.xy;

VEC4_T sum = texelFetch(t_bias, ivec2(pos.z, 0), 0);
int kx = 0;
Expand Down
8 changes: 4 additions & 4 deletions backends/vulkan/runtime/graph/ops/impl/Convolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,13 +407,11 @@ void add_conv2d_node(
utils::uvec3 wg_size = create_conv2d_global_wg_size(
graph, method, out, weight_data, stride_equals_dilation);

if (method == Conv2dMethod::Depthwise) {
wg_size = {wg_size[0] * wg_size[1] * wg_size[2], 1, 1};
} else if (method == Conv2dMethod::Pointwise) {
utils::uvec3 local_wg_size;
if (method == Conv2dMethod::Depthwise || method == Conv2dMethod::Pointwise) {
wg_size = {wg_size[0] * wg_size[1], wg_size[2], 1};
}

utils::uvec3 local_wg_size;
if (method == Conv2dMethod::Pointwise) {
uint32_t local_wg_size_y = 1;
if (wg_size[1] % 8 == 0) {
Expand All @@ -424,6 +422,8 @@ void add_conv2d_node(
local_wg_size_y = 2;
}
local_wg_size = {64 / local_wg_size_y, local_wg_size_y, 1};
} else if (method == Conv2dMethod::Depthwise) {
local_wg_size = {64, 1, 1};
} else {
local_wg_size = graph.create_local_wg_size(wg_size);
}
Expand Down
176 changes: 131 additions & 45 deletions backends/vulkan/test/op_tests/cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,17 +279,6 @@ def get_conv_inputs():
output_padding=[0, 1],
groups=1,
),
Test(
self=(1, 8, 72, 96),
weight=(8, 1, 3, 3),
bias=(8,),
stride=[1, 1],
padding=[1, 1],
dilation=[1, 1],
transposed=False,
output_padding=[0, 0],
groups=8,
),
Test(
self=(1, 6, 40, 50),
weight=(8, 6, 3, 3),
Expand Down Expand Up @@ -345,39 +334,6 @@ def get_conv_inputs():
output_padding=[0],
groups=5,
),
Test(
self=(1, 4, 234, 234),
weight=(4, 1, 3, 3),
bias=(4,),
stride=[2, 1],
padding=[1, 1],
dilation=[1, 1],
transposed=False,
output_padding=[0, 0],
groups=4,
),
Test(
self=(1, 4, 234, 234),
weight=(4, 1, 3, 3),
bias=(4,),
stride=[1, 2],
padding=[1, 1],
dilation=[1, 1],
transposed=False,
output_padding=[0, 0],
groups=4,
),
Test(
self=(1, 4, 234, 234),
weight=(4, 1, 3, 3),
bias=(4,),
stride=[2, 2],
padding=[1, 1],
dilation=[1, 1],
transposed=False,
output_padding=[0, 0],
groups=4,
),
Test(
self=(1, 8, 90, 77),
weight=(1, 8, 3, 3),
Expand Down Expand Up @@ -526,6 +482,130 @@ def get_conv_inputs():
),
]

test_cases_dw = [
Test(
self=(1, XS, S, S1),
weight=(XS, 1, 3, 3),
bias=(XS,),
stride=[1, 1],
padding=[1, 1],
dilation=[1, 1],
transposed=False,
output_padding=[0, 0],
groups=XS,
),
Test(
self=(1, XS, S, S1),
weight=(XS, 1, 5, 5),
bias=(XS,),
stride=[1, 1],
padding=[2, 2],
dilation=[1, 1],
transposed=False,
output_padding=[0, 0],
groups=XS,
),
Test(
self=(1, XS, S, S1),
weight=(XS, 1, 3, 3),
bias=(XS,),
stride=[2, 1],
padding=[1, 1],
dilation=[1, 1],
transposed=False,
output_padding=[0, 0],
groups=XS,
),
Test(
self=(1, XS, S, S1),
weight=(XS, 1, 5, 5),
bias=(XS,),
stride=[1, 2],
padding=[2, 2],
dilation=[1, 1],
transposed=False,
output_padding=[0, 0],
groups=XS,
),
Test(
self=(1, S2, S, S1),
weight=(S2, 1, 3, 3),
bias=(S2,),
stride=[1, 1],
padding=[1, 1],
dilation=[1, 1],
transposed=False,
output_padding=[0, 0],
groups=S2,
),
Test(
self=(1, S2, S, S1),
weight=(S2, 1, 5, 5),
bias=(S2,),
stride=[1, 1],
padding=[2, 2],
dilation=[1, 1],
transposed=False,
output_padding=[0, 0],
groups=S2,
),
Test(
self=(1, 8, 72, 96),
weight=(8, 1, 3, 3),
bias=(8,),
stride=[1, 1],
padding=[1, 1],
dilation=[1, 1],
transposed=False,
output_padding=[0, 0],
groups=8,
),
Test(
self=(1, 8, 72, 96),
weight=(8, 1, 5, 5),
bias=(8,),
stride=[1, 1],
padding=[2, 2],
dilation=[1, 1],
transposed=False,
output_padding=[0, 0],
groups=8,
),
Test(
self=(1, 4, 234, 234),
weight=(4, 1, 3, 3),
bias=(4,),
stride=[2, 1],
padding=[1, 1],
dilation=[1, 1],
transposed=False,
output_padding=[0, 0],
groups=4,
),
Test(
self=(1, 4, 234, 234),
weight=(4, 1, 3, 3),
bias=(4,),
stride=[1, 2],
padding=[1, 1],
dilation=[1, 1],
transposed=False,
output_padding=[0, 0],
groups=4,
),
Test(
self=(1, 4, 234, 234),
weight=(4, 1, 3, 3),
bias=(4,),
stride=[2, 2],
padding=[1, 1],
dilation=[1, 1],
transposed=False,
output_padding=[0, 0],
groups=4,
),
]

test_suite = VkTestSuite(test_cases)
test_suite.layouts = [
"utils::kChannelsPacked",
Expand All @@ -536,7 +616,13 @@ def get_conv_inputs():
"utils::kChannelsPacked",
]
test_suite_pw.test_name_suffix = "pw"
return [test_suite, test_suite_pw]

test_suite_dw = VkTestSuite(test_cases_dw)
test_suite_dw.layouts = [
"utils::kChannelsPacked",
]
test_suite_dw.test_name_suffix = "dw"
return [test_suite, test_suite_pw, test_suite_dw]


@register_test_suite("aten.native_layer_norm.default")
Expand Down
Loading