From b34d238e79d703a4627c355e9444092a4f3b1fa3 Mon Sep 17 00:00:00 2001 From: Stephen Jia Date: Tue, 14 Jul 2026 15:48:34 -0700 Subject: [PATCH 1/2] [ET][Windows] Fix ExecuTorch Windows host build portability defects Pull Request resolved: https://github.com/pytorch/executorch/pull/20948 Building ExecuTorch (Vulkan backend plus core runtime) for a Windows x86_64 host with the arvr clang toolchain surfaced three genuine portability defects that fail under its strict `-Werror` set and generated-header wiring. These are correct fixes independent of any warning-suppression workaround. In `runtime/core/portable_type/c10/c10/targets.bzl`, the arvr-mode `select` that supplies the generated `ATen/Config.h` routed every non-Android OS to `ovrsource_aten_Config.h`, an OVR-native-only `oxx_static_library` that produces no output on the Windows host. The result was `fatal error: 'ATen/Config.h' file not found` in every CPU kernel that includes ATen vec headers. This adds an `ovr_config//os:windows` branch pointing at the working `generated_aten_config_header`, mirroring the existing Android fallback. In `backends/vulkan/runtime/api/containers/Tensor.h`, `size()` and `dim()` returned `const int64_t` by value; the meaningless top-level `const` on a scalar return trips `-Werror,-Wignored-qualifiers`. This header is included throughout the Vulkan backend, so it blocked `vulkan_graph_runtime`. The `const` qualifier is dropped. In `extension/data_loader/mman.h` and `mman_windows.cpp`, `#define NOMINMAX` was unconditional while the toolchain already predefines it, tripping `-Werror,-Wmacro-redefined` when compiling `mmap_data_loader` (pulled in by `Module`). Both sites are now guarded with `#ifndef NOMINMAX`. ghstack-source-id: 402995448 @exported-using-ghexport Differential Revision: [D112012051](https://our.internmc.facebook.com/intern/diff/D112012051/) --- backends/vulkan/runtime/api/containers/Tensor.h | 4 ++-- extension/data_loader/mman.h | 4 ++++ extension/data_loader/mman_windows.cpp | 4 ++++ runtime/core/portable_type/c10/c10/targets.bzl | 5 +++-- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/backends/vulkan/runtime/api/containers/Tensor.h b/backends/vulkan/runtime/api/containers/Tensor.h index 30c243aedd5..83c714bbc90 100644 --- a/backends/vulkan/runtime/api/containers/Tensor.h +++ b/backends/vulkan/runtime/api/containers/Tensor.h @@ -549,11 +549,11 @@ class vTensor final { return sizes_; } - inline const int64_t size(size_t dim) const { + inline int64_t size(size_t dim) const { return sizes().at(dim); } - inline const int64_t dim() const { + inline int64_t dim() const { return sizes_.size(); } diff --git a/extension/data_loader/mman.h b/extension/data_loader/mman.h index 9d3ee4be5aa..1d8df959692 100644 --- a/extension/data_loader/mman.h +++ b/extension/data_loader/mman.h @@ -81,9 +81,13 @@ ET_INLINE void fcntl_rdadvise_apple(int fd, size_t file_size) { #else +#ifndef NOMINMAX #define NOMINMAX #include #undef NOMINMAX +#else +#include +#endif #include #include diff --git a/extension/data_loader/mman_windows.cpp b/extension/data_loader/mman_windows.cpp index 9bc655a7827..67e211c4ca4 100644 --- a/extension/data_loader/mman_windows.cpp +++ b/extension/data_loader/mman_windows.cpp @@ -23,9 +23,13 @@ #include #include #include +#ifndef NOMINMAX #define NOMINMAX #include #undef NOMINMAX +#else +#include +#endif #ifndef STATUS_SECTION_TOO_BIG #define STATUS_SECTION_TOO_BIG 0xC0000040L diff --git a/runtime/core/portable_type/c10/c10/targets.bzl b/runtime/core/portable_type/c10/c10/targets.bzl index 4c49232ae5c..675c04f97a1 100644 --- a/runtime/core/portable_type/c10/c10/targets.bzl +++ b/runtime/core/portable_type/c10/c10/targets.bzl @@ -81,9 +81,10 @@ def define_common_targets(): "ovr_config//build_mode:arvr_mode[enabled]": select({ "DEFAULT": ["fbsource//xplat/caffe2:ovrsource_aten_Config.h"], # ovrsource_aten_Config.h is an oxx_static_library that only - # works on OVR-native platforms. On Android, it produces no - # outputs, so use the xplat variant instead. + # works on OVR-native platforms. On Android and the Windows + # host, it produces no outputs, so use the xplat variant. "ovr_config//os:android": ["fbsource//xplat/caffe2:generated_aten_config_header"], + "ovr_config//os:windows": ["fbsource//xplat/caffe2:generated_aten_config_header"], }), }) + get_sleef_deps(), fbcode_exported_deps = ([ From f7302546610f626489bce94f0c3b4946db9162a8 Mon Sep 17 00:00:00 2001 From: Stephen Jia Date: Tue, 14 Jul 2026 15:48:35 -0700 Subject: [PATCH 2/2] [ET][Windows] Relax -Werror for ExecuTorch CPU kernels on the Windows host Pull Request resolved: https://github.com/pytorch/executorch/pull/20949 The arvr Windows clang toolchain enables a stricter `-Werror` warning set than the sanctioned ET build platforms, and vendored third-party headers that ExecuTorch does not own trip it. VMA's `vk_mem_alloc.h` hits `-Werror,-Winconsistent-missing-destructor-override`, and PyTorch's `ATen/cpu/vec/vec_base.h` uses `#if __GNUC__ <= 12` without `defined(__GNUC__)`, hitting `-Werror,-Wundef`. Because the offending code is in vendored headers we cannot patch, this disables warnings-as-errors for the affected compiles, scoped to `ovr_config//os:windows` only, so the clang target compiles are relaxed while the MSVC host tools and all non-Windows platforms are untouched. `backends/vulkan/targets.bzl` adds `-Wno-error` to the Vulkan targets (VMA header). The CPU-kernel build is split across four independent macros/targets, each of which includes the ATen vec headers and so needs the same relaxation: `kernels/portable/op_registration_util.bzl`, `kernels/optimized/op_registration_util.bzl`, the `binary_ops` support library in `kernels/optimized/cpu/targets.bzl`, and the `libblas` support library in `kernels/optimized/lib_defs.bzl`. ghstack-source-id: 402995445 @exported-using-ghexport Differential Revision: [D112012049](https://our.internmc.facebook.com/intern/diff/D112012049/) --- backends/vulkan/targets.bzl | 8 +++++++- kernels/optimized/cpu/targets.bzl | 12 ++++++++++++ kernels/optimized/lib_defs.bzl | 9 +++++++++ .../kernels/optimized/op_registration_util.bzl | 11 +++++++++++ .../kernels/portable/op_registration_util.bzl | 13 +++++++++++-- 5 files changed, 50 insertions(+), 3 deletions(-) diff --git a/backends/vulkan/targets.bzl b/backends/vulkan/targets.bzl index b1105a08c51..d2dee601399 100644 --- a/backends/vulkan/targets.bzl +++ b/backends/vulkan/targets.bzl @@ -10,7 +10,13 @@ def get_vulkan_compiler_flags(): "-Wno-global-constructors", "-Wno-missing-prototypes", ], - "ovr_config//os:windows": [], + # The Windows clang host build needs -Werror relaxed for the vendored + # VMA headers, but MSVC cl.exe rejects the gcc-style flag, so exclude + # pure MSVC. OSS buck2 has no compiler constraint, so guard to non-OSS. + "ovr_config//os:windows": select({ + "DEFAULT": ["-Wno-error"], + "ovr_config//compiler:msvc": [], + }) if not runtime.is_oss else ["-Wno-error"], }) def get_vulkan_preprocessor_flags(no_volk, is_fbcode): diff --git a/kernels/optimized/cpu/targets.bzl b/kernels/optimized/cpu/targets.bzl index 9d54a5038bc..8e0f0b86408 100644 --- a/kernels/optimized/cpu/targets.bzl +++ b/kernels/optimized/cpu/targets.bzl @@ -48,6 +48,18 @@ def define_common_targets(): srcs = ["binary_ops.cpp"], exported_headers = ["binary_ops.h"], visibility = ["PUBLIC"], + # ATen vec headers trip -Werror warnings on the Windows clang host; + # MSVC cl.exe rejects the gcc-style flag. + compiler_flags = select({ + "DEFAULT": [], + # OSS buck2 has no compiler constraint (ovr_config//compiler:msvc + # resolves to the nonexistent prelude//compiler:msvc), so it cannot + # appear as a select key there; guard the MSVC branch to non-OSS. + "ovr_config//os:windows": select({ + "DEFAULT": ["-Wno-error"], + "ovr_config//compiler:msvc": [], + }) if not runtime.is_oss else ["-Wno-error"], + }), exported_deps = [ "//executorch/runtime/core/exec_aten:lib", "//executorch/runtime/kernel:kernel_includes", diff --git a/kernels/optimized/lib_defs.bzl b/kernels/optimized/lib_defs.bzl index 928fc44635d..2ea329a8baa 100644 --- a/kernels/optimized/lib_defs.bzl +++ b/kernels/optimized/lib_defs.bzl @@ -214,6 +214,15 @@ def define_libs(is_fbcode=False): # TODO: replace with get_compiler_optimization_flags from op_registration_util.bzl when that # is re-enabled. "DEFAULT": ["-Os"], + }) + select({ + "DEFAULT": [], + # ATen vec headers trip -Werror warnings on the Windows clang + # host; MSVC cl.exe rejects the gcc-style flag. OSS buck2 has no + # compiler constraint, so guard the MSVC branch to non-OSS. + "ovr_config//os:windows": select({ + "DEFAULT": ["-Wno-error"], + "ovr_config//compiler:msvc": [], + }) if not runtime.is_oss else ["-Wno-error"], }), header_namespace = "executorch/kernels/optimized", visibility = ["PUBLIC"], diff --git a/shim_et/xplat/executorch/kernels/optimized/op_registration_util.bzl b/shim_et/xplat/executorch/kernels/optimized/op_registration_util.bzl index 4da5db56310..7e32f5b7473 100644 --- a/shim_et/xplat/executorch/kernels/optimized/op_registration_util.bzl +++ b/shim_et/xplat/executorch/kernels/optimized/op_registration_util.bzl @@ -109,6 +109,17 @@ def define_op_library(name, compiler_flags, deps): "ovr_config//os:zephyr": [ "-Wno-pass-failed", ], + # The vendored ATen vec headers trip several -Werror warnings on + # the Windows (clang) host, so disable warnings-as-errors there. + "ovr_config//os:windows": select({ + "DEFAULT": [ + "-Wno-missing-prototypes", + "-Wno-pass-failed", + "-Wno-error", + ], + # MSVC cl.exe rejects the gcc-style flags above. + "ovr_config//compiler:msvc": [], + }), }) if not runtime.is_oss else [ "-Wno-missing-prototypes", "-Wno-pass-failed", diff --git a/shim_et/xplat/executorch/kernels/portable/op_registration_util.bzl b/shim_et/xplat/executorch/kernels/portable/op_registration_util.bzl index 65016cd1ca1..f1a46616295 100644 --- a/shim_et/xplat/executorch/kernels/portable/op_registration_util.bzl +++ b/shim_et/xplat/executorch/kernels/portable/op_registration_util.bzl @@ -124,13 +124,22 @@ def define_op_library(name, deps, android_deps, aten_target, _allow_third_party_ # Zephyr and Windows builds. OSS bypasses the zephyr branch via # runtime.is_oss since ovr_config//os:zephyr is not in the OSS # buck2 prelude. + # The vendored ATen vec headers pulled in on the Windows host trip + # several -Werror warnings (e.g. -Wundef on __GNUC__), so disable + # warnings-as-errors for the Windows (clang) kernel compiles. compiler_flags = (select({ "DEFAULT": ["-Wno-missing-prototypes"], - "ovr_config//os:windows": [], + "ovr_config//os:windows": select({ + "DEFAULT": ["-Wno-error"], + "ovr_config//compiler:msvc": [], + }), "ovr_config//os:zephyr": [], }) if not runtime.is_oss else select({ "DEFAULT": ["-Wno-missing-prototypes"], - "ovr_config//os:windows": [], + # OSS buck2 has no compiler constraint (ovr_config//compiler:msvc + # resolves to the nonexistent prelude//compiler:msvc), so it + # cannot appear as a select key. Use the clang flag directly. + "ovr_config//os:windows": ["-Wno-error"], })) + ( # For shared library build, we don't want to expose symbols of # kernel implementation (ex torch::executor::native::tanh_out)