enable build flag '--use_openmp' on MacOS (#4774)

* enable build flag '--use_openmp' on MacOS

* cmake 3.16.1 to enable find_package(OpenMP) on mac
This commit is contained in:
Yulong Wang 2020-08-13 15:56:42 -07:00 committed by GitHub
parent f12e9de111
commit aa993e95c9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 20 additions and 9 deletions

View file

@ -584,7 +584,7 @@ The Vitis-AI execution provider is only supported on Linux.
.\build.bat --use_openmp
```
##### Linux
##### Linux/Mac OS X
```
./build.sh --use_openmp
@ -866,10 +866,10 @@ pip3 install numpy
# Build the latest cmake
mkdir /code
cd /code
wget https://cmake.org/files/v3.13/cmake-3.13.5.tar.gz;
tar zxf cmake-3.13.5.tar.gz
wget https://cmake.org/files/v3.13/cmake-3.16.1.tar.gz;
tar zxf cmake-3.16.1.tar.gz
cd /code/cmake-3.13.5
cd /code/cmake-3.16.1
./configure --system-curl
make
sudo make install

View file

@ -106,6 +106,7 @@ The following are required for usage of the official published packages.
* For Windows, **OpenMP** support comes as part of VC runtime. It is also available as redist packages:
[vc_redist.x64.exe](https://aka.ms/vs/16/release/vc_redist.x64.exe) and [vc_redist.x86.exe](https://aka.ms/vs/16/release/vc_redist.x86.exe)
* For Linux, the system must have **libgomp.so.1** which can be installed using `apt-get install libgomp1`.
* For Mac OS X, the system must have **libomp.dylib** which can be installed using `brew install libomp`.
* Default GPU (CUDA)
* The default GPU build requires CUDA runtime libraries being installed on the system:

View file

@ -175,6 +175,7 @@ if(onnxruntime_USE_OPENMP)
if (OPENMP_FOUND)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
include_directories(${OpenMP_CXX_INCLUDE_DIR})
# MKLML and NGraph depend on their own OpenMP library that may be different with the compiler's.
# Disable the options to build mklml/NGraph and OpenMP together.
if(onnxruntime_USE_MKLML)
@ -184,6 +185,7 @@ if(onnxruntime_USE_OPENMP)
message(FATAL_ERROR "Please use only one of onnxruntime_USE_NGRAPH, onnxruntime_USE_OPENMP")
endif()
else()
message(WARNING "Flag --use_openmp is specified, but OpenMP is not found in current build environment. Setting it to OFF.")
set(onnxruntime_USE_OPENMP OFF)
endif()
endif()
@ -1112,6 +1114,10 @@ if (CMAKE_SYSTEM_NAME STREQUAL "Android")
list(APPEND onnxruntime_EXTERNAL_LIBRARIES log)
endif()
if (onnxruntime_USE_OPENMP)
list(APPEND onnxruntime_EXTERNAL_LIBRARIES OpenMP::OpenMP_CXX)
endif()
if(WIN32)
list(APPEND onnxruntime_EXTERNAL_LIBRARIES ${SYS_PATH_LIB} Shlwapi)
list(APPEND onnxruntime_EXTERNAL_LIBRARIES debug Dbghelp)

View file

@ -835,6 +835,9 @@ set(onnxruntime_mlas_test_libs onnxruntime_mlas onnxruntime_common)
if(NOT WIN32)
list(APPEND onnxruntime_mlas_test_libs nsync_cpp ${CMAKE_DL_LIBS})
endif()
if (onnxruntime_USE_OPENMP)
list(APPEND onnxruntime_mlas_test_libs OpenMP::OpenMP_CXX)
endif()
list(APPEND onnxruntime_mlas_test_libs Threads::Threads)
target_link_libraries(onnxruntime_mlas_test PRIVATE ${onnxruntime_mlas_test_libs})
if(WIN32)

View file

@ -28,6 +28,7 @@ jobs:
sudo python3 -m pip install -r '$(Build.SourcesDirectory)/tools/ci_build/github/linux/docker/scripts/requirements.txt'
sudo xcode-select --switch /Applications/Xcode_10.app/Contents/Developer
brew install libomp
${{ parameters.BuildCommand }}
displayName: 'Build and Test OnnxRuntime lib for MacOS'
- task: PublishTestResults@2

View file

@ -80,17 +80,17 @@ if [[ $SYS_LONG_BIT = "64" && "$GLIBC_VERSION" -gt "9" ]]; then
tar --strip 1 -xf /tmp/azcopy/azcopy.tar.gz -C /tmp/azcopy
cp /tmp/azcopy/azcopy /usr/bin
echo "Installing cmake"
GetFile https://github.com/Kitware/CMake/releases/download/v3.13.5/cmake-3.13.5-Linux-x86_64.tar.gz /tmp/src/cmake-3.13.5-Linux-x86_64.tar.gz
tar -zxf /tmp/src/cmake-3.13.5-Linux-x86_64.tar.gz --strip=1 -C /usr
GetFile https://github.com/Kitware/CMake/releases/download/v3.16.1/cmake-3.16.1-Linux-x86_64.tar.gz /tmp/src/cmake-3.16.1-Linux-x86_64.tar.gz
tar -zxf /tmp/src/cmake-3.16.1-Linux-x86_64.tar.gz --strip=1 -C /usr
echo "Installing Node.js"
GetFile https://nodejs.org/dist/v12.16.3/node-v12.16.3-linux-x64.tar.xz /tmp/src/node-v12.16.3-linux-x64.tar.xz
tar -xf /tmp/src/node-v12.16.3-linux-x64.tar.xz --strip=1 -C /usr
else
echo "Installing cmake"
GetFile https://github.com/Kitware/CMake/releases/download/v3.13.5/cmake-3.13.5.tar.gz /tmp/src/cmake-3.13.5.tar.gz
tar -xf /tmp/src/cmake-3.13.5.tar.gz -C /tmp/src
GetFile https://github.com/Kitware/CMake/releases/download/v3.16.1/cmake-3.16.1.tar.gz /tmp/src/cmake-3.16.1.tar.gz
tar -xf /tmp/src/cmake-3.16.1.tar.gz -C /tmp/src
pushd .
cd /tmp/src/cmake-3.13.5
cd /tmp/src/cmake-3.16.1
./bootstrap --prefix=/usr --parallel=$(getconf _NPROCESSORS_ONLN) --system-bzip2 --system-curl --system-zlib --system-expat
make -j$(getconf _NPROCESSORS_ONLN)
make install