Support building ARM64EC onnxruntime.dll (#6999)

This commit is contained in:
Ben Niu 2021-03-29 15:35:30 -07:00 committed by GitHub
parent 77c19436c0
commit d1acdd4f4b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 28 additions and 11 deletions

View file

@ -63,6 +63,8 @@ else()
endif()
if(onnxruntime_target_platform STREQUAL "ARM64")
set(onnxruntime_target_platform "ARM64")
elseif(onnxruntime_target_platform STREQUAL "ARM64EC")
set(onnxruntime_target_platform "ARM64EC")
elseif(onnxruntime_target_platform STREQUAL "ARM" OR CMAKE_GENERATOR MATCHES "ARM")
set(onnxruntime_target_platform "ARM")
elseif(onnxruntime_target_platform STREQUAL "x64" OR onnxruntime_target_platform STREQUAL "x86_64" OR onnxruntime_target_platform STREQUAL "AMD64" OR CMAKE_GENERATOR MATCHES "Win64")
@ -71,6 +73,15 @@ elseif(onnxruntime_target_platform STREQUAL "Win32" OR onnxruntime_target_platfo
set(onnxruntime_target_platform "x86")
endif()
if(onnxruntime_target_platform STREQUAL "ARM64EC")
if (MSVC)
link_directories("$ENV{VCINSTALLDIR}/Tools/MSVC/$ENV{VCToolsVersion}/lib/ARM64EC")
link_directories("$ENV{VCINSTALLDIR}/Tools/MSVC/$ENV{VCToolsVersion}/ATLMFC/lib/ARM64EC")
link_libraries(softintrin.lib)
add_compile_options("/bigobj")
endif()
endif()
file(GLOB onnxruntime_common_src CONFIGURE_DEPENDS
${onnxruntime_common_src_patterns}
)

View file

@ -54,7 +54,7 @@ if(MSVC)
)
list(APPEND mlas_platform_srcs ${obj_filename})
endforeach()
elseif(onnxruntime_target_platform STREQUAL "ARM")
elseif((onnxruntime_target_platform STREQUAL "ARM") OR (onnxruntime_target_platform STREQUAL "ARM64EC"))
set(mlas_platform_srcs
${ONNXRUNTIME_ROOT}/core/mlas/lib/arm/sgemmc.cpp
)

View file

@ -35,7 +35,7 @@ Abstract:
// Define the target architecture.
//
#if defined(_M_AMD64) || defined(__x86_64__)
#if (defined(_M_AMD64) && !defined(_M_ARM64EC)) || defined(__x86_64__)
#define MLAS_TARGET_AMD64
#endif
#if defined(_M_IX86) || defined(__i386__)
@ -47,7 +47,7 @@ Abstract:
#if defined(_M_ARM64) || defined(__aarch64__)
#define MLAS_TARGET_ARM64
#endif
#if defined(_M_ARM) || defined(__arm__)
#if defined(_M_ARM) || defined(_M_ARM64EC) || defined(__arm__)
#define MLAS_TARGET_ARM
#endif
#if defined(__VSX__)

View file

@ -22,7 +22,7 @@
#include "Eigen/src/Core/arch/Default/BFloat16.h"
#include "Eigen/src/Core/arch/Default/Half.h"
#if defined(_M_AMD64)
#if defined(_M_AMD64) && !defined(_M_ARM64EC)
#include "core/mlas/inc/mlas.h"
#endif
@ -207,7 +207,7 @@ struct TensorCaster<std::string, DstType> {
}
};
#if defined(_M_AMD64)
#if defined(_M_AMD64) && !defined(_M_ARM64EC)
// specializations to use optimized and Windows x64-specific
// MlasConvertHalfToFloatBuffer() routine for MLFloat16 -> float conversion

View file

@ -268,6 +268,10 @@ def parse_arguments():
"--arm64", action='store_true',
help="Create ARM64 makefiles. Requires --update and no existing cache "
"CMake setup. Delete CMakeCache.txt if needed")
parser.add_argument(
"--arm64ec", action='store_true',
help="Create ARM64EC makefiles. Requires --update and no existing cache "
"CMake setup. Delete CMakeCache.txt if needed")
parser.add_argument(
"--msvc_toolset", help="MSVC toolset to use. e.g. 14.11")
parser.add_argument("--android", action='store_true', help='Build for Android')
@ -679,7 +683,7 @@ def generate_build_tree(cmake_path, source_dir, build_dir, cuda_home, cudnn_home
"-Donnxruntime_MIGRAPHX_HOME=" + (migraphx_home if args.use_migraphx else ""),
# By default - we currently support only cross compiling for ARM/ARM64
# (no native compilation supported through this script).
"-Donnxruntime_CROSS_COMPILING=" + ("ON" if args.arm64 or args.arm else "OFF"),
"-Donnxruntime_CROSS_COMPILING=" + ("ON" if args.arm64 or args.arm64ec or args.arm else "OFF"),
"-Donnxruntime_DISABLE_CONTRIB_OPS=" + ("ON" if args.disable_contrib_ops else "OFF"),
"-Donnxruntime_DISABLE_ML_OPS=" + ("ON" if args.disable_ml_ops else "OFF"),
"-Donnxruntime_DISABLE_RTTI=" + ("ON" if args.disable_rtti else "OFF"),
@ -1626,7 +1630,7 @@ def is_cross_compiling_on_apple(args):
def build_protoc_for_host(cmake_path, source_dir, build_dir, args):
if (args.arm or args.arm64 or args.enable_windows_store) and \
if (args.arm or args.arm64 or args.arm64ec or args.enable_windows_store) and \
not (is_windows() or is_cross_compiling_on_apple(args)):
raise BuildError(
'Currently only support building protoc for Windows host while '
@ -1738,7 +1742,7 @@ def main():
args = parse_arguments()
cmake_extra_defines = (args.cmake_extra_defines
if args.cmake_extra_defines else [])
cross_compiling = args.arm or args.arm64 or args.android
cross_compiling = args.arm or args.arm64 or args.arm64ec or args.android
# If there was no explicit argument saying what to do, default
# to update, build and test (for native builds).
@ -1837,7 +1841,7 @@ def main():
update_submodules(source_dir)
if is_windows():
if args.cmake_generator == 'Ninja':
if args.x86 or args.arm or args.arm64:
if args.x86 or args.arm or args.arm64 or args.arm64ec:
raise BuildError(
"To cross-compile with Ninja, load the toolset "
"environment for the target processor (e.g. Cross "
@ -1847,7 +1851,7 @@ def main():
cmake_extra_args = [
'-A', 'Win32', '-T', 'host=x64', '-G', args.cmake_generator
]
elif args.arm or args.arm64:
elif args.arm or args.arm64 or args.arm64ec:
# Cross-compiling for ARM(64) architecture
# First build protoc for host to use during cross-compilation
if path_to_protoc_exe is None:
@ -1855,8 +1859,10 @@ def main():
cmake_path, source_dir, build_dir, args)
if args.arm:
cmake_extra_args = ['-A', 'ARM']
else:
elif args.arm64:
cmake_extra_args = ['-A', 'ARM64']
elif args.arm64ec:
cmake_extra_args = ['-A', 'ARM64EC']
cmake_extra_args += ['-G', args.cmake_generator]
# Cannot test on host build machine for cross-compiled
# builds (Override any user-defined behaviour for test if any)