Skip to content

Commit c35fb94

Browse files
jorgep31415facebook-github-bot
authored andcommitted
Support texture2D in etvk.copy_offset (#5933)
Summary: Pull Request resolved: #5933 To use `copy_offset` with 2D textures in AHB experimentation. ghstack-source-id: 246850703 exported-using-ghexport Reviewed By: SS-JIA Differential Revision: D63905519 fbshipit-source-id: 03b1cdf90bd9db299003a6152648f08705197f72
1 parent 77b1f08 commit c35fb94

File tree

6 files changed

+39
-7
lines changed

6 files changed

+39
-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: 1 addition & 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;

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ void check_args(
2626
VK_CHECK_COND(check_packed_dim_is(in, WHCN::kChannelsDim));
2727
VK_CHECK_COND(check_packed_dim_is(out, WHCN::kChannelsDim));
2828

29+
VK_CHECK_COND(in.storage_type() == out.storage_type());
30+
if (in.storage_type() == utils::kTexture2D) {
31+
VK_CHECK_COND(in.dim() <= 2);
32+
}
33+
2934
int64_t in_dim = in.dim();
3035
VK_CHECK_COND(
3136
in_dim <= repeats.size(),

backends/vulkan/test/op_tests/cases.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,21 @@ 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+
((2, 3), [1, 4]),
710+
((2, 3), [4, 1]),
711+
((2, 3), [4, 4]),
712+
((2, 3), [3, 1, 4]),
713+
]
714+
)
715+
test_suite_2d.layouts = ["utils::kChannelsPacked"]
716+
test_suite_2d.storage_types = ["utils::kTexture2D"]
717+
test_suite_2d.data_gen = "make_seq_tensor"
718+
test_suite_2d.dtypes = ["at::kFloat"]
719+
test_suite_2d.test_name_suffix = "2d"
720+
721+
test_suite_3d = VkTestSuite(
708722
[
709723
# Repeat channels only (most challenging case)
710724
((3, XS, S), [2, 1, 1]),
@@ -739,12 +753,13 @@ def get_repeat_inputs():
739753
((2, 3), [3, 3, 2, 4]),
740754
]
741755
)
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
756+
test_suite_3d.layouts = ["utils::kChannelsPacked"]
757+
test_suite_3d.storage_types = ["utils::kTexture3D"]
758+
test_suite_3d.data_gen = "make_seq_tensor"
759+
test_suite_3d.dtypes = ["at::kFloat"]
760+
test_suite_3d.test_name_suffix = "3d"
761+
762+
return [test_suite_2d, test_suite_3d]
748763

749764

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

0 commit comments

Comments
 (0)