[ET-VK][build] Fix Windows Vulkan/Android build and llama ETDump profiling#21148
Conversation
…iling
Summary:
Three additive, backward-compatible fixes needed to build the ExecuTorch Vulkan
backend and profile the llama runner from a Windows host. Each is guarded so it
is a no-op on non-Windows / non-profiling builds.
- backends/vulkan/runtime/gen_vulkan_spv.py: normalize CRLF -> LF at the top of
preprocess() before the trailing-backslash macro-continuation regex. GLSL
templates checked out with CRLF otherwise leave a lone backslash that escape()
turns into an unterminated Python string literal
("SyntaxError: unterminated string literal") during shader codegen.
- third-party/CMakeLists.txt: allow importing a prebuilt host flatc/flatcc via
FLATC_EXECUTABLE / FLATCC_EXECUTABLE instead of building them from source. The
existing WIN32 host-tool build only supports the Visual Studio generator
(VS-only CMAKE_GENERATOR_PLATFORM, .exe-less BUILD_BYPRODUCTS), which fails
under the Ninja generator required by the Android NDK cross-compile.
- examples/models/llama/CMakeLists.txt: link etdump and define
ET_EVENT_TRACER_ENABLED when the etdump target exists (i.e. core libs built
with EXECUTORCH_BUILD_DEVTOOLS=ON + EXECUTORCH_ENABLE_EVENT_TRACER=ON). This
enables ETDump collection and makes the Vulkan delegate emit per-dispatch GPU
timestamps for per-shader profiling.
Test Plan:
Cross-compiled ExecuTorch core libs + llama_main for Android arm64 with the
Vulkan backend enabled from a Windows host (NDK r29, Ninja generator, imported
host flatc/flatcc). Confirmed libvulkan_backend.a is linked and llama_main runs
on a Galaxy S24 (Adreno 750): Qwen3 0.6B ~80 tok/s decode, Llama 3.2 1B 8da4w
~60 tok/s decode. With DEVTOOLS/EVENT_TRACER on, collected an ETDump containing
per-shader Vulkan events and analyzed prefill/decode breakdown via
custom_inspector.py --mode llm.
Reviewers:
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/21148
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: ✅ No FailuresAs of commit f4a0e68 with merge base 86c3470 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This PR needs a
|
Three additive, backward-compatible fixes needed to build the ExecuTorch Vulkan backend and profile the llama runner from a Windows host. Each change is guarded so it is a no-op on non-Windows / non-profiling builds.
Fixes
backends/vulkan/runtime/gen_vulkan_spv.py— normalize CRLF to LF at the top ofpreprocess(), before the trailing-backslash macro-continuation regex runs. GLSL templates checked out with CRLF line endings otherwise leave a lone backslash thatescape()turns into an unterminated Python string literal (SyntaxError: unterminated string literal) during shader codegen.third-party/CMakeLists.txt— allow importing a prebuilt hostflatc/flatccviaFLATC_EXECUTABLE/FLATCC_EXECUTABLEinstead of building them from source. The existingWIN32host-tool build only supports the Visual Studio generator (VS-onlyCMAKE_GENERATOR_PLATFORM,.exe-lessBUILD_BYPRODUCTS), which fails under the Ninja generator required by the Android NDK cross-compile.examples/models/llama/CMakeLists.txt— linketdumpand defineET_EVENT_TRACER_ENABLEDwhen theetdumptarget exists (i.e. core libs built withEXECUTORCH_BUILD_DEVTOOLS=ON+EXECUTORCH_ENABLE_EVENT_TRACER=ON). This enables ETDump collection and makes the Vulkan delegate emit per-dispatch GPU timestamps for per-shader profiling.All three changes are additive and guarded, so they are no-ops on non-Windows hosts and on non-profiling builds.
Test plan
Cross-compiled ExecuTorch core libs +
llama_mainfor Android arm64 with the Vulkan backend enabled from a Windows host (NDK r29, Ninja generator, imported hostflatc/flatcc). Confirmedlibvulkan_backend.ais linked andllama_mainruns on a Galaxy S24 (Adreno 750): Qwen3 0.6B ~80 tok/s decode, Llama 3.2 1B 8da4w ~60 tok/s decode. With DEVTOOLS/EVENT_TRACER on, collected an ETDump containing per-shader Vulkan events and analyzed the prefill/decode breakdown viacustom_inspector.py --mode llm.This PR was authored with Claude Code.
🤖 Generated with Claude Code
cc @manuelcandales @digantdesai @cbilgin