From c1a5cb65c853012cf7baff2deec41643a3d7cd93 Mon Sep 17 00:00:00 2001 From: Changming Sun Date: Wed, 13 Dec 2023 14:14:18 -0800 Subject: [PATCH 1/5] Restrict clang version --- cmake/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 7494035e4784e..b3679ba63e28c 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -61,6 +61,8 @@ endif() if("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" AND CMAKE_C_COMPILER_VERSION VERSION_LESS 8) message(FATAL_ERROR "GCC version must be greater than or equal to 8") +elseif("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang" AND CMAKE_C_COMPILER_VERSION VERSION_LESS 16) + message(FATAL_ERROR "GCC version must be greater than or equal to 16") endif() # Options From 931e0bdde6799159249609427124058246603936 Mon Sep 17 00:00:00 2001 From: Changming Sun Date: Thu, 14 Dec 2023 09:36:04 -0800 Subject: [PATCH 2/5] update --- .../android-arm64-v8a-QNN-crosscompile-ci-pipeline.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/ci_build/github/azure-pipelines/android-arm64-v8a-QNN-crosscompile-ci-pipeline.yml b/tools/ci_build/github/azure-pipelines/android-arm64-v8a-QNN-crosscompile-ci-pipeline.yml index e2ca4f64a0ecb..1f7d185fb30dd 100644 --- a/tools/ci_build/github/azure-pipelines/android-arm64-v8a-QNN-crosscompile-ci-pipeline.yml +++ b/tools/ci_build/github/azure-pipelines/android-arm64-v8a-QNN-crosscompile-ci-pipeline.yml @@ -53,6 +53,8 @@ jobs: - script: sudo apt-get update -y && sudo apt-get install -y coreutils ninja-build displayName: Install coreutils and ninja + - template: "templates/use-android-ndk.yml" + - script: sudo chmod go+rw /dev/kvm displayName: Update permissions to KVM From 1cf122399444179401dece6e9515b69e78b86676 Mon Sep 17 00:00:00 2001 From: Changming Sun Date: Mon, 18 Dec 2023 16:44:09 -0800 Subject: [PATCH 3/5] update --- cmake/CMakeLists.txt | 29 ++++++++++++++++--------- cmake/adjust_global_compile_flags.cmake | 25 +++++++++++++++++++++ 2 files changed, 44 insertions(+), 10 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index b3679ba63e28c..b04e6a5bd8fc8 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -61,8 +61,6 @@ endif() if("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" AND CMAKE_C_COMPILER_VERSION VERSION_LESS 8) message(FATAL_ERROR "GCC version must be greater than or equal to 8") -elseif("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang" AND CMAKE_C_COMPILER_VERSION VERSION_LESS 16) - message(FATAL_ERROR "GCC version must be greater than or equal to 16") endif() # Options @@ -354,13 +352,7 @@ if (onnxruntime_USE_ROCM) endif() endif() -if (APPLE) - if (NOT CMAKE_OSX_ARCHITECTURES) - message("Building ONNX Runtime for ${CMAKE_HOST_SYSTEM_PROCESSOR}") - endif() -elseif (NOT WIN32 AND NOT APPLE) - message("Building ONNX Runtime for ${CMAKE_SYSTEM_PROCESSOR}") -endif() + # Single output director for all binaries set(RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin CACHE PATH "Single output directory for all binaries.") @@ -493,6 +485,14 @@ endif() include(adjust_global_compile_flags.cmake) +if (APPLE) + if (NOT CMAKE_OSX_ARCHITECTURES) + message("Building ONNX Runtime for ${CMAKE_HOST_SYSTEM_PROCESSOR} CPU ARCH") + endif() +elseif (NOT WIN32 AND NOT APPLE) + message("Building ONNX Runtime for ${onnxruntime_target_platform} CPU ARCH") +endif() + # We need to link with libatomic on systems that do not have built-in atomics, or # don't have built-in support for 8 byte atomics # Derived from https://github.com/protocolbuffers/protobuf/blob/master/cmake/CMakeLists.txt @@ -639,7 +639,16 @@ else() check_cxx_compiler_flag(-Wunused-variable HAS_UNUSED_VARIABLE) check_cxx_compiler_flag(-Wuseless-cast HAS_USELESS_CAST) check_function_exists(reallocarray HAS_REALLOCARRAY) - + if (NOT APPLE AND onnxruntime_target_platform STREQUAL "aarch64") + check_cxx_compiler_flag(-march=armv8.2-a+bf16 HAS_ARM64_BFLOAT16) + if(NOT HAS_ARM64_BFLOAT16) + message(FATAL_ERROR "The compiler doesn't support BFLOAT16!!!") + endif() + check_cxx_compiler_flag(-march=armv8.2-a+fp16 HAS_ARM64_FLOAT16) + if(NOT HAS_ARM64_FLOAT16) + message(FATAL_ERROR "The compiler doesn't support FLOAT16!!!") + endif() + endif() if (HAS_TAUTOLOGICAL_POINTER_COMPARE) #we may have extra null pointer checkings in debug build, it's not an issue list(APPEND ORT_WARNING_FLAGS -Wno-tautological-pointer-compare) diff --git a/cmake/adjust_global_compile_flags.cmake b/cmake/adjust_global_compile_flags.cmake index e825bfeaea952..9f00c873715f4 100644 --- a/cmake/adjust_global_compile_flags.cmake +++ b/cmake/adjust_global_compile_flags.cmake @@ -300,6 +300,31 @@ if (MSVC) endif() else() if (NOT APPLE) + #XXX: Sometimes the value of CMAKE_SYSTEM_PROCESSOR is set but it's wrong. For example, if you run an armv7 docker + #image on an aarch64 machine with an aarch64 Ubuntu host OS, in the docker instance cmake may still report + # CMAKE_SYSTEM_PROCESSOR as aarch64 by default. Given compiling this code may need more than 2GB memory, we do not + # support compiling for ARM32 natively(only support cross-compiling), we will ignore this issue for now. + if(NOT CMAKE_SYSTEM_PROCESSOR) + message(WARNING "CMAKE_SYSTEM_PROCESSOR is not set. Please set it in your toolchain cmake file.") + # Try to detect it + if("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang") + execute_process( + COMMAND "${CMAKE_C_COMPILER}" -dumpmachine + OUTPUT_VARIABLE GCC_DUMP_MACHINE_OUT OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_VARIABLE _err + RESULT_VARIABLE _res + ) + if(NOT _res EQUAL 0) + message(SEND_ERROR "Failed to run 'gcc -dumpmachine':\n ${_res}") + endif() + string(REPLACE "-" ";" GCC_DUMP_MACHINE_OUT_LIST "${GCC_DUMP_MACHINE_OUT}") + list(LENGTH GCC_DUMP_MACHINE_OUT_LIST GCC_TRIPLET_LEN) + if(GCC_TRIPLET_LEN EQUAL 4) + list(GET GCC_DUMP_MACHINE_OUT_LIST 0 CMAKE_SYSTEM_PROCESSOR) + message("Setting CMAKE_SYSTEM_PROCESSOR to ${CMAKE_SYSTEM_PROCESSOR}") + endif() + endif() + endif() set(onnxruntime_target_platform ${CMAKE_SYSTEM_PROCESSOR}) endif() if (onnxruntime_BUILD_FOR_NATIVE_MACHINE) From 7011e12c9191483638072736d30e7d46f2919282 Mon Sep 17 00:00:00 2001 From: Changming Sun Date: Mon, 18 Dec 2023 16:45:30 -0800 Subject: [PATCH 4/5] update --- cmake/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index b04e6a5bd8fc8..797fe9ba28ee5 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -639,7 +639,7 @@ else() check_cxx_compiler_flag(-Wunused-variable HAS_UNUSED_VARIABLE) check_cxx_compiler_flag(-Wuseless-cast HAS_USELESS_CAST) check_function_exists(reallocarray HAS_REALLOCARRAY) - if (NOT APPLE AND onnxruntime_target_platform STREQUAL "aarch64") + if (NOT APPLE AND NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten" AND onnxruntime_target_platform STREQUAL "aarch64") check_cxx_compiler_flag(-march=armv8.2-a+bf16 HAS_ARM64_BFLOAT16) if(NOT HAS_ARM64_BFLOAT16) message(FATAL_ERROR "The compiler doesn't support BFLOAT16!!!") From a9c22ebb3dfcc23c548a69228e51e6e61b71702c Mon Sep 17 00:00:00 2001 From: Changming Sun Date: Mon, 18 Dec 2023 17:08:40 -0800 Subject: [PATCH 5/5] revert --- .../android-arm64-v8a-QNN-crosscompile-ci-pipeline.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/tools/ci_build/github/azure-pipelines/android-arm64-v8a-QNN-crosscompile-ci-pipeline.yml b/tools/ci_build/github/azure-pipelines/android-arm64-v8a-QNN-crosscompile-ci-pipeline.yml index 1f7d185fb30dd..e2ca4f64a0ecb 100644 --- a/tools/ci_build/github/azure-pipelines/android-arm64-v8a-QNN-crosscompile-ci-pipeline.yml +++ b/tools/ci_build/github/azure-pipelines/android-arm64-v8a-QNN-crosscompile-ci-pipeline.yml @@ -53,8 +53,6 @@ jobs: - script: sudo apt-get update -y && sudo apt-get install -y coreutils ninja-build displayName: Install coreutils and ninja - - template: "templates/use-android-ndk.yml" - - script: sudo chmod go+rw /dev/kvm displayName: Update permissions to KVM