Vulkan: make half-variant GLSL PRECISION configurable#19292
Closed
jgibson2 wants to merge 2 commits intopytorch:mainfrom
Closed
Vulkan: make half-variant GLSL PRECISION configurable#19292jgibson2 wants to merge 2 commits intopytorch:mainfrom
jgibson2 wants to merge 2 commits intopytorch:mainfrom
Conversation
The set(..CACHE TYPE DOCSTRING [FORCE]) form treats the docstring as a
single argument, but `${DESCRIPTION}` was being expanded unquoted, so
multi-word descriptions were spilling their trailing words into
subsequent set() arguments. This is latent for the common case because
most existing STRING options are driven by the else-branch (not overridden
via -D), but any STRING option overridden on the cmake command line with
a multi-word description hits it — for example:
cmake -DEXECUTORCH_VULKAN_FP16_PRECISION=mediump ...
fails with the description text being fed to the downstream shader
generator as CLI args.
One-char fix: quote "${DESCRIPTION}" in both set() calls. Correct for
both single- and multi-word descriptions.
Add EXECUTORCH_VULKAN_FP16_PRECISION cmake option (default "highp" — upstream-identical behavior). When set to "mediump" (or "lowp"), gen_vulkan_spv.py overrides the PRECISION define in shader variants where DTYPE=half. GLSL's mediump is a driver hint that fp16 ALUs may be used for arithmetic. On Mali GPUs this is typically honored and gives measurable conv speedups (~15% on Pixel 9 Mali G715 for this repo's conv2d_half / conv2d_pw_tiled_half workloads); on Adreno it is typically ignored (harmless). Accuracy tradeoff: mediump relaxes minimum precision guarantees for fp16 shader math. Kept off by default so this cannot silently affect any existing build. Exposed via scripts/build_android_library.sh env var for Android users. Wiring: * backends/vulkan/runtime/gen_vulkan_spv.py: --fp16-precision CLI flag, forwarded into SPVGenerator.create_shader_params(). * backends/vulkan/cmake/ShaderLibrary.cmake: forward cmake var into the python invocation when set. * tools/cmake/preset/default.cmake: declare overridable STRING option. * scripts/build_android_library.sh: read EXECUTORCH_VULKAN_FP16_PRECISION from env, default "highp".
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/19292
Note: Links to docs will display an error until the docs builds have been completed. ❗ 1 Active SEVsThere are 1 currently active SEVs. If your PR is affected, please view them below:
|
Contributor
Author
|
@pytorchbot label "release notes: android" |
Contributor
Author
|
Closing in favor of #19287 |
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
Add
EXECUTORCH_VULKAN_FP16_PRECISIONcmake option (defaulthighp— upstream-identical behavior). When set tomediump(orlowp),gen_vulkan_spv.pyoverrides thePRECISIONdefine in shader variants whereDTYPE=half.GLSL's
mediumpis a driver hint that fp16 ALUs may be used for arithmetic. On Mali GPUs this is typically honored and gives measurable conv speedups (~15% on Pixel 9 Mali G715 for this repo'sconv2d_half/conv2d_pw_tiled_halfworkloads); on Adreno it is typically ignored (harmless).Accuracy tradeoff:
mediumprelaxes minimum precision guarantees for fp16 shader math. Kept off by default so this cannot silently affect any existing build. Exposed viascripts/build_android_library.shenv var for Android users.Wiring:
backends/vulkan/runtime/gen_vulkan_spv.py:--fp16-precisionCLI flag, forwarded intoSPVGenerator.create_shader_params().backends/vulkan/cmake/ShaderLibrary.cmake: forward cmake var into the python invocation when set.tools/cmake/preset/default.cmake: declare overridableSTRINGoption.scripts/build_android_library.sh: readEXECUTORCH_VULKAN_FP16_PRECISIONfrom env, defaulthighp.Test plan
main.-DEXECUTORCH_VULKAN_FP16_PRECISION=mediump: half-variant shaders emitprecision mediump floatinstead ofprecision highp float.conv2d_half/conv2d_pw_tiled_half.🤖 Authored with Claude Code