Skip to content

[ET-VK] Minor improvement to permute op. #10117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: gh/trivedivivek/77/base
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions backends/vulkan/runtime/graph/ops/glsl/permute.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ layout(push_constant) uniform PRECISION restrict Block {
layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in;
layout(constant_id = 3) const int packed_dim = C_DIM;

#extension GL_EXT_control_flow_attributes : require

void main() {
ivec3 pos = ivec3(gl_GlobalInvocationID);

Expand All @@ -54,11 +56,16 @@ void main() {
in_bchw_pos[out_ndims[2]] = pos.y;
in_bchw_pos[out_ndims[3]] = pos.x;

for (int j = 0; j < 4; ++j) {
const int in_packed_dim_size = in_sizes[3 - out_ndims[in_packed_dim_bchw_index]];

[[unroll]] for (int j = 0, bchw_index = in_bchw_pos[out_ndims[in_packed_dim_bchw_index]]; j < 4; ++j, ++bchw_index) {
// terminate the loop if trying to access input texture out of bounds
if (any(greaterThanEqual(in_bchw_pos.wzyx, in_sizes.xyzw))) {
if (bchw_index >= in_packed_dim_size) {
break;
}
// go to position in the input, that is mapped to the packed dim in the output
in_bchw_pos[out_ndims[in_packed_dim_bchw_index]] = bchw_index;

ivec3 fetch_pos;

fetch_pos.xy = in_bchw_pos.wz;
Expand All @@ -74,9 +81,6 @@ void main() {
// fetch input texel
VEC4_T inval = VEC4_T(load_texel(t_in, fetch_pos));
outval[j] = inval[in_packed_dim_lane_index];

// go to next position in the input, that is mapped to the packed dim in the output
in_bchw_pos[out_ndims[in_packed_dim_bchw_index]]++;
}

pos[packed_dim] = int(gl_GlobalInvocationID[packed_dim]);
Expand Down
Loading