Skip to content

Commit 7f0c0b8

Browse files
nathanaelseefacebook-github-bot
authored andcommitted
add int to generated shader variants for view (#3970)
Summary: Pull Request resolved: #3970 Used in joiner model. Also updating to use the newer shader layout codegen format Reviewed By: jorgep31415 Differential Revision: D58499751 fbshipit-source-id: fa7fcf0d89e0afba3944c5f9a1b3c7017791a573
1 parent 4cf9a46 commit 7f0c0b8

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

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

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,11 @@ layout(std430) buffer;
1616

1717
#include "indexing_utils.h"
1818

19-
layout(set = 0, binding = 0, ${IMAGE_FORMAT[DTYPE]}) uniform PRECISION restrict writeonly ${IMAGE_T[NDIM][DTYPE]} image_out;
20-
layout(set = 0, binding = 1) uniform PRECISION sampler3D image_in;
19+
${layout_declare_tensor(0, "w", "t_out", DTYPE, STORAGE)}
20+
${layout_declare_tensor(1, "r", "t_in", DTYPE, STORAGE)}
2121

22-
layout(set = 0, binding = 2) uniform PRECISION restrict OutSizes {
23-
ivec4 out_sizes;
24-
};
25-
26-
layout(set = 0, binding = 3) uniform PRECISION restrict InSizes {
27-
ivec4 in_sizes;
28-
};
22+
${layout_declare_ubo(2, "ivec4", "out_sizes")}
23+
${layout_declare_ubo(3, "ivec4", "in_sizes")}
2924

3025
layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in;
3126

@@ -52,10 +47,10 @@ void main() {
5247
if (out_tensor_idx[out_packed_dim]++ < out_sizes[out_packed_dim]) {
5348
ivec4 user_coor = from_nchw_buffer_i(buf_indices[i], in_sizes);
5449
ivec4 in_pos_elem = to_texture_elem_pos(user_coor, in_sizes, in_packed_dim);
55-
VEC4_T intex = texelFetch(image_in, in_pos_elem.xyz, 0);
50+
VEC4_T intex = texelFetch(t_in, in_pos_elem.xyz, 0);
5651
value[i] = intex[in_pos_elem.w];
5752
}
5853
}
5954

60-
imageStore(image_out, out_pos, value);
55+
imageStore(t_out, out_pos, value);
6156
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ view:
22
parameter_names_with_default_values:
33
DTYPE: float
44
NDIM: 3
5+
STORAGE: texture3d
56
generate_variant_forall:
67
DTYPE:
78
- VALUE: half
89
- VALUE: float
10+
- VALUE: int
911
shader_variants:
1012
- NAME: view

backends/vulkan/test/test_vulkan_delegate.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,6 +1083,22 @@ def forward(self, x):
10831083
memory_layouts=[vk_graph_schema.VkMemoryLayout.TENSOR_CHANNELS_PACKED],
10841084
)
10851085

1086+
def test_vulkan_backend_view_int(self):
1087+
class ViewModule(torch.nn.Module):
1088+
def __init__(self):
1089+
super().__init__()
1090+
1091+
def forward(self, x):
1092+
return x.view([-1, x.size(-1)])
1093+
1094+
sample_inputs = (torch.randint(size=(3, 6, 2, 7), high=100, dtype=torch.int32),)
1095+
1096+
self.lower_module_and_test_output(
1097+
ViewModule(),
1098+
sample_inputs,
1099+
memory_layouts=[vk_graph_schema.VkMemoryLayout.TENSOR_CHANNELS_PACKED],
1100+
)
1101+
10861102
def test_vulkan_backend_unsqueeze(self):
10871103
class UnsqueezeModule(torch.nn.Module):
10881104
def __init__(self):

0 commit comments

Comments
 (0)