Re-apply fix for mkl issue for eager mode (#12881)

* reapply fix for mkl issue for eager mode
* add comment, update link libs
This commit is contained in:
pallavides 2022-09-08 12:29:24 -07:00 committed by GitHub
parent ff52d6a6bf
commit 6ebb7b91eb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -154,9 +154,19 @@ if (onnxruntime_ENABLE_EAGER_MODE OR onnxruntime_ENABLE_LAZY_TENSOR)
"${REPO_ROOT}/cmake/external/protobuf/src"
${TORCH_INCLUDE_DIRS})
if (onnxruntime_ENABLE_EAGER_MODE)
# For eager mode, torch build has a mkl dependency from torch's cmake config,
# Linking to torch libraries to avoid this unnecessary mkl dependency.
target_include_directories(onnxruntime_pybind11_state PRIVATE "${TORCH_INSTALL_PREFIX}/include" "${TORCH_INSTALL_PREFIX}/include/torch/csrc/api/include")
find_library(LIBTORCH_LIBRARY torch PATHS "${TORCH_INSTALL_PREFIX}/lib")
find_library(LIBTORCH_CPU_LIBRARY torch_cpu PATHS "${TORCH_INSTALL_PREFIX}/lib")
find_library(LIBC10_LIBRARY c10 PATHS "${TORCH_INSTALL_PREFIX}/lib")
target_link_libraries(onnxruntime_pybind11_state PRIVATE ${LIBTORCH_LIBRARY} ${LIBTORCH_CPU_LIBRARY} ${LIBC10_LIBRARY})
endif()
# Explicitly link torch_python to workaround https://github.com/pytorch/pytorch/issues/38122#issuecomment-694203281
find_library(TORCH_PYTHON_LIBRARY torch_python PATHS "${TORCH_INSTALL_PREFIX}/lib")
target_link_libraries(onnxruntime_pybind11_state PRIVATE ${TORCH_PYTHON_LIBRARY} ${TORCH_LIBRARIES})
target_link_libraries(onnxruntime_pybind11_state PRIVATE ${TORCH_PYTHON_LIBRARY})
if (onnxruntime_ENABLE_EAGER_MODE)
target_link_libraries(onnxruntime_pybind11_state PRIVATE onnxruntime_eager)
endif()