mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-06-07 00:13:17 +00:00
[XNNPACK] support building xnnpack EP for IOS (#13461)
### Description support building xnnpack for IOS ### Motivation and Context <!-- - Why is this change required? What problem does it solve? - If it fixes an open issue, please link to the issue here. -->
This commit is contained in:
parent
07271b6c8a
commit
20c3c35c33
5 changed files with 69 additions and 16 deletions
9
cmake/external/xnnpack.cmake
vendored
9
cmake/external/xnnpack.cmake
vendored
|
|
@ -8,8 +8,13 @@ set(FP16_BUILD_BENCHMARKS OFF CACHE INTERNAL "")
|
|||
set(CLOG_SOURCE_DIR "${PYTORCH_CPUINFO_DIR}/deps/clog")
|
||||
set(CPUINFO_SOURCE_DIR ${PYTORCH_CPUINFO_DIR})
|
||||
|
||||
if(onnxruntime_BUILD_WEBASSEMBLY)
|
||||
execute_process(COMMAND git apply --ignore-space-change --ignore-whitespace ${PROJECT_SOURCE_DIR}/patches/xnnpack/AddEmscriptenSupport.patch WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/${XNNPACK_DIR})
|
||||
# BF16 instructions cause ICE in Android NDK compiler
|
||||
if(CMAKE_ANDROID_ARCH_ABI STREQUAL armeabi-v7a)
|
||||
set(XNNPACK_ENABLE_ARM_BF16 OFF)
|
||||
ENDIF()
|
||||
|
||||
if(onnxruntime_BUILD_WEBASSEMBLY OR CMAKE_SYSTEM_NAME STREQUAL "iOS")
|
||||
execute_process(COMMAND git apply --ignore-space-change --ignore-whitespace ${PROJECT_SOURCE_DIR}/patches/xnnpack/AddEmscriptenAndIosSupport.patch WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/${XNNPACK_DIR})
|
||||
endif()
|
||||
|
||||
add_subdirectory(external/FP16)
|
||||
|
|
|
|||
24
cmake/patches/xnnpack/AddEmscriptenAndIosSupport.patch
Normal file
24
cmake/patches/xnnpack/AddEmscriptenAndIosSupport.patch
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
diff --git a/CMakeLists.txt b/CMakeLists.txt
|
||||
index d53c48aa1..4c987bd7a 100755
|
||||
--- a/CMakeLists.txt
|
||||
+++ b/CMakeLists.txt
|
||||
@@ -105,7 +105,7 @@ ENDIF()
|
||||
|
||||
IF(NOT CMAKE_SYSTEM_NAME)
|
||||
MESSAGE(FATAL_ERROR "CMAKE_SYSTEM_NAME not defined")
|
||||
-ELSEIF(NOT CMAKE_SYSTEM_NAME MATCHES "^(Darwin|Linux|Android|Windows|CYGWIN|MSYS)$")
|
||||
+ELSEIF(NOT CMAKE_SYSTEM_NAME MATCHES "^(Darwin|Linux|Android|Windows|CYGWIN|MSYS|Emscripten|iOS)$")
|
||||
MESSAGE(FATAL_ERROR "Unrecognized CMAKE_SYSTEM_NAME = ${CMAKE_SYSTEM_NAME}")
|
||||
ENDIF()
|
||||
|
||||
@@ -7108,6 +7108,10 @@ IF(MSVC)
|
||||
SET_PROPERTY(SOURCE ${ALL_MICROKERNEL_SRCS} APPEND_STRING PROPERTY COMPILE_FLAGS "$<$<NOT:$<CONFIG:Debug>>: /O2 >")
|
||||
SET_PROPERTY(SOURCE ${HOT_SRCS} APPEND_STRING PROPERTY COMPILE_FLAGS "$<$<NOT:$<CONFIG:Debug>>: /O2 >")
|
||||
SET_PROPERTY(SOURCE ${COLD_SRCS} APPEND_STRING PROPERTY COMPILE_FLAGS "$<$<NOT:$<CONFIG:Debug>>: /O1 >")
|
||||
+ELSEIF(CMAKE_GENERATOR STREQUAL Xcode)
|
||||
+ TARGET_COMPILE_OPTIONS(all_microkernels PRIVATE $<$<NOT:$<CONFIG:Debug>>: -O2 >)
|
||||
+ TARGET_COMPILE_OPTIONS(XNNPACK PRIVATE $<$<NOT:$<CONFIG:Debug>>: -O2 >)
|
||||
+ TARGET_COMPILE_OPTIONS(XNNPACK PRIVATE $<$<NOT:$<CONFIG:Debug>>: -Os >)
|
||||
ELSE()
|
||||
SET_PROPERTY(SOURCE ${ALL_MICROKERNEL_SRCS} APPEND_STRING PROPERTY COMPILE_FLAGS "$<$<NOT:$<CONFIG:Debug>>: -O2 >")
|
||||
SET_PROPERTY(SOURCE ${HOT_SRCS} APPEND_STRING PROPERTY COMPILE_FLAGS "$<$<NOT:$<CONFIG:Debug>>: -O2 >")
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
diff --git a/CMakeLists.txt b/CMakeLists.txt
|
||||
index 937b17f51..af0d2300f 100755
|
||||
--- a/CMakeLists.txt
|
||||
+++ b/CMakeLists.txt
|
||||
@@ -82,7 +82,7 @@ ENDIF()
|
||||
|
||||
IF(NOT CMAKE_SYSTEM_NAME)
|
||||
MESSAGE(FATAL_ERROR "CMAKE_SYSTEM_NAME not defined")
|
||||
-ELSEIF(NOT CMAKE_SYSTEM_NAME MATCHES "^(Darwin|Linux|Android|Windows|CYGWIN|MSYS)$")
|
||||
+ELSEIF(NOT CMAKE_SYSTEM_NAME MATCHES "^(Darwin|Linux|Android|Windows|CYGWIN|MSYS|Emscripten)$")
|
||||
MESSAGE(FATAL_ERROR "Unrecognized CMAKE_SYSTEM_NAME = ${CMAKE_SYSTEM_NAME}")
|
||||
ENDIF()
|
||||
|
||||
|
|
@ -16,6 +16,7 @@
|
|||
"--use_coreml",
|
||||
"--skip_tests",
|
||||
"--cmake_extra_defines=onnxruntime_BUILD_UNIT_TESTS=OFF",
|
||||
"--apple_deploy_target=11.0"
|
||||
"--apple_deploy_target=11.0",
|
||||
"--use_xnnpack"
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,8 @@
|
|||
parameters:
|
||||
- name: BuildXnnpack
|
||||
default: false
|
||||
type: boolean
|
||||
|
||||
jobs:
|
||||
- job: iOS_CI_CPU_on_Mac
|
||||
pool:
|
||||
|
|
@ -58,3 +63,34 @@ jobs:
|
|||
--path_to_protoc_exe $(Build.BinariesDirectory)/protobuf_install/bin/protoc \
|
||||
--parallel
|
||||
displayName: (CoreML EP) Build onnxruntime for iOS x86_64 and run tests using simulator
|
||||
|
||||
- job: iOS_CI_XNNPACK_on_Mac
|
||||
pool:
|
||||
vmImage: 'macOS-11'
|
||||
variables:
|
||||
MACOSX_DEPLOYMENT_TARGET: '10.14'
|
||||
timeoutInMinutes: 100
|
||||
condition: or(eq('${{parameters.BuildXnnpack}}', 'true'), eq(variables['Build.SourceBranch'], 'refs/heads/main'))
|
||||
steps:
|
||||
- script: |
|
||||
/bin/bash $(Build.SourcesDirectory)/tools/ci_build/github/apple/build_host_protoc.sh \
|
||||
$(Build.SourcesDirectory) \
|
||||
$(Build.BinariesDirectory)/protobuf \
|
||||
$(Build.BinariesDirectory)/protobuf_install
|
||||
displayName: Build Host Protoc
|
||||
|
||||
- script: |
|
||||
python3 $(Build.SourcesDirectory)/tools/ci_build/build.py \
|
||||
--skip_submodule_sync \
|
||||
--build_dir $(Build.BinariesDirectory)/iOS_xnnpack \
|
||||
--use_xnnpack \
|
||||
--ios \
|
||||
--ios_sysroot iphonesimulator \
|
||||
--osx_arch x86_64 \
|
||||
--apple_deploy_target 11.0 \
|
||||
--use_xcode \
|
||||
--config RelWithDebInfo \
|
||||
--build_apple_framework \
|
||||
--path_to_protoc_exe $(Build.BinariesDirectory)/protobuf_install/bin/protoc \
|
||||
--parallel
|
||||
displayName: (XNNPACK EP) Build onnxruntime for iOS x86_64 and run tests using simulator
|
||||
|
|
|
|||
Loading…
Reference in a new issue