Skip to content

Commit 0dda2cb

Browse files
author
ssjia
committed
[ET-VK] Modernize repeat
Modernize repeat to support ANY_STORAGE. Rewrite texture shader to use TextureMetadata with indexing.glslh helpers for coordinate conversion. Add buffer shader variant using BufferMetadata. Unify dispatch to use graph.meta_ubo() for both paths. Add symint support for dynamic repeat counts. Pull Request resolved: #18056 ghstack-source-id: 353546685 @exported-using-ghexport Differential Revision: [D95970170](https://our.internmc.facebook.com/intern/diff/D95970170/)
1 parent 27089de commit 0dda2cb

File tree

8 files changed

+167
-222
lines changed

8 files changed

+167
-222
lines changed

backends/vulkan/op_registry.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1378,7 +1378,7 @@ def register_grid_priors():
13781378
@update_features(exir_ops.edge.aten.repeat.default)
13791379
def register_repeat():
13801380
return OpFeatures(
1381-
inputs_storage=utils.ANY_TEXTURE,
1381+
inputs_storage=utils.ANY_STORAGE,
13821382
inputs_dtypes=utils.FP_INT_BOOL_T,
13831383
)
13841384

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

Lines changed: 0 additions & 129 deletions
This file was deleted.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
#version 450 core
10+
11+
${define_required_extensions("buffer", DTYPE)}
12+
13+
#define PRECISION ${PRECISION}
14+
15+
#define T ${buffer_scalar_type(DTYPE)}
16+
17+
${define_active_storage_type("buffer")}
18+
19+
layout(std430) buffer;
20+
21+
#include "indexing.glslh"
22+
23+
${layout_declare_tensor(B, "w", "t_out", DTYPE, "buffer")}
24+
${layout_declare_tensor(B, "r", "t_in", DTYPE, "buffer")}
25+
26+
${layout_declare_ubo(B, "BufferMetadata", "out_meta")}
27+
${layout_declare_ubo(B, "BufferMetadata", "in_meta")}
28+
29+
layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in;
30+
31+
void main() {
32+
const uint out_bufi = gl_GlobalInvocationID.x;
33+
if (out_of_bounds(out_bufi, out_meta)) {
34+
return;
35+
}
36+
37+
TensorIndex out_tidx = linear_idx_to_tensor_idx(out_meta, out_bufi);
38+
39+
TensorIndex in_tidx;
40+
initialize(in_tidx);
41+
42+
const int n = int_ndim(out_meta);
43+
for (int d = 0; d < n; d++) {
44+
in_tidx.data[div_4(d)][mod_4(d)] =
45+
idx_at(out_tidx, d) % size_at(in_meta, d);
46+
}
47+
48+
const uint in_bufi = tensor_idx_to_linear_idx(in_meta, in_tidx);
49+
50+
t_out[out_bufi] = t_in[in_bufi];
51+
}

backends/vulkan/runtime/graph/ops/glsl/repeat.yaml renamed to backends/vulkan/runtime/graph/ops/glsl/repeat_buffer.yaml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
repeat:
1+
repeat_buffer:
22
parameter_names_with_default_values:
33
DTYPE: float
4-
NDIM: 3
5-
STORAGE: texture3d
4+
STORAGE: buffer
65
generate_variant_forall:
76
DTYPE:
87
- VALUE: half
@@ -11,4 +10,4 @@ repeat:
1110
- VALUE: int8
1211
- VALUE: uint8
1312
shader_variants:
14-
- NAME: repeat
13+
- NAME: repeat_buffer
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
#version 450 core
10+
11+
${define_required_extensions("texture3d", DTYPE)}
12+
13+
#define PRECISION ${PRECISION}
14+
15+
#define VEC4_T ${texel_load_type(DTYPE, "texture3d")}
16+
17+
${define_active_storage_type("texture3d")}
18+
19+
#extension GL_EXT_control_flow_attributes : require
20+
21+
layout(std430) buffer;
22+
23+
#include "common.glslh"
24+
#include "indexing.glslh"
25+
26+
${layout_declare_tensor(B, "w", "t_out", DTYPE, "texture3d")}
27+
${layout_declare_tensor(B, "r", "t_in", DTYPE, "texture3d")}
28+
29+
${layout_declare_ubo(B, "TextureMetadata", "out_meta")}
30+
${layout_declare_ubo(B, "TextureMetadata", "in_meta")}
31+
32+
layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in;
33+
34+
${layout_declare_spec_const(C, "int", "out_layout", "CONTIG_LAYOUT_INT")}
35+
const int packed_dim = get_packed_dim(out_layout);
36+
37+
void main() {
38+
const ivec3 out_pos = ivec3(gl_GlobalInvocationID);
39+
40+
if (out_of_bounds(out_pos, out_meta)) {
41+
return;
42+
}
43+
44+
TensorIndex4D out_tidx = texture_pos_to_tensor4d_idx_simple(out_meta, out_pos);
45+
46+
VEC4_T out_texel = VEC4_T(0);
47+
48+
const int limit = min(
49+
4, out_meta.sizes[packed_dim] - out_tidx.data[packed_dim]);
50+
for (int comp = 0; comp < limit; comp++) {
51+
TensorIndex4D in_tidx = out_tidx;
52+
in_tidx.data = ivec4(
53+
out_tidx.data.x % in_meta.sizes.x,
54+
out_tidx.data.y % in_meta.sizes.y,
55+
out_tidx.data.z % in_meta.sizes.z,
56+
out_tidx.data.w % in_meta.sizes.w);
57+
58+
TextureElementIndex in_elem =
59+
tensor4d_idx_to_texture_element_idx_simple(in_meta, in_tidx);
60+
61+
VEC4_T in_texel = texelFetch(t_in, in_elem.pos, 0);
62+
out_texel[comp] = in_texel[in_elem.comp];
63+
64+
out_tidx.data[packed_dim]++;
65+
}
66+
67+
imageStore(t_out, out_pos, out_texel);
68+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
repeat_texture:
2+
parameter_names_with_default_values:
3+
DTYPE: float
4+
generate_variant_forall:
5+
DTYPE:
6+
- VALUE: half
7+
- VALUE: float
8+
- VALUE: int32
9+
- VALUE: int8
10+
- VALUE: uint8
11+
shader_variants:
12+
- NAME: repeat_texture3d

0 commit comments

Comments
 (0)