Skip to content

[ET-VK] Using uint16 for quantized linear tiling shader to reduce register pressure and improve performance. #10509

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

Merged
merged 11 commits into from
Apr 28, 2025
Merged
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
20 changes: 11 additions & 9 deletions backends/vulkan/runtime/graph/ops/glsl/q_8w_linear_tiled.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@ layout(push_constant) uniform restrict Block {

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

#extension GL_EXT_shader_explicit_arithmetic_types_int16 : require

void main() {
const uint out_width_ntexels = divup4(out_sizes.x);
const uint out_col = (gl_GlobalInvocationID.x % out_width_ntexels) << 2;
const uint out_row = (gl_GlobalInvocationID.x / out_width_ntexels) * TILE_ROWS;
const uint16_t out_width_ntexels = uint16_t(divup4(out_sizes.x));
const uint16_t out_col = uint16_t((gl_GlobalInvocationID.x % out_width_ntexels) << 2);
const uint16_t out_row = uint16_t((gl_GlobalInvocationID.x / out_width_ntexels) * TILE_ROWS);

if (out_row >= out_sizes.y) {
if (out_row >= uint16_t(out_sizes.y)) {
return;
}

Expand All @@ -54,29 +56,29 @@ void main() {
VEC4_T c[TILE_ROWS];

$if SCALES_STORAGE == "buffer":
const VEC4_T scales = VEC4_T(t_scales[out_col >> 2]);
const VEC4_T scales = VEC4_T(t_scales[int(out_col >> 2)]);
$else:
const VEC4_T scales = VEC4_T(texelFetch(t_scales, ivec2(out_col >> 2, 0), 0));
const VEC4_T scales = VEC4_T(texelFetch(t_scales, u16vec2(out_col >> 2, 0), 0));

[[unroll]] for (int i = 0; i < TILE_ROWS; ++i) {
c[i] = VEC4_T(0.0);
}

for (int pos = 0; pos < in_sizes.x; pos += 4) {
for (uint16_t pos = uint16_t(0); pos < uint16_t(in_sizes.x); pos += uint16_t(4)) {
// Preload weight tensor
[[unroll]] for (int i = 0; i < 4; i++) {
$if WEIGHT_STORAGE == "buffer":
b[i] = t_weight[((pos + i) * out_sizes.x + out_col) >> 2];
$else:
b[i] = VEC4_T(texelFetch(t_weight, ivec2(out_col >> 2, pos + i), 0));
b[i] = VEC4_T(texelFetch(t_weight, u16vec2(out_col >> 2, pos + i), 0));
}

// Preload input tensor
[[unroll]] for (int i = 0; i < TILE_ROWS; i++) {
$if IN_STORAGE == "buffer":
a[i] = t_in[((out_row + i) * in_sizes.x + pos) >> 2];
$else:
a[i] = VEC4_T(texelFetch(t_in, ivec3(pos >> 2, out_row + i, 0), 0));
a[i] = VEC4_T(texelFetch(t_in, u16vec3(pos >> 2, out_row + i, 0), 0));
}

// Accumulate output
Expand Down
Loading