Skip to content

Commit

Permalink
In a Linux or Android build check if the compiler support bfloat16 an…
Browse files Browse the repository at this point in the history
…d float16 (#18813)

### Description
Restrict clang version because we have an upcoming change that requires
clang version >=16 , which will mainly affect Android build.
  • Loading branch information
snnn authored Jan 9, 2024
1 parent 8f024b7 commit 68c29ec
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 8 deletions.
27 changes: 19 additions & 8 deletions cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -354,13 +354,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.")
Expand Down Expand Up @@ -493,6 +487,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
Expand Down Expand Up @@ -639,7 +641,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 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!!!")
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)
Expand Down
25 changes: 25 additions & 0 deletions cmake/adjust_global_compile_flags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 68c29ec

Please sign in to comment.