Skip to content

Commit

Permalink
* Enable OpenMP for ONNX Runtime on Mac once again (issue #917)
Browse files Browse the repository at this point in the history
  • Loading branch information
saudet committed Jan 1, 2021
1 parent 4e30eec commit 8e6f58d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 26 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

* Enable OpenMP for ONNX Runtime on Mac once again ([issue #917](https://github.com/bytedeco/javacpp-presets/issues/917))
* Build OpenCV without OpenBLAS when environment variable `NOOPENBLAS=yes` ([pull #987](https://github.com/bytedeco/javacpp-presets/pull/987))
* Enable OpenCL acceleration for DNNL ([issue #938](https://github.com/bytedeco/javacpp-presets/issues/938))
* Introduce monkey patching when loading presets for CPython to relocate home more reliably
Expand Down
7 changes: 2 additions & 5 deletions onnxruntime/cppbuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ export MAKEFLAGS="-j $MAKEJ"
export PYTHON_BIN_PATH=$(which python3)
export OPENMP_FLAGS="--use_openmp"
case $PLATFORM in
macosx-*)
# disable OpenMP on Mac until it's fixed
export OPENMP_FLAGS=
;;
windows-*)
if [[ -n "${CUDA_PATH:-}" ]]; then
export CUDACXX="$CUDA_PATH/bin/nvcc"
Expand Down Expand Up @@ -89,6 +85,7 @@ sedinplace '/static synchronized void init() throws IOException {/a\
loaded = org.bytedeco.javacpp.Loader.load(org.bytedeco.onnxruntime.presets.onnxruntime.class) != null;\
ortApiHandle = initialiseAPIBase(ORT_API_VERSION_1);\
' java/src/main/java/ai/onnxruntime/OnnxRuntime.java
sedinplace 's/return metadataJava/return (jstring)metadataJava/g' java/src/main/native/ai_onnxruntime_OrtSession.cpp

which ctest3 &> /dev/null && CTEST="ctest3" || CTEST="ctest"
"$PYTHON_BIN_PATH" tools/ci_build/build.py --build_dir ../build --config Release --cmake_path "$CMAKE" --ctest_path "$CTEST" --build_shared_lib --use_dnnl $OPENMP_FLAGS $GPU_FLAGS
Expand All @@ -106,7 +103,7 @@ cp ../build/Release/onnxruntime*.lib ../lib || true
# fix library with the same name for OpenMP as MKL on Mac
case $PLATFORM in
macosx-*)
install_name_tool -change @rpath/libomp.dylib @rpath/libiomp5.dylib ../lib/libonnxruntime.dylib
install_name_tool -change @rpath/libomp.dylib @rpath/libiomp5.dylib ../lib/libonnxruntime.*.dylib
;;
esac

Expand Down
43 changes: 22 additions & 21 deletions onnxruntime/onnxruntime.patch
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
index 853651ac5..b3aa88b17 100644
index 5970505f5..fa6db1085 100644
--- a/cmake/CMakeLists.txt
+++ b/cmake/CMakeLists.txt
@@ -860,8 +860,8 @@ if (WIN32)
@@ -944,8 +944,8 @@ if (WIN32)
else()
add_definitions(-DPLATFORM_POSIX)
# Enable warning and enable space optimization in Linux
Expand All @@ -14,10 +14,10 @@ index 853651ac5..b3aa88b17 100644
if(onnxruntime_DEV_MODE)
string(APPEND CMAKE_CXX_FLAGS " -Werror")
diff --git a/cmake/onnxruntime.cmake b/cmake/onnxruntime.cmake
index 512367174..50878c3eb 100644
index bc07f67bb..447652398 100644
--- a/cmake/onnxruntime.cmake
+++ b/cmake/onnxruntime.cmake
@@ -56,9 +56,9 @@ endif()
@@ -59,9 +59,9 @@ endif()

if(UNIX)
if (APPLE)
Expand All @@ -29,22 +29,11 @@ index 512367174..50878c3eb 100644
endif()
else()
set(ONNXRUNTIME_SO_LINK_FLAG " -DEF:${SYMBOL_FILE}")
diff --git a/java/src/main/native/ai_onnxruntime_OrtSession.c b/java/src/main/native/ai_onnxruntime_OrtSession.c
index 79a2abc2e..a742571e9 100644
--- a/java/src/main/native/ai_onnxruntime_OrtSession.c
+++ b/java/src/main/native/ai_onnxruntime_OrtSession.c
@@ -428,5 +428,5 @@ JNIEXPORT jstring JNICALL Java_ai_onnxruntime_OrtSession_constructMetadata
// Release the metadata
api->ReleaseModelMetadata(metadata);

- return metadataJava;
+ return (jstring)metadataJava;
}
diff --git a/onnxruntime/core/framework/provider_bridge_ort.cc b/onnxruntime/core/framework/provider_bridge_ort.cc
index 75bade5da..7468073ae 100644
index 14ac345d5..6d5a3c2b3 100644
--- a/onnxruntime/core/framework/provider_bridge_ort.cc
+++ b/onnxruntime/core/framework/provider_bridge_ort.cc
@@ -611,12 +611,27 @@ struct ProviderHostImpl : ProviderHost {
@@ -606,12 +606,27 @@ struct ProviderHostImpl : ProviderHost {

} provider_host_;

Expand Down Expand Up @@ -72,7 +61,7 @@ index 75bade5da..7468073ae 100644
auto error = Env::Default().LoadDynamicLibrary(full_path, &handle_);
if (!error.IsOK()) {
LOGS_DEFAULT(ERROR) << error.ErrorMessage();
@@ -660,6 +675,17 @@ struct ProviderLibrary {
@@ -657,6 +672,17 @@ struct ProviderLibrary {
return nullptr;

std::string full_path = Env::Default().GetRuntimePath() + std::string(filename_);
Expand Down Expand Up @@ -797,7 +786,7 @@ index 200fa352a..71f2acb98 100644

template<>
diff --git a/onnxruntime/core/providers/dnnl/subgraph/dnnl_conv_batchnorm.h b/onnxruntime/core/providers/dnnl/subgraph/dnnl_conv_batchnorm.h
index 8173855da..c2bfda9f9 100644
index 7e2654d6f..5bdf410e5 100644
--- a/onnxruntime/core/providers/dnnl/subgraph/dnnl_conv_batchnorm.h
+++ b/onnxruntime/core/providers/dnnl/subgraph/dnnl_conv_batchnorm.h
@@ -2,6 +2,7 @@
Expand All @@ -808,11 +797,23 @@ index 8173855da..c2bfda9f9 100644
#include "dnnl_types.h"
#include "core/providers/dnnl/dnnl_fwd.h"
#include "core/providers/dnnl/dnnl_execution_provider.h"
diff --git a/onnxruntime/core/providers/shared_library/provider_bridge_provider.cc b/onnxruntime/core/providers/shared_library/provider_bridge_provider.cc
index fe1527519..4b1041e1b 100644
--- a/onnxruntime/core/providers/shared_library/provider_bridge_provider.cc
+++ b/onnxruntime/core/providers/shared_library/provider_bridge_provider.cc
@@ -125,6 +125,7 @@ std::string GetEnvironmentVar(const std::string& var_name) {
}

Provider_IExecutionProvider::Provider_IExecutionProvider(const std::string& type) {
+ g_host = Provider_GetHost();
p_ = g_host->Create_IExecutionProvider_Router(this, type).release();
}

diff --git a/tools/ci_build/build.py b/tools/ci_build/build.py
index a2629ff63..0ac396981 100755
index 6168a960b..7dceb225c 100644
--- a/tools/ci_build/build.py
+++ b/tools/ci_build/build.py
@@ -579,7 +579,9 @@ def generate_build_tree(cmake_path, source_dir, build_dir, cuda_home, cudnn_home
@@ -665,7 +665,9 @@ def generate_build_tree(cmake_path, source_dir, build_dir, cuda_home, cudnn_home
"-Donnxruntime_BUILD_WINML_TESTS=" + (
"OFF" if args.skip_winml_tests else "ON"),
"-Donnxruntime_GENERATE_TEST_REPORTS=ON",
Expand Down

0 comments on commit 8e6f58d

Please sign in to comment.