Skip to content

Vulkan: make half-variant GLSL PRECISION configurable#19292

Closed
jgibson2 wants to merge 2 commits intopytorch:mainfrom
PolyCam:jgibson/vulkan-fp16-precision-option
Closed

Vulkan: make half-variant GLSL PRECISION configurable#19292
jgibson2 wants to merge 2 commits intopytorch:mainfrom
PolyCam:jgibson/vulkan-fp16-precision-option

Conversation

@jgibson2
Copy link
Copy Markdown
Contributor

@jgibson2 jgibson2 commented May 5, 2026

Summary

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.

Note: overriding this option on the cmake command line (e.g. -DEXECUTORCH_VULKAN_FP16_PRECISION=mediump) requires the define_overridable_option DESCRIPTION-quoting fix from #19293 — without it, the multi-word description spills into subsequent set() arguments. The default-value path works either way.

Test plan

  • Default (no override): bit-identical SPIR-V to current main.
  • -DEXECUTORCH_VULKAN_FP16_PRECISION=mediump: half-variant shaders emit precision mediump float instead of precision highp float.
  • Pixel 9 (Mali G715) Vulkan delegate: ~15% speedup on conv2d_half / conv2d_pw_tiled_half.
  • Pixel 9 Adreno (separate run): no regression; driver appears to ignore the hint.

🤖 Authored with Claude Code

jgibson2 added 2 commits May 5, 2026 09:58
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".
@pytorch-bot pytorch-bot Bot added the module: vulkan Issues related to the Vulkan delegate and code under backends/vulkan/ label May 5, 2026
@pytorch-bot
Copy link
Copy Markdown

pytorch-bot Bot commented May 5, 2026

🔗 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 SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

⚠️ 11 Awaiting Approval

As of commit 2ca72a0 with merge base 8a397b4 (image):

AWAITING APPROVAL - The following workflows need approval before CI can run:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label May 5, 2026
@jgibson2
Copy link
Copy Markdown
Contributor Author

jgibson2 commented May 5, 2026

@pytorchbot label "release notes: android"

@pytorch-bot pytorch-bot Bot added the release notes: android Android Java and JNI code label May 5, 2026
@jgibson2
Copy link
Copy Markdown
Contributor Author

jgibson2 commented May 5, 2026

Closing in favor of #19287

@jgibson2 jgibson2 closed this May 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. module: vulkan Issues related to the Vulkan delegate and code under backends/vulkan/ release notes: android Android Java and JNI code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant