Skip to content

Commit 8aab7d0

Browse files
[ET-VK] Use push constants for image and buffer to nchw prepack nodes. (#11371)
This PR was created by the merge bot to help merge the original PR into the main branch. ghstack PR number: #11305 by @trivedivivek ^ Please use this as the source of truth for the PR details, comments, and reviews ghstack PR base: https://github.com/pytorch/executorch/tree/gh/trivedivivek/109/base ghstack PR head: https://github.com/pytorch/executorch/tree/gh/trivedivivek/109/head Merge bot PR base: https://github.com/pytorch/executorch/tree/main Merge bot PR head: https://github.com/pytorch/executorch/tree/gh/trivedivivek/109/orig @diff-train-skip-merge --------- Co-authored-by: Vivek Trivedi <[email protected]>
1 parent 6415c15 commit 8aab7d0

16 files changed

+83
-42
lines changed

backends/vulkan/runtime/graph/ops/glsl/bitw8_image_to_nchw_nobitw8buffer.glsl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,15 @@ layout(std430) buffer;
2020

2121
${layout_declare_buffer(B, "w", "nchw_out", "int")}
2222
${layout_declare_tensor(B, "r", "t_in", DTYPE, STORAGE)}
23-
${layout_declare_ubo(B, "ivec4", "tensor_sizes")}
24-
${layout_declare_ubo(B, "int", "out_numel")}
23+
24+
$if USE_PUSH_CONST:
25+
layout(push_constant) uniform restrict Block {
26+
ivec4 tensor_sizes;
27+
int out_numel;
28+
};
29+
$else:
30+
${layout_declare_ubo(B, "ivec4", "tensor_sizes")}
31+
${layout_declare_ubo(B, "int", "out_numel")}
2532

2633
layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in;
2734

backends/vulkan/runtime/graph/ops/glsl/bitw8_image_to_nchw_nobitw8buffer.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ bitw8_image_to_nchw_nobitw8buffer:
88
parameter_names_with_default_values:
99
STORAGE: texture3d
1010
DTYPE: int8
11+
USE_PUSH_CONST: True
1112
generate_variant_forall:
1213
STORAGE:
1314
- VALUE: texture2d
@@ -17,3 +18,5 @@ bitw8_image_to_nchw_nobitw8buffer:
1718
- VALUE: uint8
1819
shader_variants:
1920
- NAME: bitw8_image_to_nchw_nobitw8buffer
21+
- NAME: bitw8_image_to_nchw_nobitw8buffer_no_pc
22+
USE_PUSH_CONST: False

backends/vulkan/runtime/graph/ops/glsl/buffer_to_nchw.glsl

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,17 @@ layout(std430) buffer;
1212

1313
${layout_declare_tensor(0, "w", "nchw_buf", DTYPE, STORAGE)}
1414
${layout_declare_tensor(1, "r", "t_in", DTYPE, STORAGE)}
15-
${layout_declare_ubo(2, "ivec4", "in_sizes")}
16-
${layout_declare_ubo(3, "ivec4", "in_strides")}
17-
${layout_declare_ubo(4, "int", "numel")}
15+
16+
$if USE_PUSH_CONST:
17+
layout(push_constant) uniform restrict Block {
18+
ivec4 in_sizes;
19+
ivec4 in_strides;
20+
int numel;
21+
};
22+
$else:
23+
${layout_declare_ubo(2, "ivec4", "in_sizes")}
24+
${layout_declare_ubo(3, "ivec4", "in_strides")}
25+
${layout_declare_ubo(4, "int", "numel")}
1826

1927
layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in;
2028

backends/vulkan/runtime/graph/ops/glsl/buffer_to_nchw.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ buffer_to_nchw:
88
parameter_names_with_default_values:
99
DTYPE: float
1010
STORAGE: buffer
11+
USE_PUSH_CONST: True
1112
generate_variant_forall:
1213
DTYPE:
1314
- VALUE: half
@@ -17,3 +18,5 @@ buffer_to_nchw:
1718
- VALUE: uint8
1819
shader_variants:
1920
- NAME: buffer_to_nchw
21+
- NAME: buffer_to_nchw_no_pc
22+
USE_PUSH_CONST: False

backends/vulkan/runtime/graph/ops/glsl/conv2d_dw_prepack_weights.glsl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,8 @@ layout(set = 0, binding = 1) buffer PRECISION restrict readonly Buffer {
2626
BUF_T buffer_in[];
2727
};
2828

29-
layout(set = 0, binding = 2) uniform PRECISION restrict Sizes {
29+
layout(push_constant) uniform PRECISION restrict Block {
3030
ivec4 sizes;
31-
};
32-
33-
layout(set = 0, binding = 3) uniform PRECISION restrict OriginalSizes {
3431
ivec4 original_sizes;
3532
};
3633

backends/vulkan/runtime/graph/ops/glsl/conv2d_prepack_weights.glsl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,8 @@ layout(set = 0, binding = 1) buffer PRECISION restrict readonly Buffer {
2626
BUF_T buffer_in[];
2727
};
2828

29-
layout(set = 0, binding = 2) uniform PRECISION restrict Sizes {
29+
layout(push_constant) uniform PRECISION restrict Block {
3030
ivec4 sizes;
31-
};
32-
33-
layout(set = 0, binding = 3) uniform PRECISION restrict OriginalSizes {
3431
ivec4 original_sizes;
3532
};
3633

backends/vulkan/runtime/graph/ops/glsl/conv_transpose2d_prepack_weights.glsl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,8 @@ layout(set = 0, binding = 1) buffer PRECISION restrict readonly Buffer {
2626
BUF_T buffer_in[];
2727
};
2828

29-
layout(set = 0, binding = 2) uniform PRECISION restrict Sizes {
29+
layout(push_constant) uniform PRECISION restrict Block {
3030
ivec4 sizes;
31-
};
32-
33-
layout(set = 0, binding = 3) uniform PRECISION restrict OriginalSizes {
3431
ivec4 original_sizes;
3532
};
3633

backends/vulkan/runtime/graph/ops/glsl/image_to_nchw.glsl

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,17 @@ layout(std430) buffer;
2121

2222
${layout_declare_buffer(B, "w", "buf_out", DTYPE)}
2323
${layout_declare_tensor(B, "r", "t_in", DTYPE, STORAGE)}
24-
${layout_declare_ubo(B, "ivec4", "sizes")}
25-
$if not TO_STAGING:
26-
${layout_declare_ubo(B, "ivec4", "buf_strides")}
24+
25+
$if USE_PUSH_CONST:
26+
layout(push_constant) uniform restrict Block {
27+
ivec4 sizes;
28+
$if not TO_STAGING:
29+
ivec4 buf_strides;
30+
};
31+
$else:
32+
${layout_declare_ubo(B, "ivec4", "sizes")}
33+
$if not TO_STAGING:
34+
${layout_declare_ubo(B, "ivec4", "buf_strides")}
2735

2836
#include "indexing_utils.h"
2937

backends/vulkan/runtime/graph/ops/glsl/image_to_nchw.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ image_to_nchw:
99
DTYPE: float
1010
STORAGE: texture3d
1111
TO_STAGING: True
12+
USE_PUSH_CONST: True
1213
generate_variant_forall:
1314
DTYPE:
1415
- VALUE: half
@@ -22,3 +23,11 @@ image_to_nchw:
2223
STORAGE: texture2d
2324
- NAME: clone_image_to_buffer
2425
TO_STAGING: False
26+
- NAME: image_to_nchw_no_pc_texture3d
27+
USE_PUSH_CONST: False
28+
- NAME: image_to_nchw_no_pc_texture2d
29+
STORAGE: texture2d
30+
USE_PUSH_CONST: False
31+
- NAME: clone_image_to_buffer_no_pc
32+
TO_STAGING: False
33+
USE_PUSH_CONST: False

backends/vulkan/runtime/graph/ops/impl/Clone.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ void add_image_to_buffer_node(
8888
// Input and Outputs
8989
{{buffer, vkapi::kWrite}, {image, vkapi::kRead}},
9090
// Parameter Buffers
91-
{graph.sizes_ubo(image), graph.strides_ubo(buffer)},
92-
// Push Constants
9391
{},
92+
// Push Constants
93+
{graph.sizes_pc_of(image), graph.strides_pc_of(buffer)},
9494
// Specialization Constants
9595
{graph.hashed_layout_of(image)},
9696
// Resize Args

0 commit comments

Comments
 (0)