diff --git a/backends/vulkan/runtime/graph/ops/glsl/adamw_step.glsl b/backends/vulkan/runtime/graph/ops/glsl/adamw_step.glsl index ccb7b34bcb7..860b4f0f1df 100644 --- a/backends/vulkan/runtime/graph/ops/glsl/adamw_step.glsl +++ b/backends/vulkan/runtime/graph/ops/glsl/adamw_step.glsl @@ -36,8 +36,10 @@ layout(push_constant) uniform restrict Block { layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in; +#include "dispatch.glslh" + void main() { - const int i = int(gl_GlobalInvocationID.x); + const int i = int(linear_idx_from_gid()); if (i >= numel) { return; } diff --git a/backends/vulkan/runtime/graph/ops/glsl/arange_buffer.glsl b/backends/vulkan/runtime/graph/ops/glsl/arange_buffer.glsl index 906ed91a466..2e9377533c8 100644 --- a/backends/vulkan/runtime/graph/ops/glsl/arange_buffer.glsl +++ b/backends/vulkan/runtime/graph/ops/glsl/arange_buffer.glsl @@ -28,8 +28,10 @@ ${layout_declare_ubo(B, "float", "step")} layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in; +#include "dispatch.glslh" + void main() { - const uint out_bufi = gl_GlobalInvocationID.x; + const uint out_bufi = linear_idx_from_gid(); if (out_of_bounds(out_bufi, outp)) { return; } diff --git a/backends/vulkan/runtime/graph/ops/glsl/binary_op_buffer.glsl b/backends/vulkan/runtime/graph/ops/glsl/binary_op_buffer.glsl index 4d56d991bdc..ac4751a47e5 100644 --- a/backends/vulkan/runtime/graph/ops/glsl/binary_op_buffer.glsl +++ b/backends/vulkan/runtime/graph/ops/glsl/binary_op_buffer.glsl @@ -53,6 +53,8 @@ layout(push_constant) uniform restrict Block { layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in; +#include "dispatch.glslh" + ${layout_declare_spec_const(C, "int", "out_layout", "CONTIG_LAYOUT_INT")} ${layout_declare_spec_const(C, "int", "in_layout", "CONTIG_LAYOUT_INT")} ${layout_declare_spec_const(C, "int", "other_layout", "CONTIG_LAYOUT_INT")} @@ -61,7 +63,7 @@ ${layout_declare_spec_const(C, "int", "in_broadcast_packed_dim", "0")} ${layout_declare_spec_const(C, "int", "other_broadcast_packed_dim", "0")} void main() { - const uint out_bufi = gl_GlobalInvocationID.x; + const uint out_bufi = linear_idx_from_gid(); if (out_of_bounds(out_bufi, outp)) { return; } diff --git a/backends/vulkan/runtime/graph/ops/glsl/binary_scalar_buffer.glsl b/backends/vulkan/runtime/graph/ops/glsl/binary_scalar_buffer.glsl index 1de98128159..9def3666870 100644 --- a/backends/vulkan/runtime/graph/ops/glsl/binary_scalar_buffer.glsl +++ b/backends/vulkan/runtime/graph/ops/glsl/binary_scalar_buffer.glsl @@ -57,11 +57,13 @@ layout(push_constant) uniform restrict Block { layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in; +#include "dispatch.glslh" + $if not IS_COMPARISON_OP: #include "binary_op_defs.glslh" void main() { - const uint out_bufi = gl_GlobalInvocationID.x; + const uint out_bufi = linear_idx_from_gid(); if (out_of_bounds(out_bufi, outp)) { return; } diff --git a/backends/vulkan/runtime/graph/ops/glsl/bitw8_image_to_nchw_nobitw8buffer.glsl b/backends/vulkan/runtime/graph/ops/glsl/bitw8_image_to_nchw_nobitw8buffer.glsl index ac39dd36fc3..ff5554ad6bc 100644 --- a/backends/vulkan/runtime/graph/ops/glsl/bitw8_image_to_nchw_nobitw8buffer.glsl +++ b/backends/vulkan/runtime/graph/ops/glsl/bitw8_image_to_nchw_nobitw8buffer.glsl @@ -32,12 +32,14 @@ $else: layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in; +#include "dispatch.glslh" + ${layout_declare_spec_const(C, "int", "t_layout", "DEFAULT_LAYOUT")} const lowp ivec4 axis_map = unhash_axis_map(t_layout); const lowp int packed_dim = unhash_packed_dim(t_layout); void main() { - const int out_buf_idx = int(gl_GlobalInvocationID.x); + const int out_buf_idx = int(linear_idx_from_gid()); // On the CPU, the number of elements is determined based on a buffer of int8 // elements. However, on the GPU, since the int8 data type is not supported // each group of 4 elements is interepreted as 1 int32 element. Thus each diff --git a/backends/vulkan/runtime/graph/ops/glsl/buffer_to_buffer.glsl b/backends/vulkan/runtime/graph/ops/glsl/buffer_to_buffer.glsl index b0050740e8d..caf1ac80170 100644 --- a/backends/vulkan/runtime/graph/ops/glsl/buffer_to_buffer.glsl +++ b/backends/vulkan/runtime/graph/ops/glsl/buffer_to_buffer.glsl @@ -14,8 +14,10 @@ ${layout_declare_ubo(2, "int", "numel")} layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in; +#include "dispatch.glslh" + void main() { - int tid = int(gl_GlobalInvocationID.x); + int tid = int(linear_idx_from_gid()); if (tid >= numel) { return; } diff --git a/backends/vulkan/runtime/graph/ops/glsl/buffer_to_nchw.glsl b/backends/vulkan/runtime/graph/ops/glsl/buffer_to_nchw.glsl index 3b487c43887..2e2502f85b2 100644 --- a/backends/vulkan/runtime/graph/ops/glsl/buffer_to_nchw.glsl +++ b/backends/vulkan/runtime/graph/ops/glsl/buffer_to_nchw.glsl @@ -19,12 +19,14 @@ ${layout_declare_ubo(B, "BufferMetadata", "inp")} layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in; +#include "dispatch.glslh" + // This constant is unused in this shader but is kept so that the signature is // consistent with image_to_nchw. ${layout_declare_spec_const(C, "int", "unused", "0")} void main() { - uint inp_bufi = gl_GlobalInvocationID.x; + uint inp_bufi = linear_idx_from_gid(); if (inp_bufi>= numel(inp)) { return; } diff --git a/backends/vulkan/runtime/graph/ops/glsl/concat_buffer.glsl b/backends/vulkan/runtime/graph/ops/glsl/concat_buffer.glsl index f19cbe7ab40..735660f8866 100644 --- a/backends/vulkan/runtime/graph/ops/glsl/concat_buffer.glsl +++ b/backends/vulkan/runtime/graph/ops/glsl/concat_buffer.glsl @@ -37,6 +37,8 @@ ${layout_declare_spec_const(C, "int", "out_layout", "CONTIG_LAYOUT_INT")} layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in; +#include "dispatch.glslh" + #define NUM_INPUTS ${NUM_INPUTS} /* @@ -45,7 +47,7 @@ layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in; * be inserted along the output's concat_dim starting at concat_offset. */ void main() { - const int tid = int(gl_GlobalInvocationID.x); + const int tid = int(linear_idx_from_gid()); // The 1-3 input tensors are interpreted as one concatenated tensor ("volume") // along the concat_dim for the purposes of tensor indexing. Each thread is diff --git a/backends/vulkan/runtime/graph/ops/glsl/concat_texture.glsl b/backends/vulkan/runtime/graph/ops/glsl/concat_texture.glsl index ef6264440cf..7345a61afa0 100644 --- a/backends/vulkan/runtime/graph/ops/glsl/concat_texture.glsl +++ b/backends/vulkan/runtime/graph/ops/glsl/concat_texture.glsl @@ -43,6 +43,8 @@ const int out_packed_dim = get_packed_dim(out_layout); layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in; +#include "dispatch.glslh" + #define NUM_INPUTS ${NUM_INPUTS} /* @@ -55,7 +57,7 @@ layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in; * input tensor. */ void main() { - const int tid = int(gl_GlobalInvocationID.x); + const int tid = int(linear_idx_from_gid()); // Compute inp_volume_sizes from output sizes, replacing concat_dim with the // sum of all input sizes along that dimension. diff --git a/backends/vulkan/runtime/graph/ops/glsl/conv2d_dw.glsl b/backends/vulkan/runtime/graph/ops/glsl/conv2d_dw.glsl index 9089f87d658..ad7074c5e10 100644 --- a/backends/vulkan/runtime/graph/ops/glsl/conv2d_dw.glsl +++ b/backends/vulkan/runtime/graph/ops/glsl/conv2d_dw.glsl @@ -30,6 +30,8 @@ ${layout_declare_ubo(8, "float", "out_min", "float", "out_max")} layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in; +#include "dispatch.glslh" + ${layout_declare_spec_const(C, "int", "ngroups", "1")} /* @@ -37,9 +39,10 @@ ${layout_declare_spec_const(C, "int", "ngroups", "1")} * output at a single output location. */ void main() { - const uint div_by_x = gl_GlobalInvocationID.x / out_limits.x; + const uint linear_idx = linear_idx_from_gid(); + const uint div_by_x = linear_idx / out_limits.x; const ivec3 pos = ivec3( - gl_GlobalInvocationID.x % out_limits.x, + linear_idx % out_limits.x, div_by_x % out_limits.y, div_by_x / out_limits.y); diff --git a/backends/vulkan/runtime/graph/ops/glsl/conv2d_dw_q8ta_q8csw_q8to.glsl b/backends/vulkan/runtime/graph/ops/glsl/conv2d_dw_q8ta_q8csw_q8to.glsl index b4196551fa1..a94811ef204 100644 --- a/backends/vulkan/runtime/graph/ops/glsl/conv2d_dw_q8ta_q8csw_q8to.glsl +++ b/backends/vulkan/runtime/graph/ops/glsl/conv2d_dw_q8ta_q8csw_q8to.glsl @@ -46,6 +46,8 @@ layout(push_constant) uniform restrict Block { layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in; +#include "dispatch.glslh" + ${layout_declare_spec_const(C, "int", "apply_bias", "1")} ${layout_declare_spec_const(C, "int", "conv2d_params_stride_x", "1")} ${layout_declare_spec_const(C, "int", "conv2d_params_stride_y", "1")} @@ -69,7 +71,7 @@ ${layout_declare_spec_const(C, "int", "conv2d_params_groups", "1")} #include "conv2d_dw_q8_utils.glslh" void main() { - const int tid = int(gl_GlobalInvocationID.x); + const int tid = int(linear_idx_from_gid()); Conv2dBlockExtents out_block_extents = make_block_extents(output_sizes); Conv2dBlockIndex out_block_idx = linear_idx_to_block_idx( diff --git a/backends/vulkan/runtime/graph/ops/glsl/dispatch.glslh b/backends/vulkan/runtime/graph/ops/glsl/dispatch.glslh new file mode 100644 index 00000000000..a127ff4bb74 --- /dev/null +++ b/backends/vulkan/runtime/graph/ops/glsl/dispatch.glslh @@ -0,0 +1,19 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. + */ + +#ifndef DISPATCH_GLSLH +#define DISPATCH_GLSLH + +uint linear_idx_from_gid() { + // Extend this to include Z if two-dimensional linear dispatches become + // insufficient. + return gl_GlobalInvocationID.x + + gl_GlobalInvocationID.y * gl_NumWorkGroups.x * gl_WorkGroupSize.x; +} + +#endif // DISPATCH_GLSLH diff --git a/backends/vulkan/runtime/graph/ops/glsl/embedding_buffer.glsl b/backends/vulkan/runtime/graph/ops/glsl/embedding_buffer.glsl index f9a46fda141..5b084a1d5cf 100644 --- a/backends/vulkan/runtime/graph/ops/glsl/embedding_buffer.glsl +++ b/backends/vulkan/runtime/graph/ops/glsl/embedding_buffer.glsl @@ -32,6 +32,8 @@ ${layout_declare_ubo(B, "BufferMetadata", "weight")} layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in; +#include "dispatch.glslh" + TensorIndex out_tidx_to_indices_tidx(const TensorIndex out_tidx) { TensorIndex indices_tidx; int d = 0; @@ -56,7 +58,7 @@ T load_weight_elem(const int embedding_idx, const uint dim_idx) { } void main() { - const uint out_bufi = gl_GlobalInvocationID.x; + const uint out_bufi = linear_idx_from_gid(); if (out_of_bounds(out_bufi, outp)) { return; } diff --git a/backends/vulkan/runtime/graph/ops/glsl/expand_buffer.glsl b/backends/vulkan/runtime/graph/ops/glsl/expand_buffer.glsl index 806c27cfd69..cb3b74d0d87 100644 --- a/backends/vulkan/runtime/graph/ops/glsl/expand_buffer.glsl +++ b/backends/vulkan/runtime/graph/ops/glsl/expand_buffer.glsl @@ -27,8 +27,10 @@ ${layout_declare_ubo(B, "BufferMetadata", "inp")} layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in; +#include "dispatch.glslh" + void main() { - const uint outp_bufi = gl_GlobalInvocationID.x; + const uint outp_bufi = linear_idx_from_gid(); if (outp_bufi >= numel(outp)) { return; } diff --git a/backends/vulkan/runtime/graph/ops/glsl/full_buffer.glsl b/backends/vulkan/runtime/graph/ops/glsl/full_buffer.glsl index 729baec324d..8243d13325c 100644 --- a/backends/vulkan/runtime/graph/ops/glsl/full_buffer.glsl +++ b/backends/vulkan/runtime/graph/ops/glsl/full_buffer.glsl @@ -26,8 +26,10 @@ ${layout_declare_ubo(B, "float", "fill_value")} layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in; +#include "dispatch.glslh" + void main() { - const uint out_bufi = gl_GlobalInvocationID.x; + const uint out_bufi = linear_idx_from_gid(); if (out_of_bounds(out_bufi, outp)) { return; } diff --git a/backends/vulkan/runtime/graph/ops/glsl/gather_buffer.glsl b/backends/vulkan/runtime/graph/ops/glsl/gather_buffer.glsl index eadc3403635..5a390b93480 100644 --- a/backends/vulkan/runtime/graph/ops/glsl/gather_buffer.glsl +++ b/backends/vulkan/runtime/graph/ops/glsl/gather_buffer.glsl @@ -32,10 +32,12 @@ ${layout_declare_ubo(B, "BufferMetadata", "index")} layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in; +#include "dispatch.glslh" + ${layout_declare_spec_const(C, "int", "gather_dim", "0")} void main() { - const uint out_bufi = gl_GlobalInvocationID.x; + const uint out_bufi = linear_idx_from_gid(); if (out_of_bounds(out_bufi, outp)) { return; } diff --git a/backends/vulkan/runtime/graph/ops/glsl/im2col_packed_int8.glsl b/backends/vulkan/runtime/graph/ops/glsl/im2col_packed_int8.glsl index a60e52fa12b..e5b7d05863e 100644 --- a/backends/vulkan/runtime/graph/ops/glsl/im2col_packed_int8.glsl +++ b/backends/vulkan/runtime/graph/ops/glsl/im2col_packed_int8.glsl @@ -60,11 +60,13 @@ layout(push_constant) uniform restrict Block { layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in; +#include "dispatch.glslh" + #include "conv2d_int8_output_tile_store.glslh" #include "im2col_packed_int8_utils.glslh" void main() { - const int out_buf_idx = int(gl_GlobalInvocationID.x); + const int out_buf_idx = int(linear_idx_from_gid()); Conv2dBlockExtents im2col_block_extents = make_block_extents(im2col_sizes); diff --git a/backends/vulkan/runtime/graph/ops/glsl/image_to_nchw.glsl b/backends/vulkan/runtime/graph/ops/glsl/image_to_nchw.glsl index c4dcfa688f8..8e5d1f53304 100644 --- a/backends/vulkan/runtime/graph/ops/glsl/image_to_nchw.glsl +++ b/backends/vulkan/runtime/graph/ops/glsl/image_to_nchw.glsl @@ -46,6 +46,8 @@ $if not TO_STAGING: layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in; +#include "dispatch.glslh" + ${layout_declare_spec_const(C, "int", "in_layout", "CONTIG_LAYOUT_INT")} $if not TO_STAGING: @@ -60,7 +62,7 @@ void main() { // the (VRAM-cached) texture reads -- even though each texel is now fetched up // to 4 times, once per component. On unified-memory (mobile) GPUs the extra // fetches are a net loss, so this variant is gated to discrete GPUs. - const int oi = int(gl_GlobalInvocationID.x); + const int oi = int(linear_idx_from_gid()); const int W = inp.sizes.x; const int H = inp.sizes.y; const int C = inp.sizes.z; diff --git a/backends/vulkan/runtime/graph/ops/glsl/index_tensor_buffer.glsl b/backends/vulkan/runtime/graph/ops/glsl/index_tensor_buffer.glsl index f430a570b92..db61e0859f2 100644 --- a/backends/vulkan/runtime/graph/ops/glsl/index_tensor_buffer.glsl +++ b/backends/vulkan/runtime/graph/ops/glsl/index_tensor_buffer.glsl @@ -30,12 +30,14 @@ ${layout_declare_ubo(B, "BufferMetadata", "index")} layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in; +#include "dispatch.glslh" + // Implements aten.index.Tensor for the case where self is 1D and there is // exactly one index tensor. Each output element is: // output[...] = self[index[...]] void main() { - const uint out_bufi = gl_GlobalInvocationID.x; + const uint out_bufi = linear_idx_from_gid(); if (out_of_bounds(out_bufi, outp)) { return; } diff --git a/backends/vulkan/runtime/graph/ops/glsl/int8x4_buffer_to_nchw.glsl b/backends/vulkan/runtime/graph/ops/glsl/int8x4_buffer_to_nchw.glsl index 76e6a6c6238..25fefc1037c 100644 --- a/backends/vulkan/runtime/graph/ops/glsl/int8x4_buffer_to_nchw.glsl +++ b/backends/vulkan/runtime/graph/ops/glsl/int8x4_buffer_to_nchw.glsl @@ -26,12 +26,14 @@ ${layout_declare_ubo(B, "BufferMetadata", "inp")} layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in; +#include "dispatch.glslh" + ${layout_declare_spec_const(C, "int", "inp_layout", "CONTIG_LAYOUT_INT")} void main() { // One thread per output int32 in the NCHW staging buffer. // Each output int32 holds 4 consecutive NCHW bytes. - const uint out_int32_idx = gl_GlobalInvocationID.x; + const uint out_int32_idx = linear_idx_from_gid(); const uint W = inp.sizes[0][0]; const uint H = inp.sizes[0][1]; diff --git a/backends/vulkan/runtime/graph/ops/glsl/linear_dW.glsl b/backends/vulkan/runtime/graph/ops/glsl/linear_dW.glsl index 1a8ed94031b..42fde2111e4 100644 --- a/backends/vulkan/runtime/graph/ops/glsl/linear_dW.glsl +++ b/backends/vulkan/runtime/graph/ops/glsl/linear_dW.glsl @@ -28,6 +28,8 @@ ${layout_declare_ubo(B, "ivec4", "x_sizes")} layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in; +#include "dispatch.glslh" + void main() { // dW[N, K] = sum_m d_out[m, N] * x[m, K]; contraction over the flattened M. const int N = dout_sizes.x; @@ -38,7 +40,7 @@ void main() { const int nkt = (K + TILE_K - 1) / TILE_K; const int tiles = nnt * nkt; - const int tile_idx = int(gl_GlobalInvocationID.x); + const int tile_idx = int(linear_idx_from_gid()); if (tile_idx >= tiles) { return; } diff --git a/backends/vulkan/runtime/graph/ops/glsl/linear_q4gsw_coop.glsl b/backends/vulkan/runtime/graph/ops/glsl/linear_q4gsw_coop.glsl index 505fc3d0009..0f88dc59702 100644 --- a/backends/vulkan/runtime/graph/ops/glsl/linear_q4gsw_coop.glsl +++ b/backends/vulkan/runtime/graph/ops/glsl/linear_q4gsw_coop.glsl @@ -57,6 +57,8 @@ ${layout_declare_ubo(B, "ivec4", "input_sizes")} layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in; +#include "dispatch.glslh" + ${layout_declare_spec_const(C, "int", "apply_bias", "0")} ${layout_declare_spec_const(C, "int", "K4_per_group", "0")} @@ -73,7 +75,7 @@ shared FPOutTile partial_sums[WGS]; void main() { const int lid = int(gl_LocalInvocationID.z); - const int n8 = int(gl_GlobalInvocationID.x); + const int n8 = int(linear_idx_from_gid()); // The output tensor will have a shape of [n, 1, 1, 1]. Each thread computes // 8 output elements, so each thread will write to 8 elements starting at the diff --git a/backends/vulkan/runtime/graph/ops/glsl/linear_qcsnw.glsl b/backends/vulkan/runtime/graph/ops/glsl/linear_qcsnw.glsl index 369112bf7fd..2599f3d67f5 100644 --- a/backends/vulkan/runtime/graph/ops/glsl/linear_qcsnw.glsl +++ b/backends/vulkan/runtime/graph/ops/glsl/linear_qcsnw.glsl @@ -46,6 +46,8 @@ $else: layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in; +#include "dispatch.glslh" + // This header file must be defined after the layout descriptors have been // declared because the functions in the header assume some variables have been // declared as layout descriptors. @@ -57,7 +59,7 @@ layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in; #endif void main() { - const int out_bufi = int(gl_GlobalInvocationID.x); + const int out_bufi = int(linear_idx_from_gid()); if (out_bufi >= out_numel) { return; } @@ -88,9 +90,10 @@ void main() { #else // USING_TEXTURE void main() { + const uint linear_idx = linear_idx_from_gid(); const ivec2 out_pos = ivec2( - gl_GlobalInvocationID.x % out_limits.x, - gl_GlobalInvocationID.x / out_limits.x); + linear_idx % out_limits.x, + linear_idx / out_limits.x); if (out_pos.y >= out_limits.y) { return; diff --git a/backends/vulkan/runtime/graph/ops/glsl/linear_qcsnw_coop.glsl b/backends/vulkan/runtime/graph/ops/glsl/linear_qcsnw_coop.glsl index c1c4f72c600..86c01cfa80e 100644 --- a/backends/vulkan/runtime/graph/ops/glsl/linear_qcsnw_coop.glsl +++ b/backends/vulkan/runtime/graph/ops/glsl/linear_qcsnw_coop.glsl @@ -46,20 +46,23 @@ layout(push_constant) uniform restrict Block { layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in; +#include "dispatch.glslh" + shared VEC4_T partial_sums[NGROUPS][NWORKERS][TILE_ROWS][TILE_TXCOLS]; void main() { + const uint linear_idx = linear_idx_from_gid(); // txcol stands for "texel column". One txcol corresponds to 4 scalar columns. $if TILE_TXCOLS > 1: const uint global_wg_x = uint(divup(out_sizes.x, 4 * TILE_TXCOLS)); const uint out_txcol = uint( - (gl_GlobalInvocationID.x % global_wg_x) * TILE_TXCOLS); + (linear_idx % global_wg_x) * TILE_TXCOLS); $else: const uint global_wg_x = uint(divup4(out_sizes.x)); - const uint out_txcol = uint(gl_GlobalInvocationID.x % global_wg_x); + const uint out_txcol = uint(linear_idx % global_wg_x); const uint out_row = uint( - (gl_GlobalInvocationID.x / global_wg_x) * TILE_ROWS); + (linear_idx / global_wg_x) * TILE_ROWS); $if QUANT_NBITS == 4: const uint weight_txcol = uint(out_txcol / 2); diff --git a/backends/vulkan/runtime/graph/ops/glsl/linear_qcsnw_tiled.glsl b/backends/vulkan/runtime/graph/ops/glsl/linear_qcsnw_tiled.glsl index 1d4a24bacc3..d8f042f54e8 100644 --- a/backends/vulkan/runtime/graph/ops/glsl/linear_qcsnw_tiled.glsl +++ b/backends/vulkan/runtime/graph/ops/glsl/linear_qcsnw_tiled.glsl @@ -42,18 +42,21 @@ layout(push_constant) uniform restrict Block { layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in; +#include "dispatch.glslh" + #extension GL_EXT_shader_explicit_arithmetic_types_int16 : require void main() { + const int linear_idx = int(linear_idx_from_gid()); // txcol stands for "texel column". One txcol corresponds to 4 scalar columns. $if TILE_TXCOLS > 1: const int global_wg_x = divup(out_sizes.x, 4 * TILE_TXCOLS); - const int out_txcol = (int(gl_GlobalInvocationID.x) % global_wg_x) * TILE_TXCOLS; + const int out_txcol = (linear_idx % global_wg_x) * TILE_TXCOLS; $else: const int global_wg_x = divup4(out_sizes.x); - const int out_txcol = int(gl_GlobalInvocationID.x) % global_wg_x; + const int out_txcol = linear_idx % global_wg_x; - const int out_row = (int(gl_GlobalInvocationID.x) / global_wg_x) * TILE_ROWS; + const int out_row = (linear_idx / global_wg_x) * TILE_ROWS; $if QUANT_NBITS == 4: const int weight_txcol = out_txcol / 2; diff --git a/backends/vulkan/runtime/graph/ops/glsl/nchw_to_buffer.glsl b/backends/vulkan/runtime/graph/ops/glsl/nchw_to_buffer.glsl index a6f9fed4471..ef2511f2d89 100644 --- a/backends/vulkan/runtime/graph/ops/glsl/nchw_to_buffer.glsl +++ b/backends/vulkan/runtime/graph/ops/glsl/nchw_to_buffer.glsl @@ -18,13 +18,15 @@ ${layout_declare_ubo(B, "BufferMetadata", "outp")} layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in; +#include "dispatch.glslh" + // This constant is unused in this shader but is kept so that the signature is // consistent with nchw_to_image. ${layout_declare_spec_const(C, "int", "unused", "0")} ${layout_declare_spec_const(C, "int", "transpose_hw", "0")} void main() { - const uint outp_bufi = int(gl_GlobalInvocationID.x); + const uint outp_bufi = linear_idx_from_gid(); if (outp_bufi >= numel(outp)) { return; } diff --git a/backends/vulkan/runtime/graph/ops/glsl/nchw_to_int8x4_buffer.glsl b/backends/vulkan/runtime/graph/ops/glsl/nchw_to_int8x4_buffer.glsl index 6b535400554..f911cfe92b7 100644 --- a/backends/vulkan/runtime/graph/ops/glsl/nchw_to_int8x4_buffer.glsl +++ b/backends/vulkan/runtime/graph/ops/glsl/nchw_to_int8x4_buffer.glsl @@ -26,10 +26,12 @@ ${layout_declare_ubo(B, "BufferMetadata", "outp")} layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in; +#include "dispatch.glslh" + ${layout_declare_spec_const(C, "int", "outp_layout", "CONTIG_LAYOUT_INT")} void main() { - const uint texel_idx = gl_GlobalInvocationID.x; + const uint texel_idx = linear_idx_from_gid(); const uint num_texels = numel(outp) / 4; if (texel_idx >= num_texels) { return; diff --git a/backends/vulkan/runtime/graph/ops/glsl/pad_buffer.glsl b/backends/vulkan/runtime/graph/ops/glsl/pad_buffer.glsl index ea5222c74b3..4b8d1558652 100644 --- a/backends/vulkan/runtime/graph/ops/glsl/pad_buffer.glsl +++ b/backends/vulkan/runtime/graph/ops/glsl/pad_buffer.glsl @@ -32,10 +32,12 @@ ${layout_declare_ubo(B, "float", "fill_value")} layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in; +#include "dispatch.glslh" + ${layout_declare_spec_const(C, "int", "out_layout", "CONTIG_LAYOUT_INT")} void main() { - const uint out_bufi = gl_GlobalInvocationID.x; + const uint out_bufi = linear_idx_from_gid(); if (out_of_bounds(out_bufi, outp)) { return; } diff --git a/backends/vulkan/runtime/graph/ops/glsl/permute_buffer.glsl b/backends/vulkan/runtime/graph/ops/glsl/permute_buffer.glsl index d517003bb8c..b35b0c61488 100644 --- a/backends/vulkan/runtime/graph/ops/glsl/permute_buffer.glsl +++ b/backends/vulkan/runtime/graph/ops/glsl/permute_buffer.glsl @@ -33,6 +33,8 @@ ${layout_declare_spec_const(C, "int", "permute_order", "0")} layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in; +#include "dispatch.glslh" + TensorIndex permute(TensorIndex tidx) { TensorIndex new_tidx = tidx; @@ -50,7 +52,7 @@ TensorIndex permute(TensorIndex tidx) { } void main() { - const uint inp_bufi = gl_GlobalInvocationID.x; + const uint inp_bufi = linear_idx_from_gid(); if (inp_bufi >= numel(inp)) { return; } diff --git a/backends/vulkan/runtime/graph/ops/glsl/pixel_shuffle_buffer.glsl b/backends/vulkan/runtime/graph/ops/glsl/pixel_shuffle_buffer.glsl index 196555a279f..b1b05872538 100644 --- a/backends/vulkan/runtime/graph/ops/glsl/pixel_shuffle_buffer.glsl +++ b/backends/vulkan/runtime/graph/ops/glsl/pixel_shuffle_buffer.glsl @@ -30,6 +30,8 @@ ${layout_declare_ubo(B, "BufferMetadata", "inp")} layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in; +#include "dispatch.glslh" + ${layout_declare_spec_const(C, "int", "outp_layout", "CONTIG_LAYOUT_INT")} ${layout_declare_spec_const(C, "int", "inp_layout", "CONTIG_LAYOUT_INT")} ${layout_declare_spec_const(C, "int", "upscale_factor", "1")} @@ -47,7 +49,7 @@ ${layout_declare_spec_const(C, "int", "upscale_factor", "1")} * mapping is independent of the tensor's memory layout. */ void main() { - const uint outp_bufi = gl_GlobalInvocationID.x; + const uint outp_bufi = linear_idx_from_gid(); if (outp_bufi >= numel(outp)) { return; } diff --git a/backends/vulkan/runtime/graph/ops/glsl/q4gsw_backward.glsl b/backends/vulkan/runtime/graph/ops/glsl/q4gsw_backward.glsl index d89bb83feed..d54fb731956 100644 --- a/backends/vulkan/runtime/graph/ops/glsl/q4gsw_backward.glsl +++ b/backends/vulkan/runtime/graph/ops/glsl/q4gsw_backward.glsl @@ -30,6 +30,8 @@ ${layout_declare_ubo(B, "ivec4", "dx_sizes")} layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in; +#include "dispatch.glslh" + ${layout_declare_spec_const(C, "int", "group_size", "32")} // d_x[M, K] = d_out[M, N] @ dequant(W)[N, K], contracting over N. @@ -44,7 +46,7 @@ void main() { const int nkt = (K + TILE_K - 1) / TILE_K; const int tiles = nmt * nkt; - const int tile_idx = int(gl_GlobalInvocationID.x); + const int tile_idx = int(linear_idx_from_gid()); if (tile_idx >= tiles) { return; } diff --git a/backends/vulkan/runtime/graph/ops/glsl/q8ta_binary.glsl b/backends/vulkan/runtime/graph/ops/glsl/q8ta_binary.glsl index be93e800436..34fe483db10 100644 --- a/backends/vulkan/runtime/graph/ops/glsl/q8ta_binary.glsl +++ b/backends/vulkan/runtime/graph/ops/glsl/q8ta_binary.glsl @@ -44,6 +44,8 @@ layout(push_constant) uniform restrict Block { layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in; +#include "dispatch.glslh" + ${layout_declare_spec_const(C, "int", "out_layout", "CONTIG_LAYOUT_INT")} ${layout_declare_spec_const(C, "int", "in_layout", "CONTIG_LAYOUT_INT")} ${layout_declare_spec_const(C, "int", "other_layout", "CONTIG_LAYOUT_INT")} @@ -58,7 +60,7 @@ define_store_int8x4_buffer_fns(t_out) void main() { // Buffer storage: use linear dispatch - const uint contig_block_idx = gl_GlobalInvocationID.x; + const uint contig_block_idx = linear_idx_from_gid(); TensorIndex4D tidx = contiguous_block_idx_to_tensor4d_idx_with_block_config( out_meta, contig_block_idx, block_config); diff --git a/backends/vulkan/runtime/graph/ops/glsl/q8ta_clone.glsl b/backends/vulkan/runtime/graph/ops/glsl/q8ta_clone.glsl index 0006311e13c..7734b23c32d 100644 --- a/backends/vulkan/runtime/graph/ops/glsl/q8ta_clone.glsl +++ b/backends/vulkan/runtime/graph/ops/glsl/q8ta_clone.glsl @@ -28,6 +28,8 @@ ${layout_declare_ubo(B, "BufferMetadata", "inp")} layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in; +#include "dispatch.glslh" + ${layout_declare_spec_const(C, "int", "inp_layout", "CONTIG_LAYOUT_INT")} ${layout_declare_spec_const(C, "int", "outp_layout", "CONTIG_LAYOUT_INT")} ${layout_declare_spec_const(C, "int", "inp_block_config", "0")} @@ -47,7 +49,7 @@ void main() { TensorIndex4D tidx; // Buffer storage: use linear dispatch - const uint contig_block_idx = gl_GlobalInvocationID.x; + const uint contig_block_idx = linear_idx_from_gid(); tidx = contiguous_block_idx_to_tensor4d_idx_with_block_config( inp, contig_block_idx, inp_block_config); diff --git a/backends/vulkan/runtime/graph/ops/glsl/q8ta_dequantize.glsl b/backends/vulkan/runtime/graph/ops/glsl/q8ta_dequantize.glsl index 88089627911..69343ee04d5 100644 --- a/backends/vulkan/runtime/graph/ops/glsl/q8ta_dequantize.glsl +++ b/backends/vulkan/runtime/graph/ops/glsl/q8ta_dequantize.glsl @@ -44,6 +44,8 @@ layout(push_constant) uniform restrict Block { layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in; +#include "dispatch.glslh" + ${layout_declare_spec_const(C, "int", "outp_layout", "CONTIG_LAYOUT_INT")} ${layout_declare_spec_const(C, "int", "inp_layout", "CONTIG_LAYOUT_INT")} ${layout_declare_spec_const(C, "int", "outp_block_config", "0")} @@ -85,7 +87,7 @@ void main() { #ifdef USING_BUFFER // Buffer storage: use linear dispatch (supports up to 8D) - const uint contig_block_idx = gl_GlobalInvocationID.x; + const uint contig_block_idx = linear_idx_from_gid(); tidx = contiguous_block_idx_to_tensor_idx_with_block_config( inp, contig_block_idx, inp_block_config); #else diff --git a/backends/vulkan/runtime/graph/ops/glsl/q8ta_im2col.glsl b/backends/vulkan/runtime/graph/ops/glsl/q8ta_im2col.glsl index ed4e124ac45..314788cb857 100644 --- a/backends/vulkan/runtime/graph/ops/glsl/q8ta_im2col.glsl +++ b/backends/vulkan/runtime/graph/ops/glsl/q8ta_im2col.glsl @@ -37,8 +37,10 @@ layout(push_constant) uniform restrict Block { layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in; +#include "dispatch.glslh" + void main() { - const int out_buf_idx = int(gl_GlobalInvocationID.x); + const int out_buf_idx = int(linear_idx_from_gid()); // Extract sizes from BufferMetadata const ivec4 im2col_sizes = ivec4(im2col_outp.sizes[0]); diff --git a/backends/vulkan/runtime/graph/ops/glsl/q8ta_linear_gemv.glsl b/backends/vulkan/runtime/graph/ops/glsl/q8ta_linear_gemv.glsl index becff2ab9ab..9153cb0e294 100644 --- a/backends/vulkan/runtime/graph/ops/glsl/q8ta_linear_gemv.glsl +++ b/backends/vulkan/runtime/graph/ops/glsl/q8ta_linear_gemv.glsl @@ -59,6 +59,8 @@ layout(push_constant) uniform restrict Block { layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in; +#include "dispatch.glslh" + #include "common.glslh" #include "linear_int8_weight_tile_load.glslh" #include "linear_fp_output_tile_int8_int8_compute.glslh" @@ -75,7 +77,7 @@ shared ivec4 partial_accums[WGS][TILE_N4]; void main() { const int lid = int(gl_LocalInvocationID.z); - const int n4 = int(gl_GlobalInvocationID.x) * TILE_N4; + const int n4 = int(linear_idx_from_gid()) * TILE_N4; const int n = mul_4(n4); diff --git a/backends/vulkan/runtime/graph/ops/glsl/q8ta_pixel_shuffle.glsl b/backends/vulkan/runtime/graph/ops/glsl/q8ta_pixel_shuffle.glsl index 2de47e1452e..69ce99ec839 100644 --- a/backends/vulkan/runtime/graph/ops/glsl/q8ta_pixel_shuffle.glsl +++ b/backends/vulkan/runtime/graph/ops/glsl/q8ta_pixel_shuffle.glsl @@ -39,6 +39,8 @@ layout(push_constant) uniform restrict Block { layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in; +#include "dispatch.glslh" + ${layout_declare_spec_const(C, "int", "inp_layout", "CONTIG_LAYOUT_INT")} ${layout_declare_spec_const(C, "int", "outp_layout", "CONTIG_LAYOUT_INT")} @@ -90,7 +92,7 @@ void main() { // (along the packed dim) at one (n, oh, ow) spatial position. const int C_words = div_up_4(C_out); const int total_words = N * C_words * H_out * W_out; - const int thread_idx = int(gl_GlobalInvocationID.x); + const int thread_idx = int(linear_idx_from_gid()); if (thread_idx >= total_words) { return; } diff --git a/backends/vulkan/runtime/graph/ops/glsl/q8ta_quantize.glsl b/backends/vulkan/runtime/graph/ops/glsl/q8ta_quantize.glsl index 2f458054a32..739ca327d4f 100644 --- a/backends/vulkan/runtime/graph/ops/glsl/q8ta_quantize.glsl +++ b/backends/vulkan/runtime/graph/ops/glsl/q8ta_quantize.glsl @@ -44,6 +44,8 @@ layout(push_constant) uniform restrict Block { layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in; +#include "dispatch.glslh" + ${layout_declare_spec_const(C, "int", "inp_layout", "CONTIG_LAYOUT_INT")} ${layout_declare_spec_const(C, "int", "outp_layout", "CONTIG_LAYOUT_INT")} ${layout_declare_spec_const(C, "int", "inp_block_config", "0")} @@ -83,7 +85,7 @@ void main() { #ifdef USING_BUFFER // Buffer storage: use linear dispatch (supports up to 8D) - const uint contig_block_idx = gl_GlobalInvocationID.x; + const uint contig_block_idx = linear_idx_from_gid(); tidx = contiguous_block_idx_to_tensor_idx_with_block_config( inp, contig_block_idx, inp_block_config); #else diff --git a/backends/vulkan/runtime/graph/ops/glsl/q8ta_unary.glsl b/backends/vulkan/runtime/graph/ops/glsl/q8ta_unary.glsl index e97d6d47877..5949f3fab52 100644 --- a/backends/vulkan/runtime/graph/ops/glsl/q8ta_unary.glsl +++ b/backends/vulkan/runtime/graph/ops/glsl/q8ta_unary.glsl @@ -40,6 +40,8 @@ layout(push_constant) uniform restrict Block { layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in; +#include "dispatch.glslh" + ${layout_declare_spec_const(C, "int", "out_layout", "CONTIG_LAYOUT_INT")} ${layout_declare_spec_const(C, "int", "in_layout", "CONTIG_LAYOUT_INT")} ${layout_declare_spec_const(C, "int", "block_config", "0")} @@ -52,7 +54,7 @@ define_store_int8x4_buffer_fns(t_out) void main() { // Buffer storage: use linear dispatch - const uint contig_block_idx = gl_GlobalInvocationID.x; + const uint contig_block_idx = linear_idx_from_gid(); TensorIndex4D tidx = contiguous_block_idx_to_tensor4d_idx_with_block_config( out_meta, contig_block_idx, block_config); diff --git a/backends/vulkan/runtime/graph/ops/glsl/repeat_buffer.glsl b/backends/vulkan/runtime/graph/ops/glsl/repeat_buffer.glsl index be2d87a168f..a7a6de4d8a1 100644 --- a/backends/vulkan/runtime/graph/ops/glsl/repeat_buffer.glsl +++ b/backends/vulkan/runtime/graph/ops/glsl/repeat_buffer.glsl @@ -28,8 +28,10 @@ ${layout_declare_ubo(B, "BufferMetadata", "in_meta")} layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in; +#include "dispatch.glslh" + void main() { - const uint out_bufi = gl_GlobalInvocationID.x; + const uint out_bufi = linear_idx_from_gid(); if (out_of_bounds(out_bufi, out_meta)) { return; } diff --git a/backends/vulkan/runtime/graph/ops/glsl/scalar_tensor.glsl b/backends/vulkan/runtime/graph/ops/glsl/scalar_tensor.glsl index b8b73646e8e..372c233ea7c 100644 --- a/backends/vulkan/runtime/graph/ops/glsl/scalar_tensor.glsl +++ b/backends/vulkan/runtime/graph/ops/glsl/scalar_tensor.glsl @@ -27,10 +27,12 @@ ${layout_declare_ubo(B, buffer_scalar_type(SCALAR_VALUE_TYPE), "scalar_value")} layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in; +#include "dispatch.glslh" + #ifdef USING_BUFFER void main() { - const int i = int(gl_GlobalInvocationID.x); + const int i = int(linear_idx_from_gid()); if (i > 0) { return; diff --git a/backends/vulkan/runtime/graph/ops/glsl/split_buffer.glsl b/backends/vulkan/runtime/graph/ops/glsl/split_buffer.glsl index 932617ecb36..b1e69bc1215 100644 --- a/backends/vulkan/runtime/graph/ops/glsl/split_buffer.glsl +++ b/backends/vulkan/runtime/graph/ops/glsl/split_buffer.glsl @@ -29,12 +29,14 @@ ${layout_declare_ubo(B, "BufferMetadata", "inp")} layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in; +#include "dispatch.glslh" + ${layout_declare_spec_const(C, "int", "split_dim", "0")} ${layout_declare_spec_const(C, "int", "split_idx", "0")} ${layout_declare_spec_const(C, "int", "split_offset", "0")} void main() { - const uint out_bufi = gl_GlobalInvocationID.x; + const uint out_bufi = linear_idx_from_gid(); if (out_of_bounds(out_bufi, outp)) { return; } diff --git a/backends/vulkan/runtime/graph/ops/glsl/tan.glsl b/backends/vulkan/runtime/graph/ops/glsl/tan.glsl index 4e6dcab8d35..7ce2dd86644 100644 --- a/backends/vulkan/runtime/graph/ops/glsl/tan.glsl +++ b/backends/vulkan/runtime/graph/ops/glsl/tan.glsl @@ -30,12 +30,13 @@ $else: layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in; +#include "dispatch.glslh" #include "activations.h" #ifdef USING_BUFFER void main() { - const int i = int(gl_GlobalInvocationID.x); + const int i = int(linear_idx_from_gid()); if (i >= numel) { return; } diff --git a/backends/vulkan/runtime/graph/ops/glsl/transfer_buffer.glsl b/backends/vulkan/runtime/graph/ops/glsl/transfer_buffer.glsl index 79b2cd69790..33ec64034cb 100644 --- a/backends/vulkan/runtime/graph/ops/glsl/transfer_buffer.glsl +++ b/backends/vulkan/runtime/graph/ops/glsl/transfer_buffer.glsl @@ -49,10 +49,11 @@ layout(push_constant) uniform restrict Block { layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in; +#include "dispatch.glslh" #include "${OP_NAME}.glslh" void main() { - const uint out_bufi = gl_GlobalInvocationID.x; + const uint out_bufi = linear_idx_from_gid(); if (out_of_bounds(out_bufi, outp)) { return; } diff --git a/backends/vulkan/runtime/graph/ops/glsl/unary_op.glsl b/backends/vulkan/runtime/graph/ops/glsl/unary_op.glsl index d3390229ac1..45aa3ed7133 100644 --- a/backends/vulkan/runtime/graph/ops/glsl/unary_op.glsl +++ b/backends/vulkan/runtime/graph/ops/glsl/unary_op.glsl @@ -37,12 +37,13 @@ float maximum; layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in; +#include "dispatch.glslh" #include "activations.h" #ifdef USING_BUFFER void main() { - const int i = int(gl_GlobalInvocationID.x); + const int i = int(linear_idx_from_gid()); if (i >= numel) { return; } diff --git a/backends/vulkan/runtime/graph/ops/glsl/unfold_copy_buffer.glsl b/backends/vulkan/runtime/graph/ops/glsl/unfold_copy_buffer.glsl index 81c4b6f1940..646c2dec2af 100644 --- a/backends/vulkan/runtime/graph/ops/glsl/unfold_copy_buffer.glsl +++ b/backends/vulkan/runtime/graph/ops/glsl/unfold_copy_buffer.glsl @@ -30,8 +30,10 @@ ${layout_declare_spec_const(C, "int", "step", "1")} layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in; +#include "dispatch.glslh" + void main() { - const uint out_bufi = gl_GlobalInvocationID.x; + const uint out_bufi = linear_idx_from_gid(); if (out_of_bounds(out_bufi, out_meta)) { return; } diff --git a/backends/vulkan/runtime/graph/ops/glsl/update_concat_offset.glsl b/backends/vulkan/runtime/graph/ops/glsl/update_concat_offset.glsl index 44cb30e96c5..def742cefe1 100644 --- a/backends/vulkan/runtime/graph/ops/glsl/update_concat_offset.glsl +++ b/backends/vulkan/runtime/graph/ops/glsl/update_concat_offset.glsl @@ -29,9 +29,11 @@ ${layout_declare_spec_const(C, "int", "concat_dim", "0")} layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in; +#include "dispatch.glslh" + void main() { // Only one thread needs to update the offset - if (gl_GlobalInvocationID.x != 0) { + if (linear_idx_from_gid() != 0) { return; } diff --git a/backends/vulkan/runtime/graph/ops/glsl/view_buffer.glsl b/backends/vulkan/runtime/graph/ops/glsl/view_buffer.glsl index b5c9f71144e..7470a5ceba5 100644 --- a/backends/vulkan/runtime/graph/ops/glsl/view_buffer.glsl +++ b/backends/vulkan/runtime/graph/ops/glsl/view_buffer.glsl @@ -18,6 +18,8 @@ ${layout_declare_ubo(B, "BufferMetadata", "inp")} layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in; +#include "dispatch.glslh" + ${layout_declare_spec_const(C, "int", "outp_layout", "CONTIG_LAYOUT_INT")} ${layout_declare_spec_const(C, "int", "inp_layout", "CONTIG_LAYOUT_INT")} @@ -26,7 +28,7 @@ ${layout_declare_spec_const(C, "int", "inp_layout", "CONTIG_LAYOUT_INT")} * tensor element in the input and output tensors are the same. */ void main() { - const uint outp_bufi = gl_GlobalInvocationID.x; + const uint outp_bufi = linear_idx_from_gid(); if (outp_bufi >= numel(outp)) { return; } diff --git a/backends/vulkan/runtime/graph/ops/glsl/view_convert_buffer.glsl b/backends/vulkan/runtime/graph/ops/glsl/view_convert_buffer.glsl index f947419fa74..e7622db7572 100644 --- a/backends/vulkan/runtime/graph/ops/glsl/view_convert_buffer.glsl +++ b/backends/vulkan/runtime/graph/ops/glsl/view_convert_buffer.glsl @@ -20,6 +20,8 @@ ${layout_declare_ubo(B, "BufferMetadata", "inp")} layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in; +#include "dispatch.glslh" + ${layout_declare_spec_const(C, "int", "outp_layout", "0")} ${layout_declare_spec_const(C, "int", "inp_layout", "0")} @@ -29,7 +31,7 @@ ${layout_declare_spec_const(C, "int", "inp_layout", "0")} * may be different and need conversion. */ void main() { - const uint outp_bufi = gl_GlobalInvocationID.x; + const uint outp_bufi = linear_idx_from_gid(); if (outp_bufi >= numel(outp)) { return; } diff --git a/backends/vulkan/runtime/graph/ops/glsl/where.glsl b/backends/vulkan/runtime/graph/ops/glsl/where.glsl index 6982d41dd3a..4fae9d94437 100644 --- a/backends/vulkan/runtime/graph/ops/glsl/where.glsl +++ b/backends/vulkan/runtime/graph/ops/glsl/where.glsl @@ -41,6 +41,8 @@ $else: layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in; +#include "dispatch.glslh" + ${layout_declare_spec_const(C, "int", "out_layout", "CONTIG_LAYOUT_INT")} ${layout_declare_spec_const(C, "int", "cond_layout", "CONTIG_LAYOUT_INT")} ${layout_declare_spec_const(C, "int", "self_layout", "CONTIG_LAYOUT_INT")} @@ -49,7 +51,7 @@ ${layout_declare_spec_const(C, "int", "other_layout", "CONTIG_LAYOUT_INT")} #ifdef USING_BUFFER void main() { - const uint out_bufi = gl_GlobalInvocationID.x; + const uint out_bufi = linear_idx_from_gid(); if (out_of_bounds(out_bufi, outp)) { return; }