Skip to content

Commit f1bdb50

Browse files
committed
[7/n][ET-VK] Support texture2D in etvk.copy_offset
Pull Request resolved: #5933 To use `copy_offset` with 2D textures in AHB experimentation. ghstack-source-id: 246657862 @exported-using-ghexport Differential Revision: [D63905519](https://our.internmc.facebook.com/intern/diff/D63905519/)
1 parent b820ff0 commit f1bdb50

File tree

5 files changed

+44
-7
lines changed

5 files changed

+44
-7
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
#define PRECISION ${PRECISION}
1212

13+
${define_active_storage_type(STORAGE)}
14+
1315
#include "indexing_utils.h"
1416

1517
layout(std430) buffer;

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,10 @@ copy_offset:
88
- VALUE: half
99
- VALUE: float
1010
- VALUE: int
11+
- VALUE: int8
12+
- VALUE: uint8
13+
STORAGE:
14+
- VALUE: texture3d
15+
- VALUE: texture2d
1116
shader_variants:
1217
- NAME: copy_offset

backends/vulkan/runtime/graph/ops/glsl/indexing_utils.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,8 @@ ivec3 lpos_to_pos(const ivec3 lpos, const ivec4 axis_map) {
212212
#define load_texel(buf, idx) buf[idx]
213213
#elif defined(USING_TEXTURE2D)
214214
#define load_texel(im, pos) texelFetch(im, pos.xy, 0)
215+
#define load_texel_lpos(im, lpos, axis_map) \
216+
texelFetch(im, lpos_to_pos(lpos, axis_map).xy, 0)
215217
#else // defined(USING_TEXTURE3D)
216218
#define load_texel(im, pos) texelFetch(im, pos, 0)
217219
#define load_texel_lpos(im, lpos, axis_map) \
@@ -222,6 +224,8 @@ ivec3 lpos_to_pos(const ivec3 lpos, const ivec4 axis_map) {
222224
#define write_texel(buf, idx, texel) buf[idx] = texel
223225
#elif defined(USING_TEXTURE2D)
224226
#define write_texel(im, pos, texel) imageStore(im, pos.xy, texel)
227+
#define write_texel_lpos(im, lpos, texel, axis_map) \
228+
imageStore(im, lpos_to_pos(lpos, axis_map).xy, texel)
225229
#else // defined(USING_TEXTURE3D)
226230
#define write_texel(im, pos, texel) imageStore(im, pos, texel)
227231
#define write_texel_lpos(im, lpos, texel, axis_map) \

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ void add_copy_offset_node(
3131
std::string kernel_name = "copy_offset";
3232
kernel_name.reserve(kShaderNameReserve);
3333
add_dtype_suffix(kernel_name, *t_out);
34+
add_storage_type_suffix(kernel_name, *t_out);
3435

3536
const struct Block final {
3637
alignas(16) ivec3 range;
@@ -115,6 +116,7 @@ void add_copy_channel_offset_node(
115116
std::string kernel_name = "copy_channel_offset";
116117
kernel_name.reserve(kShaderNameReserve);
117118
add_dtype_suffix(kernel_name, *t_out);
119+
add_storage_type_suffix(kernel_name, *t_out);
118120

119121
int32_t out_channels = dim_at<kChannel4D>(out_sizes);
120122

backends/vulkan/test/op_tests/cases.py

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,30 @@ def get_clone_inputs():
704704

705705
@register_test_suite("aten.repeat.default")
706706
def get_repeat_inputs():
707-
test_suite = VkTestSuite(
707+
test_suite_2d = VkTestSuite(
708+
[
709+
# Repeat channels only (most challenging case)
710+
((3, XS, S), [2, 1, 1]),
711+
((7, XS, S), [4, 1, 1]),
712+
# More other cases
713+
((2, 3), [1, 4]),
714+
((2, 3), [4, 1]),
715+
((2, 3), [4, 4]),
716+
((S1, S2, S2), [1, 3, 1]),
717+
((S1, S2, S2), [1, 3, 3]),
718+
((S1, S2, S2), [3, 3, 1]),
719+
((S1, S2, S2), [3, 3, 3]),
720+
# Expanding cases
721+
((2, 3), [3, 1, 4]),
722+
]
723+
)
724+
test_suite_2d.layouts = ["utils::kChannelsPacked"]
725+
test_suite_2d.storage_types = ["utils::kTexture2D"]
726+
test_suite_2d.data_gen = "make_seq_tensor"
727+
test_suite_2d.dtypes = ["at::kFloat"]
728+
test_suite_2d.test_name_suffix = "2d"
729+
730+
test_suite_3d = VkTestSuite(
708731
[
709732
# Repeat channels only (most challenging case)
710733
((3, XS, S), [2, 1, 1]),
@@ -739,12 +762,13 @@ def get_repeat_inputs():
739762
((2, 3), [3, 3, 2, 4]),
740763
]
741764
)
742-
test_suite.layouts = [
743-
"utils::kChannelsPacked",
744-
]
745-
test_suite.data_gen = "make_seq_tensor"
746-
test_suite.dtypes = ["at::kFloat"]
747-
return test_suite
765+
test_suite_3d.layouts = ["utils::kChannelsPacked"]
766+
test_suite_3d.storage_types = ["utils::kTexture3D"]
767+
test_suite_3d.data_gen = "make_seq_tensor"
768+
test_suite_3d.dtypes = ["at::kFloat"]
769+
test_suite_2d.test_name_suffix = "3d"
770+
771+
return [test_suite_2d, test_suite_3d]
748772

749773

750774
@register_test_suite("aten.repeat_interleave.self_int")

0 commit comments

Comments
 (0)