Skip to content

Commit 566a7ed

Browse files
committed
[Windows] misc fixes to enable Windows build
Summary: ## Context Implement some small miscellaneous fixes to enable installing ExecuTorch on Windows. Currently, the optimized kernels cannot be built successfully but the installation works in custom ops are not built. ## Installation ```powershell cd executorch # Need to disable building custom kernels; there are a bunch of build errors $env:EXECUTORCH_BUILD_KERNELS_CUSTOM_AOT=0 # For some reason need to explicitly enable tensor extension otherwise I see a linker error $env:CMAKE_ARGS="-DEXECUTORCH_BUILD_EXTENSION_TENSOR=ON" python install_executorch.py # Unset if you want Remove-Item Env:\EXECUTORCH_BUILD_KERNELS_CUSTOM_AOT Remove-Item Env:\CMAKE_ARGS ``` ## Testing I am able to follow the [Getting Started tutorial](https://pytorch.org/executorch/stable/getting-started-setup.html#run-your-program) successfully. ## Outstanding Build Issues Currently, with CMake I can successfully build with the following settings: ``` del -Recurse -Force cmake-out; ` cmake . ` -DCMAKE_INSTALL_PREFIX=cmake-out ` -DPYTHON_EXECUTABLE=C:\\Users\\ssjia\\AppData\\Local\\miniconda3\\python.exe ` -DCMAKE_PREFIX_PATH=C:\\Users\\ssjia\\AppData\\Local\\miniconda3\\Lib\\site-packages ` -DCMAKE_BUILD_TYPE=Release ` -DEXECUTORCH_BUILD_EXTENSION_TENSOR=ON ` -DEXECUTORCH_BUILD_PYBIND=ON ` -DEXECUTORCH_BUILD_XNNPACK=ON ` -DEXECUTORCH_BUILD_KERNELS_QUANTIZED_AOT=ON ` -DEXECUTORCH_BUILD_KERNELS_CUSTOM_AOT=ON ` -DEXECUTORCH_BUILD_KERNELS_CUSTOM=OFF ` -T ClangCL ` -Bcmake-out; ` cmake --build cmake-out -j64 --target install ``` If I switch `EXECUTORCH_BUILD_KERNELS_CUSTOM` to `ON`, then the build fails. The primary offenders appear to be the `gelu`. The implementation includes a header from ATen which is causing the majority of the errors.
1 parent 4f02b33 commit 566a7ed

File tree

4 files changed

+28
-18
lines changed

4 files changed

+28
-18
lines changed

backends/xnnpack/CMakeLists.txt

+11-3
Original file line numberDiff line numberDiff line change
@@ -73,34 +73,42 @@ foreach(fbs_file ${_xnnpack_schema__srcs})
7373
)
7474
endforeach()
7575

76+
if(WIN32)
77+
set(MV_COMMAND powershell -Command "Move-Item -Path ${_xnnpack_flatbuffer__outputs} -Destination ${_xnnpack_schema__outputs}")
78+
else()
79+
set(MV_COMMAND mv ${_xnnpack_flatbuffer__outputs} ${_xnnpack_schema__outputs})
80+
endif()
81+
7682
# Generate the headers from the .fbs files.
7783
add_custom_command(
7884
OUTPUT ${_xnnpack_schema__outputs}
7985
COMMAND
8086
${FLATC_EXECUTABLE} --cpp --cpp-std c++11 --scoped-enums -o
8187
"${_xnnpack_schema__include_dir}/executorch/backends/xnnpack/serialization"
8288
${_xnnpack_schema__srcs}
83-
COMMAND mv ${_xnnpack_flatbuffer__outputs} ${_xnnpack_schema__outputs}
89+
COMMAND ${MV_COMMAND}
8490
WORKING_DIRECTORY ${EXECUTORCH_ROOT}
8591
COMMENT "Generating xnnpack_schema headers"
8692
VERBATIM
8793
)
8894

95+
unset(MV_COMMAND)
96+
8997
add_library(xnnpack_schema INTERFACE ${_xnnpack_schema__outputs})
9098
set_target_properties(xnnpack_schema PROPERTIES LINKER_LANGUAGE CXX)
9199
target_include_directories(
92100
xnnpack_schema INTERFACE ${_xnnpack_schema__include_dir}
93101
${EXECUTORCH_ROOT}/third-party/flatbuffers/include
94102
)
95103

96-
set(xnnpack_third_party pthreadpool cpuinfo)
104+
set(xnnpack_third_party pthreadpool extension_threadpool cpuinfo)
97105

98106
include(cmake/Dependencies.cmake)
99107

100108
list(TRANSFORM _xnnpack_backend__srcs PREPEND "${EXECUTORCH_ROOT}/")
101109
add_library(xnnpack_backend STATIC ${_xnnpack_backend__srcs})
102110
target_link_libraries(
103-
xnnpack_backend PRIVATE ${xnnpack_third_party} executorch_core xnnpack_schema
111+
xnnpack_backend PUBLIC ${xnnpack_third_party} executorch_core xnnpack_schema
104112
)
105113

106114
target_include_directories(

extension/llm/custom_ops/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ if(CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64|arm64|armv7)$")
4949
list(APPEND _custom_ops__srcs
5050
"extension/llm/custom_ops/spinquant/third-party/FFHT/fht_neon.c"
5151
)
52-
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
52+
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|AMD64)")
5353
list(APPEND _custom_ops__srcs
5454
"extension/llm/custom_ops/spinquant/third-party/FFHT/fht_avx.c"
5555
)

install_executorch.bat

+2-8
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,8 @@ rem This batch file provides a basic functionality similar to the bash script.
77

88
cd /d "%~dp0"
99

10-
rem Find the names of the python tools to use (replace with your actual python installation)
11-
if "%PYTHON_EXECUTABLE%"=="" (
12-
if "%CONDA_DEFAULT_ENV%"=="" OR "%CONDA_DEFAULT_ENV%"=="base" OR NOT EXIST "python" (
13-
set PYTHON_EXECUTABLE=python3
14-
) else (
15-
set PYTHON_EXECUTABLE=python
16-
)
17-
)
10+
rem Under windows, it's always python
11+
set PYTHON_EXECUTABLE=python
1812

1913
"%PYTHON_EXECUTABLE%" install_executorch.py %*
2014

setup.py

+14-6
Original file line numberDiff line numberDiff line change
@@ -345,22 +345,30 @@ def inplace_dir(self, installer: "InstallerBuildExt") -> Path:
345345
class BuiltExtension(_BaseExtension):
346346
"""An extension that installs a python extension that was built by cmake."""
347347

348-
def __init__(self, src: str, modpath: str):
348+
def __init__(self, src: str, modpath: str, src_dir: Optional[str] = None):
349349
"""Initializes a BuiltExtension.
350350
351351
Args:
352-
src: The path to the file to install (typically a shared library),
353-
relative to the cmake-out directory. May be an fnmatch-style
354-
glob that matches exactly one file. If the path ends in `.so`,
355-
this class will also look for similarly-named `.dylib` files.
352+
src_dir: The directory of the file to install, relative to the cmake-out
353+
directory. A placeholder %BUILD_TYPE% will be replaced with the build
354+
type for multi-config generators (like Visual Studio) where the build
355+
output is in a subdirectory named after the build type. For single-
356+
config generators (like Makefile Generators or Ninja), this placeholder
357+
will be removed.
358+
src_name: The name of the file to install. If the path ends in `.so`,
356359
modpath: The dotted path of the python module that maps to the
357360
extension.
358361
"""
359362
assert (
360363
"/" not in modpath
361364
), f"modpath must be a dotted python module path: saw '{modpath}'"
365+
full_src = src
366+
if src_dir is None and platform.system() == "Windows":
367+
src_dir = "%BUILD_TYPE%/"
368+
if src_dir is not None:
369+
full_src = os.path.join(src_dir, src)
362370
# This is a real extension, so use the modpath as the name.
363-
super().__init__(src=f"%CMAKE_CACHE_DIR%/{src}", dst=modpath, name=modpath)
371+
super().__init__(src=f"%CMAKE_CACHE_DIR%/{full_src}", dst=modpath, name=modpath)
364372

365373
def src_path(self, installer: "InstallerBuildExt") -> Path:
366374
"""Returns the path to the source file, resolving globs.

0 commit comments

Comments
 (0)