From eb4fa84fb9faa8252e4a911c454c029644177735 Mon Sep 17 00:00:00 2001 From: Stephen Jia Date: Thu, 19 Nov 2026 14:18:41 -0800 Subject: [PATCH] [ET-VK][runtime] Fix channels-last buffer index decode above 4D Pull Request resolved: https://github.com/pytorch/executorch/pull/25306 ## Rationale **What**: The channels-last fast path of `linear_idx_to_tensor_idx` now decodes dims 4-7 in their real dim order. **Why**: It hard-coded the upper dim order as `(6, 5, 4, 7)`, but channels-packed buffers above 4D order those dims `(4, 5, 6, 7)`. When WHCN dims 4 and 5 are both larger than 1, dim 4 was decoded with the wrong stride. Both the scalar and vec4 buffer `permute` shaders use this path. For example, permuting `(2, 3, 2, 2, 5, 6)` by `(0, 1, 4, 2, 5, 3)` into a channels-packed buffer gave wrong outputs. ## Details - Channels-last decode order (innermost first) - **Before**: `(2, 0, 1, 3, 6, 5, 4, 7)` - **After**: `(2, 0, 1, 3, 4, 5, 6, 7)` - `cases.py` adds that 6D permute case with leading dim 2 to the buffer permute highdim suite. Authored with Claude Code. Differential Revision: [D133233613](https://our.internmc.facebook.com/intern/diff/D133233613/) ghstack-source-id: 478906420 --- backends/vulkan/runtime/graph/ops/glsl/indexing.glslh | 2 +- backends/vulkan/test/op_tests/cases.py | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/backends/vulkan/runtime/graph/ops/glsl/indexing.glslh b/backends/vulkan/runtime/graph/ops/glsl/indexing.glslh index fd2c31938d9..af9ba9bcfac 100644 --- a/backends/vulkan/runtime/graph/ops/glsl/indexing.glslh +++ b/backends/vulkan/runtime/graph/ops/glsl/indexing.glslh @@ -418,7 +418,7 @@ TensorIndex linear_idx_to_tensor_idx_channelslast_case( uint linear_idx) { TensorIndex tidx; - const uint dim_order[DIMLIMIT] = uint[DIMLIMIT](2, 0, 1, 3, 6, 5, 4, 7); + const uint dim_order[DIMLIMIT] = uint[DIMLIMIT](2, 0, 1, 3, 4, 5, 6, 7); [[unroll]] for (int d = DIMLIMIT - 1; d >= 0; --d) { uint dim = dim_order[d]; diff --git a/backends/vulkan/test/op_tests/cases.py b/backends/vulkan/test/op_tests/cases.py index 08625e4c234..28774dd7261 100644 --- a/backends/vulkan/test/op_tests/cases.py +++ b/backends/vulkan/test/op_tests/cases.py @@ -1148,7 +1148,12 @@ def get_permute_inputs(): # Pixel shuffle decomposed into view -> permute -> view, which leaves a # packed dim of size 2. - highdim_test_suite = VkTestSuite([((1, 3, 2, 2, 5, 6), (0, 1, 4, 2, 5, 3))]) + highdim_test_suite = VkTestSuite( + [ + ((1, 3, 2, 2, 5, 6), (0, 1, 4, 2, 5, 3)), + ((2, 3, 2, 2, 5, 6), (0, 1, 4, 2, 5, 3)), + ] + ) highdim_test_suite.layouts = test_suite.layouts highdim_test_suite.storage_types = ["utils::kBuffer"] highdim_test_suite.dtypes = ["at::kFloat", "at::kInt"]