From 7cb3dfc18a043fe1d9c402cfa75024150742e431 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Tue, 27 Nov 2018 10:44:19 -0800 Subject: [PATCH 1/8] Optimize ReduceMean/ReduceSum when all reduce axises located at the tail of the input tensor's dims by do not make extra copy. And use openmp to parallel the reduce on results. --- .../providers/cpu/reduction/reduction_ops.cc | 61 +++++++++++++++---- 1 file changed, 49 insertions(+), 12 deletions(-) diff --git a/onnxruntime/core/providers/cpu/reduction/reduction_ops.cc b/onnxruntime/core/providers/cpu/reduction/reduction_ops.cc index ae17d9c563..80ee17cde0 100644 --- a/onnxruntime/core/providers/cpu/reduction/reduction_ops.cc +++ b/onnxruntime/core/providers/cpu/reduction/reduction_ops.cc @@ -34,14 +34,20 @@ REGISTER_UNARY_ELEMENTWISE_KERNEL(ReduceSumSquare, 1); REGISTER_UNARY_ELEMENTWISE_KERNEL(ArgMax, 1); REGISTER_UNARY_ELEMENTWISE_KERNEL(ArgMin, 1); +// When all reduce axises located at the tail of the dims, quite general cases, copy could be +// skip to improve performance, if required by check_no_copy = true; +// return value: true means transposedInputData is not created/copied, input tensor data could +// be direct use as row major matrix [block_size, blocks], where blocks is the +// size of each reduce. template -void PrepareForReduce(OpKernelContext* ctx, +bool PrepareForReduce(OpKernelContext* ctx, std::vector& transposedInputData, Tensor** reducedTensor, int64_t& block_size, int64_t& blocks, const std::vector& axes_, - bool keepdims_) { + bool keepdims_, + bool check_no_copy = false) { const Tensor* input_tensor_ptr = ctx->Input(0); ONNXRUNTIME_ENFORCE(input_tensor_ptr != nullptr); const Tensor& input = *input_tensor_ptr; @@ -51,8 +57,6 @@ void PrepareForReduce(OpKernelContext* ctx, ONNXRUNTIME_ENFORCE(axe >= 0 && axe < (int64_t)ndim, "Axis attribute out of range"); } - transposedInputData.resize(input.Shape().Size(), 0); - std::vector axes = axes_; if (axes.empty()) { // This is the default case for non-arg kind reductions. Reduce on all dimensions. @@ -62,6 +66,13 @@ void PrepareForReduce(OpKernelContext* ctx, std::sort(axes.begin(), axes.end()); + // If all reduced axes are located at the tail of the input shape, then copy could be skipped is required + bool need_copy = true; + if (axes.size() <= ndim && axes.front() == static_cast(ndim - axes.size()) + && axes.back() == static_cast(ndim) - 1) { + need_copy = false; + } + vector keep_axis(ndim, true); for (auto i : axes) { keep_axis[i] = false; @@ -96,7 +107,6 @@ void PrepareForReduce(OpKernelContext* ctx, } const T* from_data = input.template Data(); - T* to_data = &transposedInputData[0]; size_t count = input.Shape().Size(); //set to-be-reduced axes to one. squeeze is keepdims_ is false @@ -117,9 +127,15 @@ void PrepareForReduce(OpKernelContext* ctx, block_size = input.Shape().Size() / first_dim; blocks = first_dim; + if (!need_copy && check_no_copy) { + return true; + } + + transposedInputData.resize(input.Shape().Size(), 0); + T* to_data = &transposedInputData[0]; if (num_axes < 2 || n_shared_idxs == num_axes) { memcpy(to_data, from_data, count * sizeof(T)); - return; + return false; } int itr_axes = num_axes - n_shared_idxs; @@ -178,6 +194,7 @@ void PrepareForReduce(OpKernelContext* ctx, } } } + return false; } template @@ -272,12 +289,22 @@ Status ReduceMean::Compute(OpKernelContext* ctx) const { std::vector transposedInputData; int64_t block_size, blocks; Tensor* reduced; - PrepareForReduce(ctx, transposedInputData, &reduced, block_size, blocks, axes_, keepdims_); + bool no_copy = PrepareForReduce(ctx, transposedInputData, &reduced, block_size, blocks, axes_, keepdims_, true); T* output_data = reduced->template MutableData(); - EigenVectorMap out_vec(output_data, block_size); - out_vec = ConstEigenMatrixMap(&transposedInputData[0], block_size, blocks).rowwise().mean(); + if (no_copy) { + const T* input_data = ctx->Input(0)->template Data(); + + #pragma omp parallel for + for (int64_t i = 0; i < block_size; ++i) { + output_data[i] = ConstEigenVectorMap(input_data + (i * blocks), blocks).mean(); + } + } + else { + EigenVectorMap out_vec(output_data, block_size); + out_vec = ConstEigenMatrixMap(&transposedInputData[0], block_size, blocks).rowwise().mean(); + } return Status::OK(); } @@ -317,12 +344,22 @@ Status ReduceSum::Compute(OpKernelContext* ctx) const { std::vector transposedInputData; int64_t block_size, blocks; Tensor* reduced; - PrepareForReduce(ctx, transposedInputData, &reduced, block_size, blocks, axes_, keepdims_); + bool no_copy = PrepareForReduce(ctx, transposedInputData, &reduced, block_size, blocks, axes_, keepdims_, true); T* output_data = reduced->template MutableData(); - EigenVectorMap out_vec(output_data, block_size); - out_vec = ConstEigenMatrixMap(&transposedInputData[0], block_size, blocks).rowwise().sum(); + if (no_copy) { + const T* input_data = ctx->Input(0)->template Data(); + + #pragma omp parallel for + for (int64_t i = 0; i < block_size; ++i) { + output_data[i] = ConstEigenVectorMap(input_data + (i * blocks), blocks).sum(); + } + } + else { + EigenVectorMap out_vec(output_data, block_size); + out_vec = ConstEigenMatrixMap(&transposedInputData[0], block_size, blocks).rowwise().sum(); + } return Status::OK(); } From 0540d8e5f71835e836a188cf6ce0de7dd23b2d81 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Wed, 28 Nov 2018 12:20:53 -0800 Subject: [PATCH 2/8] Better name for read. --- .../providers/cpu/reduction/reduction_ops.cc | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/onnxruntime/core/providers/cpu/reduction/reduction_ops.cc b/onnxruntime/core/providers/cpu/reduction/reduction_ops.cc index 80ee17cde0..a332aa2c33 100644 --- a/onnxruntime/core/providers/cpu/reduction/reduction_ops.cc +++ b/onnxruntime/core/providers/cpu/reduction/reduction_ops.cc @@ -34,8 +34,8 @@ REGISTER_UNARY_ELEMENTWISE_KERNEL(ReduceSumSquare, 1); REGISTER_UNARY_ELEMENTWISE_KERNEL(ArgMax, 1); REGISTER_UNARY_ELEMENTWISE_KERNEL(ArgMin, 1); -// When all reduce axises located at the tail of the dims, quite general cases, copy could be -// skip to improve performance, if required by check_no_copy = true; +// When all reduce axises located at the tail of the dims, quite general cases, transpose and extra +// copy could be skiped to improve performance, if required by check_no_transpose = true; // return value: true means transposedInputData is not created/copied, input tensor data could // be direct use as row major matrix [block_size, blocks], where blocks is the // size of each reduce. @@ -47,7 +47,7 @@ bool PrepareForReduce(OpKernelContext* ctx, int64_t& blocks, const std::vector& axes_, bool keepdims_, - bool check_no_copy = false) { + bool check_no_transpose = false) { const Tensor* input_tensor_ptr = ctx->Input(0); ONNXRUNTIME_ENFORCE(input_tensor_ptr != nullptr); const Tensor& input = *input_tensor_ptr; @@ -127,7 +127,7 @@ bool PrepareForReduce(OpKernelContext* ctx, block_size = input.Shape().Size() / first_dim; blocks = first_dim; - if (!need_copy && check_no_copy) { + if (!need_copy && check_no_transpose) { return true; } @@ -289,11 +289,11 @@ Status ReduceMean::Compute(OpKernelContext* ctx) const { std::vector transposedInputData; int64_t block_size, blocks; Tensor* reduced; - bool no_copy = PrepareForReduce(ctx, transposedInputData, &reduced, block_size, blocks, axes_, keepdims_, true); + bool no_transpose = PrepareForReduce(ctx, transposedInputData, &reduced, block_size, blocks, axes_, keepdims_, true); T* output_data = reduced->template MutableData(); - if (no_copy) { + if (no_transpose) { const T* input_data = ctx->Input(0)->template Data(); #pragma omp parallel for @@ -344,11 +344,11 @@ Status ReduceSum::Compute(OpKernelContext* ctx) const { std::vector transposedInputData; int64_t block_size, blocks; Tensor* reduced; - bool no_copy = PrepareForReduce(ctx, transposedInputData, &reduced, block_size, blocks, axes_, keepdims_, true); + bool no_transpose = PrepareForReduce(ctx, transposedInputData, &reduced, block_size, blocks, axes_, keepdims_, true); T* output_data = reduced->template MutableData(); - if (no_copy) { + if (no_transpose) { const T* input_data = ctx->Input(0)->template Data(); #pragma omp parallel for From cb1781927fae1d2840f4554324d4d6a73e14370d Mon Sep 17 00:00:00 2001 From: Raymond Yang Date: Wed, 28 Nov 2018 17:37:49 -0800 Subject: [PATCH 3/8] Remove mklml in Linux python wheel packagaing (#53) --- tools/ci_build/github/azure-pipelines/azure-pipelines.yml | 2 +- tools/ci_build/github/linux/run_build.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/ci_build/github/azure-pipelines/azure-pipelines.yml b/tools/ci_build/github/azure-pipelines/azure-pipelines.yml index 1ebfce85de..047e0cda91 100644 --- a/tools/ci_build/github/azure-pipelines/azure-pipelines.yml +++ b/tools/ci_build/github/azure-pipelines/azure-pipelines.yml @@ -5,7 +5,7 @@ jobs: pool: Linux-CPU steps: - - script: 'tools/ci_build/github/linux/run_dockerbuild.sh -o ubuntu16.04 -d cpu -r $(Build.BinariesDirectory)' + - script: 'tools/ci_build/github/linux/run_dockerbuild.sh -o ubuntu16.04 -d cpu -r $(Build.BinariesDirectory) -x "--use_mklml"' displayName: 'Command Line Script' env: AZURE_BLOB_KEY: $(onnxruntime-storage-key) diff --git a/tools/ci_build/github/linux/run_build.sh b/tools/ci_build/github/linux/run_build.sh index 083204a6a6..83110363ce 100755 --- a/tools/ci_build/github/linux/run_build.sh +++ b/tools/ci_build/github/linux/run_build.sh @@ -38,6 +38,6 @@ else --config Debug Release --build_shared_lib \ --skip_submodule_sync \ --enable_pybind \ - --parallel --use_mkldnn --use_mklml --build_shared_lib $BUILD_EXTR_PAR + --parallel --use_mkldnn --build_shared_lib $BUILD_EXTR_PAR /home/onnxruntimedev/Release/onnx_test_runner /data/onnx fi From 6179ddb2a14eefb159ceab9bc8f058ac9345f2c8 Mon Sep 17 00:00:00 2001 From: George Wu Date: Wed, 28 Nov 2018 18:14:20 -0800 Subject: [PATCH 4/8] fix for possible incremental build breaks. --- cmake/external/mkldnn.cmake | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cmake/external/mkldnn.cmake b/cmake/external/mkldnn.cmake index 69d20b8f77..8acc389302 100644 --- a/cmake/external/mkldnn.cmake +++ b/cmake/external/mkldnn.cmake @@ -11,6 +11,9 @@ set(MKLDNN_INCLUDE_DIR ${MKLDNN_INSTALL}/include) # patch for mkldnn_sgemm thread safety bug. # it can be removed once a fix is available in a validated mkldnn release version. set(MKLDNN_PATCH_COMMAND1 git apply ${CMAKE_SOURCE_DIR}/patches/mkldnn/mkldnn_sgemm.patch) +set(MKLDNN_PATCH_COMMAND2 git apply ${CMAKE_SOURCE_DIR}/patches/mkldnn/platform.cmake.patch) +# discard prior changes due to patching in mkldnn source to unblock incremental builds. +set(MKLDNN_PATCH_DISCARD_COMMAND cd ${MKLDNN_SOURCE} && git checkout -- .) if(WIN32) set(MKLDNN_SHARED_LIB mkldnn.dll) @@ -20,7 +23,6 @@ if(WIN32) set(MKLML_SHARED_LIB mklml.dll) set(IOMP5MD_SHARED_LIB libiomp5md.dll) endif() - set(MKLDNN_PATCH_COMMAND2 "") else() set(MKLDNN_SHARED_LIB libmkldnn.so.0) if(onnxruntime_USE_MKLML) @@ -28,7 +30,6 @@ else() set(MKLML_SHARED_LIB libmklml_intel.so) set(IOMP5MD_SHARED_LIB libiomp5.so) endif() - set(MKLDNN_PATCH_COMMAND2 git apply ${CMAKE_SOURCE_DIR}/patches/mkldnn/platform.cmake.patch) endif() if(NOT onnxruntime_USE_MKLDNN OR EXISTS ${MKLDNN_SOURCE}/external) @@ -39,7 +40,7 @@ ExternalProject_Add(project_mkldnn PREFIX mkl-dnn GIT_REPOSITORY ${MKLDNN_URL} GIT_TAG ${MKLDNN_TAG} - PATCH_COMMAND ${DOWNLOAD_MKLML} COMMAND ${MKLDNN_PATCH_COMMAND1} COMMAND ${MKLDNN_PATCH_COMMAND2} + PATCH_COMMAND ${DOWNLOAD_MKLML} COMMAND ${MKLDNN_PATCH_DISCARD_COMMAND} COMMAND ${MKLDNN_PATCH_COMMAND1} COMMAND ${MKLDNN_PATCH_COMMAND2} SOURCE_DIR ${MKLDNN_SOURCE} CMAKE_ARGS -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_INSTALL_PREFIX=${MKLDNN_INSTALL} ) From d60507d2e9ea5f55afb72e864195b62a580da464 Mon Sep 17 00:00:00 2001 From: Yulong Wang Date: Wed, 28 Nov 2018 18:29:16 -0800 Subject: [PATCH 5/8] [Mac] fix python binding (#54) --- cmake/onnxruntime_python.cmake | 10 +++++----- setup.py | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cmake/onnxruntime_python.cmake b/cmake/onnxruntime_python.cmake index 8f2f55c69c..2411717001 100644 --- a/cmake/onnxruntime_python.cmake +++ b/cmake/onnxruntime_python.cmake @@ -75,13 +75,13 @@ add_dependencies(onnxruntime_pybind11_state ${onnxruntime_pybind11_state_depende if (MSVC) # if MSVC, pybind11 looks for release version of python lib (pybind11/detail/common.h undefs _DEBUG) target_link_libraries(onnxruntime_pybind11_state ${onnxruntime_pybind11_state_libs} ${onnxruntime_EXTERNAL_LIBRARIES} ${PYTHON_LIBRARY_RELEASE} ${ONNXRUNTIME_SO_LINK_FLAG}) +elseif (APPLE) + set_target_properties(onnxruntime_pybind11_state PROPERTIES LINK_FLAGS "-undefined dynamic_lookup") + target_link_libraries(onnxruntime_pybind11_state ${onnxruntime_pybind11_state_libs} ${onnxruntime_EXTERNAL_LIBRARIES} ${ONNXRUNTIME_SO_LINK_FLAG}) + set_target_properties(onnxruntime_pybind11_state PROPERTIES INSTALL_RPATH "@loader_path") else() target_link_libraries(onnxruntime_pybind11_state ${onnxruntime_pybind11_state_libs} ${onnxruntime_EXTERNAL_LIBRARIES} ${PYTHON_LIBRARY} ${ONNXRUNTIME_SO_LINK_FLAG}) - if (APPLE) - set_target_properties(onnxruntime_pybind11_state PROPERTIES INSTALL_RPATH "@loader_path") - else() - set_target_properties(onnxruntime_pybind11_state PROPERTIES LINK_FLAGS "-Xlinker -rpath=\$ORIGIN") - endif() + set_target_properties(onnxruntime_pybind11_state PROPERTIES LINK_FLAGS "-Xlinker -rpath=\$ORIGIN") endif() set_target_properties(onnxruntime_pybind11_state PROPERTIES PREFIX "") diff --git a/setup.py b/setup.py index ea32fa84bf..2a8954809d 100644 --- a/setup.py +++ b/setup.py @@ -23,7 +23,7 @@ except ImportError: bdist_wheel = None # Additional binaries -if platform.system() == 'Linux': +if platform.system() == 'Linux' or platform.system() == 'Darwin': libs = ['onnxruntime_pybind11_state.so', 'libmkldnn.so.0', 'libmklml_intel.so', 'libiomp5.so'] else: libs = ['onnxruntime_pybind11_state.pyd', 'mkldnn.dll', 'mklml.dll', 'libiomp5md.dll'] From 6371025860dada8dc30671ac148cdb5b179a5698 Mon Sep 17 00:00:00 2001 From: Raymond Yang Date: Wed, 28 Nov 2018 19:22:29 -0800 Subject: [PATCH 6/8] Add flag for mac compliance (#45) * Refine windows CI configs * Add flag for mac compliance --- cmake/CMakeLists.txt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 158356b67f..3d2c7fa4b7 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -110,6 +110,13 @@ else() add_definitions(-DUSE_OPENMP) endif() endif() + +if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + #For Mac compliance + message("Adding flags for Mac builds") + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector-strong") +endif() + find_package(PNG) set(ENABLE_DATE_TESTING OFF CACHE BOOL "" FORCE) set(USE_SYSTEM_TZ_DB ON CACHE BOOL "" FORCE) From 7523e76649b8d6ba4610f7f6532bd73fd04f6b2b Mon Sep 17 00:00:00 2001 From: Faith Xu Date: Wed, 28 Nov 2018 19:43:03 -0800 Subject: [PATCH 7/8] Minor wording changes to design doc (#51) * Update HighLevelDesign.md * Update HighLevelDesign.md * Update HighLevelDesign.md --- docs/HighLevelDesign.md | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/docs/HighLevelDesign.md b/docs/HighLevelDesign.md index 7b9dc27e9a..8e6b955934 100644 --- a/docs/HighLevelDesign.md +++ b/docs/HighLevelDesign.md @@ -1,7 +1,7 @@ # ONNX Runtime High Level Design This document outlines the high level design of -ONNXRuntime - a high performance, cross platform engine. +ONNX Runtime - a high performance, cross platform engine. ## Key objectives * Maximally and automatically leverage the custom accelerators and runtimes @@ -10,8 +10,8 @@ available on disparate platforms. runtimes. We call this abstraction an [execution provider](../include/onnxruntime/core/framework/execution_provider.h). It defines and exposes a set of its capabilities to ONNXRuntime: a set of single or fused nodes it can -execute, its memory allocator and more. Custom accelerators and runtimes are -instances of execution provider. +execute, its memory allocator, and more. Custom accelerators and runtimes are +instances of execution providers. * We don't expect that an execution provider can always run an ONNX model fully on its device. This means that ONNXRuntime must be able to execute a single model in a heterogeneous environment involving multiple execution providers. @@ -35,46 +35,45 @@ provider using the GetCapability() API. ![ONNXRuntime high level system architecture](https://azurecomcdn.azureedge.net/mediahandler/acomblog/media/Default/blog/228d22d3-6e3e-48b1-811c-1d48353f031c.png) -*Note: TensorRT and nGraph support in the works.* +*Note: TensorRT and nGraph support are in progress* ### More about partitioning -ONNXRuntime partitions a model graph based on the available execution providers -into subgraphs, each for a distinct provider respectively. ONNXRuntime provides -a default execution provider that is used for fallback execution for the +ONNXRuntime partitions a model graph into subgraphs based on the available execution providers, one for each distinct provider. ONNXRuntime provides +a default execution provider that is used as the fallback execution for the operators that cannot be pushed onto the more specialized but more efficient -execution providers. Intuitively we probably want to push computation to the -specialized execution providers as much as possible. +execution providers. Intuitively we want to push computation to more +specialized execution providers whenever possible. We use a simple graph partitioning technique. The available execution providers will be considered in a specific order, and each will be assigned the maximal subgraphs (possibly more than one) that it is able to handle. The -ONNXRuntime-provided default execution provider will be the last one to be +ONNXRuntime-provided default execution provider will be the last one considered, and it ensures completeness. More sophisticated optimizations can be considered in the future (or can even be implemented as a composite execution provider). Conceptually, each partition is reduced to a single fused operator. It is -created by invoking the execution provider's Compile() method and wrap it as a +created by invoking the execution provider's Compile() method and wraps it as a custom operator. Currently we support only synchronous mode of execution. An execution provider exposes its memory allocator, which is used to allocate the input tensors for the execution provider. The rewriting and partitioning transform the -initial model graph into a new graph composed with operators assigned to either +initial model graph into a new graph composed of operators assigned to either the default execution provider or other registered execution -providers. ONNXRuntime execution engine is responsible for running this graph. +providers. The ONNXRuntime execution engine is responsible for running this graph. ## Key design decisions -* Multiple threads should be able to inovke the Run() method on the same +* Multiple threads can invoke the Run() method on the same inference session object. See [API doc](C_API.md) for more details. -* To facilitate the above the Compute() function of all kernels is const +* To facilitate this, the Compute() function of all kernels is const implying the kernels are stateless. -* We call implementations of the operators by execution providers as +* Implementations of the operators by execution providers are called kernels. Each execution provider supports a subset of the (ONNX) operators/kernels. -* ONNXRuntime runtime guarantees that all operators are supported by the default +* The ONNXRuntime runtime guarantees that all operators are supported by the default execution provider. * Tensor representation: ONNXRuntime will utilize a standard representation for the tensor runtime values. The execution providers can internally use a -different representation, if they choose to, but it is their responsibility to +different representation if they choose to, but it is their responsibility to convert the values from/to the standard representation at the boundaries of their subgraph. From 846044e28289defe2408aca22bebd1710f582f30 Mon Sep 17 00:00:00 2001 From: Yulong Wang Date: Wed, 28 Nov 2018 20:01:21 -0800 Subject: [PATCH 8/8] [Mac] support mkldnn for macOS (#56) --- cmake/external/mkldnn.cmake | 6 +++++- cmake/onnxruntime_python.cmake | 5 ++++- setup.py | 4 +++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/cmake/external/mkldnn.cmake b/cmake/external/mkldnn.cmake index 69d20b8f77..b8bec9d0d0 100644 --- a/cmake/external/mkldnn.cmake +++ b/cmake/external/mkldnn.cmake @@ -22,7 +22,11 @@ if(WIN32) endif() set(MKLDNN_PATCH_COMMAND2 "") else() - set(MKLDNN_SHARED_LIB libmkldnn.so.0) + if (APPLE) + set(MKLDNN_SHARED_LIB libmkldnn.0.dylib) + else() + set(MKLDNN_SHARED_LIB libmkldnn.so.0) + endif() if(onnxruntime_USE_MKLML) set(DOWNLOAD_MKLML ${MKLDNN_SOURCE}/scripts/prepare_mkl.sh) set(MKLML_SHARED_LIB libmklml_intel.so) diff --git a/cmake/onnxruntime_python.cmake b/cmake/onnxruntime_python.cmake index 2411717001..22db4d45f2 100644 --- a/cmake/onnxruntime_python.cmake +++ b/cmake/onnxruntime_python.cmake @@ -78,7 +78,10 @@ if (MSVC) elseif (APPLE) set_target_properties(onnxruntime_pybind11_state PROPERTIES LINK_FLAGS "-undefined dynamic_lookup") target_link_libraries(onnxruntime_pybind11_state ${onnxruntime_pybind11_state_libs} ${onnxruntime_EXTERNAL_LIBRARIES} ${ONNXRUNTIME_SO_LINK_FLAG}) - set_target_properties(onnxruntime_pybind11_state PROPERTIES INSTALL_RPATH "@loader_path") + set_target_properties(onnxruntime_pybind11_state PROPERTIES + INSTALL_RPATH "@loader_path" + BUILD_WITH_INSTALL_RPATH TRUE + INSTALL_RPATH_USE_LINK_PATH FALSE) else() target_link_libraries(onnxruntime_pybind11_state ${onnxruntime_pybind11_state_libs} ${onnxruntime_EXTERNAL_LIBRARIES} ${PYTHON_LIBRARY} ${ONNXRUNTIME_SO_LINK_FLAG}) set_target_properties(onnxruntime_pybind11_state PROPERTIES LINK_FLAGS "-Xlinker -rpath=\$ORIGIN") diff --git a/setup.py b/setup.py index 2a8954809d..812886f0bd 100644 --- a/setup.py +++ b/setup.py @@ -23,8 +23,10 @@ except ImportError: bdist_wheel = None # Additional binaries -if platform.system() == 'Linux' or platform.system() == 'Darwin': +if platform.system() == 'Linux': libs = ['onnxruntime_pybind11_state.so', 'libmkldnn.so.0', 'libmklml_intel.so', 'libiomp5.so'] +elif platform.system() == "Darwin": + libs = ['onnxruntime_pybind11_state.so', 'libmkldnn.0.dylib'] # TODO add libmklml and libiomp5 later. else: libs = ['onnxruntime_pybind11_state.pyd', 'mkldnn.dll', 'mklml.dll', 'libiomp5md.dll']