Vulkan: hoist the pointwise conv spatial divides out of the K loop - #22780
Open
msluszniak wants to merge 1 commit into
Open
Vulkan: hoist the pointwise conv spatial divides out of the K loop#22780msluszniak wants to merge 1 commit into
msluszniak wants to merge 1 commit into
Conversation
conv2d_pw_tiled recovers the (x, y) texel coordinate from the flattened spatial index with a divide and a modulo by W_out. W_out is a runtime uniform, so neither strength reduces to a shift, and both sat inside the loop over K: once per (m, k4) on the input loads, and again per output texel on the store. The coordinates depend only on m, so a conv with K4 = 4 issued four times as many integer divides as the arithmetic they fed. Compute them once per invocation and pass them down. On a Mali-G76, selfie segmentation fp16 at 256x256 spends 66% of its GPU time in this shader, and that drops from 8.02 ms to 4.18 ms (1.92x); whole-graph GPU time goes 12.2 ms to 8.3 ms and end-to-end inference 14.6 ms to 10.7 ms. Output is bit identical before and after.
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/22780
Note: Links to docs will display an error until the docs builds have been completed.
|
This PR needs a
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
conv2d_pw_tiledrecovers the(x, y)texel coordinate from the flattened spatial index with a divide and a modulo byW_out.W_outis a runtime uniform, so neither strength reduces to a shift, and both sat inside the loop overK: once per(m, k4)on the input loads, and again per output texel on the store. The coordinates depend only onm, so a conv withK4 = 4issued four times as many integer divides as the arithmetic they fed.This computes them once per invocation and passes them down. No change to the tiling, the dispatch, or the math.
Measurements
Three models, both GPU vendors. Arms interleaved within one session, per-dispatch GPU timestamps from the query pool, median of 3 rounds. Mali-G76 is a Galaxy S10+, Adreno 840 a Galaxy S26 Ultra.
conv2d_pwshareconv2d_pwThe gain tracks how much of the graph is pointwise convolution and how deep the K loop is, which is why lraspp gains most: more channels means more K iterations, so more redundant divides per invocation. A transformer with no pointwise convs (CLIP ViT-B/32 vision, 0 such dispatches) is unaffected at 1.000x, as expected.
End to end on lraspp this is 310.3 -> 114.1 ms on Mali. For reference the XNNPACK int8 build of the same model, which is what that backend ships as its Android default, measures 93.0 ms there.
Interleaving matters on the Mali part: the same binary reads 25.2 ms hot and 8.0 ms settled, so arms measured in separate sessions are not comparable. Within a session, round to round spread is under 1%.
Correctness
Output is bit identical before and after on every model measured,
max |diff| = 0.0, including on inputs chosen to produce non-degenerate outputs.