Skip to content

Commit 01f80e7

Browse files
Qualcomm AI Engine Direct - Support Windows native build (pytorch#20052)
## Summary This PR updates the CMake files to enable native Windows builds for the QNN ExecuTorch components. Specifically, it adds support for building both the QNN backend as a Windows dynamic library (.dll) and the corresponding runner executable (.exe). ## Core Changes ### 1. CMake Enhancements - Extend existing CMake to support native Windows builds. - Enable generation of `qnn_executorch_backend.dll` and `qnn_executor_runner.exe`. ### 2. Build Script Support - Provide a dedicated build script to simplify and standardize the Windows build process. - The script configures the appropriate CMake options and toolchain settings required for Windows. ## Build instructions 1. `.\install_executorch.bat` to build `PyQnnManagerAdaptor*.pyd` and its static library as dependencies. 2. `.\backends\qualcomm\scripts\build.ps1 -SkipArm64Windows -Release` to build Windows x86_64 AOT on Windows x86_64. 3. `.\backends\qualcomm\scripts\build.ps1 -SkipX86Windows -Release` to cross compile and build WoA Runtime on Windows x86_64. ## Follow-up - Add PyTorch documentation change. --------- Co-authored-by: Cheng-Hsin Weng <chenweng@qti.qualcomm.com>
1 parent d0a8dd6 commit 01f80e7

13 files changed

Lines changed: 497 additions & 50 deletions

File tree

backends/qualcomm/CMakeLists.txt

Lines changed: 47 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,11 @@ if(${ANDROID})
7777
find_library(android_log log)
7878
endif()
7979

80-
add_compile_options("-Wall" "-Werror" "-fvisibility=hidden")
80+
if(MSVC)
81+
add_compile_options("/wd4996")
82+
else()
83+
add_compile_options("-Wall" "-Werror" "-fvisibility=hidden")
84+
endif()
8185
add_compile_definitions(C10_USING_CUSTOM_GENERATED_MACROS)
8286

8387
# GNU emits warning for ignored attributes Unfortunately, we use
@@ -89,21 +93,26 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
8993
endif()
9094

9195
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
92-
# strip symbols
93-
add_link_options(LINKER:-s,--gc-sections)
94-
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES Hexagon)
95-
add_compile_options(
96-
"-Os"
97-
"-ffunction-sections"
98-
"-fdata-sections"
99-
"-frtti"
100-
"-fno-exceptions"
101-
"-fomit-frame-pointer"
102-
"-fno-asynchronous-unwind-tables"
103-
)
96+
if(MSVC)
97+
add_compile_options("/O2")
10498
else()
105-
106-
add_compile_options("-O3" "-ffunction-sections" "-fdata-sections" "-frtti")
99+
# strip symbols
100+
add_link_options(LINKER:-s,--gc-sections)
101+
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES Hexagon)
102+
add_compile_options(
103+
"-Os"
104+
"-ffunction-sections"
105+
"-fdata-sections"
106+
"-frtti"
107+
"-fno-exceptions"
108+
"-fomit-frame-pointer"
109+
"-fno-asynchronous-unwind-tables"
110+
)
111+
else()
112+
add_compile_options(
113+
"-O3" "-ffunction-sections" "-fdata-sections" "-frtti"
114+
)
115+
endif()
107116
endif()
108117
endif()
109118

@@ -275,16 +284,27 @@ if(${CMAKE_SYSTEM_PROCESSOR} MATCHES Hexagon)
275284
)
276285
endif()
277286

278-
set_target_properties(
279-
qnn_executorch_backend PROPERTIES LINK_FLAGS "-Wl,-rpath='$ORIGIN'"
280-
)
287+
if(MSVC)
288+
target_compile_definitions(
289+
qnn_executorch_backend PRIVATE QNN_EXECUTORCH_BUILDING_DLL
290+
)
291+
set_target_properties(
292+
qnn_executorch_backend PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON
293+
)
294+
else()
295+
set_target_properties(
296+
qnn_executorch_backend PROPERTIES LINK_FLAGS "-Wl,-rpath='$ORIGIN'"
297+
)
298+
endif()
281299
target_link_libraries(
282300
shared_buffer PRIVATE qnn_executorch_logging ${CMAKE_DL_LIBS}
283301
)
284302
#
285303
# add linker option
286304
#
287-
executorch_target_link_options_shared_lib(qnn_executorch_backend)
305+
if(NOT MSVC)
306+
executorch_target_link_options_shared_lib(qnn_executorch_backend)
307+
endif()
288308

289309
#
290310
# add sources
@@ -316,7 +336,7 @@ if(${CMAKE_SYSTEM_PROCESSOR} MATCHES Hexagon)
316336
endif()
317337

318338
# QNN pybind
319-
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64")
339+
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64|AMD64")
320340
add_subdirectory(
321341
${EXECUTORCH_SOURCE_DIR}/third-party/pybind11
322342
${CMAKE_CURRENT_BINARY_DIR}/pybind11
@@ -350,9 +370,13 @@ if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64")
350370

351371
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
352372
# need to allow exceptions in pybind
353-
set(_pybind_compile_options -Wno-deprecated-declarations -fPIC -frtti
354-
-fexceptions
355-
)
373+
if(MSVC)
374+
set(_pybind_compile_options /wd4996 /EHsc)
375+
else()
376+
set(_pybind_compile_options -Wno-deprecated-declarations -fPIC -frtti
377+
-fexceptions
378+
)
379+
endif()
356380
target_compile_options(
357381
PyQnnManagerAdaptor PUBLIC ${_pybind_compile_options}
358382
)

backends/qualcomm/aot/wrappers/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
# wrappers
88
target_sources(
99
wrappers
10-
PUBLIC ${CMAKE_CURRENT_LIST_DIR}/TensorWrapper.cpp
11-
${CMAKE_CURRENT_LIST_DIR}/TensorWrapper.h
12-
PRIVATE ${CMAKE_CURRENT_LIST_DIR}/QuantizeParamsWrapper.cpp
10+
PUBLIC ${CMAKE_CURRENT_LIST_DIR}/TensorWrapper.h
11+
PRIVATE ${CMAKE_CURRENT_LIST_DIR}/TensorWrapper.cpp
12+
${CMAKE_CURRENT_LIST_DIR}/QuantizeParamsWrapper.cpp
1313
${CMAKE_CURRENT_LIST_DIR}/QuantizeParamsWrapper.h
1414
${CMAKE_CURRENT_LIST_DIR}/OpWrapper.cpp
1515
${CMAKE_CURRENT_LIST_DIR}/OpWrapper.h

backends/qualcomm/runtime/backends/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ target_sources(
4444
)
4545

4646
set(platform target)
47-
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES x86_64)
47+
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64|AMD64")
4848
set(platform host)
4949
endif()
5050

0 commit comments

Comments
 (0)