-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Patch onnxruntime to compile with clang-cl (#165)
* Fix onnxruntime port for clang-cl * Bump port versions * [onnxruntime] clang arch options for SSE * several features fail with clang-cl, but ok * may requires customized triplet file for clang-cl --------- Co-authored-by: luncliff <[email protected]>
- Loading branch information
Showing
6 changed files
with
105 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
diff --git a/cmake/onnxruntime_mlas.cmake b/cmake/onnxruntime_mlas.cmake | ||
index bee83ff07c..04b4cf42b7 100644 | ||
--- a/cmake/onnxruntime_mlas.cmake | ||
+++ b/cmake/onnxruntime_mlas.cmake | ||
@@ -159,15 +159,27 @@ function(setup_mlas_source_for_windows) | ||
) | ||
set_source_files_properties(${mlas_platform_srcs_avx2} PROPERTIES COMPILE_FLAGS "/arch:AVX2") | ||
|
||
+ file(GLOB_RECURSE mlas_platform_srcs_avx512 CONFIGURE_DEPENDS | ||
+ "${MLAS_SRC_DIR}/intrinsics/avx512/*.cpp" | ||
+ ) | ||
+ set(mlas_platform_srcs_amx "${MLAS_SRC_DIR}/qgemm_kernel_amx.cpp") | ||
+ | ||
+ # clang-cl requires us to enable the platform feature flags explicitly to compile the intrinsics code | ||
+ # unlike MSVC. See: https://github.com/llvm/llvm-project/issues/53520 | ||
+ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") | ||
+ set_source_files_properties(${mlas_platform_srcs_avx512} PROPERTIES COMPILE_FLAGS "/arch:AVX512") | ||
+ set_source_files_properties(${mlas_platform_srcs_amx} PROPERTIES COMPILE_FLAGS "/arch:AVX512 -mamx-tile -mamx-int8") | ||
+ endif() | ||
+ | ||
target_sources(onnxruntime_mlas PRIVATE | ||
${MLAS_SRC_DIR}/dgemm.cpp | ||
${mlas_platform_srcs_avx} | ||
${mlas_platform_srcs_avx2} | ||
- ${MLAS_SRC_DIR}/qgemm_kernel_amx.cpp | ||
+ ${mlas_platform_srcs_avx512} | ||
+ ${mlas_platform_srcs_amx} | ||
${MLAS_SRC_DIR}/qgemm_kernel_avx2.cpp | ||
${MLAS_SRC_DIR}/qgemm_kernel_sse.cpp | ||
${MLAS_SRC_DIR}/qgemm_kernel_sse41.cpp | ||
- ${MLAS_SRC_DIR}/intrinsics/avx512/quantize_avx512f.cpp | ||
${MLAS_SRC_DIR}/amd64/QgemmU8S8KernelAmx.asm | ||
${MLAS_SRC_DIR}/amd64/QgemmU8S8KernelAvx2.asm | ||
${MLAS_SRC_DIR}/amd64/QgemmU8U8KernelAvx2.asm | ||
@@ -205,9 +217,15 @@ function(setup_mlas_source_for_windows) | ||
${MLAS_SRC_DIR}/amd64/ErfKernelFma3.asm | ||
) | ||
if (NOT onnxruntime_ORT_MINIMAL_BUILD) | ||
- target_sources(onnxruntime_mlas PRIVATE | ||
+ set(onnxruntime_mlas_q4gemm_avx512 | ||
${MLAS_SRC_DIR}/q4gemm_avx512.cpp | ||
) | ||
+ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") | ||
+ # clang-cl requires us to enable the platform feature flags explicitly to compile the intrinsics code | ||
+ # unlike MSVC. See: https://github.com/llvm/llvm-project/issues/53520 | ||
+ set_source_files_properties(${onnxruntime_mlas_q4gemm_avx512} PROPERTIES COMPILE_FLAGS "/arch:AVX512 -mavx512vnni") | ||
+ endif() | ||
+ target_sources(onnxruntime_mlas PRIVATE ${onnxruntime_mlas_q4gemm_avx512}) | ||
endif() | ||
else() | ||
target_sources(onnxruntime_mlas PRIVATE | ||
diff --git a/cmake/onnxruntime_mlas.cmake b/cmake/onnxruntime_mlas.cmake | ||
index 5c294b5..a466c77 100644 | ||
--- a/cmake/onnxruntime_mlas.cmake | ||
+++ b/cmake/onnxruntime_mlas.cmake | ||
@@ -169,6 +169,9 @@ function(setup_mlas_source_for_windows) | ||
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") | ||
set_source_files_properties(${mlas_platform_srcs_avx512} PROPERTIES COMPILE_FLAGS "/arch:AVX512") | ||
set_source_files_properties(${mlas_platform_srcs_amx} PROPERTIES COMPILE_FLAGS "/arch:AVX512 -mamx-tile -mamx-int8") | ||
+ # https://clang.llvm.org/docs/UsersManual.html#cpu-architectures-features-and-limitations | ||
+ set_source_files_properties(${MLAS_SRC_DIR}/qgemm_kernel_sse.cpp PROPERTIES COMPILE_FLAGS "-march=x86-64") | ||
+ set_source_files_properties(${MLAS_SRC_DIR}/qgemm_kernel_sse41.cpp PROPERTIES COMPILE_FLAGS "-march=x86-64-v2") | ||
endif() | ||
|
||
target_sources(onnxruntime_mlas PRIVATE | ||
diff --git a/onnxruntime/core/mlas/lib/qgemm_kernel_sse41.cpp b/onnxruntime/core/mlas/lib/qgemm_kernel_sse41.cpp | ||
index 68931c5..6c095bd 100644 | ||
--- a/onnxruntime/core/mlas/lib/qgemm_kernel_sse41.cpp | ||
+++ b/onnxruntime/core/mlas/lib/qgemm_kernel_sse41.cpp | ||
@@ -16,6 +16,10 @@ Abstract: | ||
|
||
#include "mlasi.h" | ||
#include "qgemm.h" | ||
+#if defined(__clang__) | ||
+#include <smmintrin.h> | ||
+#include <tmmintrin.h> | ||
+#endif | ||
|
||
// N.B. MSVC does not require turning on SSE 4.1 intrinsics and the current use | ||
// for this code is Windows only, so restrict this kernel to that environment. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
diff --git a/onnxruntime/core/dll/onnxruntime.rc b/onnxruntime/core/dll/onnxruntime.rc | ||
index 4b08dfdb7e..c566a4f713 100644 | ||
--- a/onnxruntime/core/dll/onnxruntime.rc | ||
+++ b/onnxruntime/core/dll/onnxruntime.rc | ||
@@ -32,9 +32,9 @@ BEGIN | ||
VALUE "FileDescription", "ONNX Runtime" | ||
VALUE "FileVersion", VER_STRING | ||
VALUE "InternalName", "ONNX Runtime" | ||
- VALUE "LegalCopyright", "\251 Microsoft Corporation. All rights reserved." | ||
+ VALUE "LegalCopyright", L"\251 Microsoft Corporation. All rights reserved." | ||
VALUE "OriginalFilename", FILE_NAME | ||
- VALUE "ProductName", "Microsoft\256 Windows\256 Operating System" | ||
+ VALUE "ProductName", L"Microsoft\256 Windows\256 Operating System" | ||
VALUE "ProductVersion", VER_STRING | ||
END | ||
END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters