From 00d8f8ce95e3ea8b7ad45b3e96bf615a8e94f66e Mon Sep 17 00:00:00 2001 From: "Tang, Cheng" Date: Wed, 28 Jul 2021 16:58:13 -0700 Subject: [PATCH] enable shared lib based execution provider test on linux (#8480) * enable shared lib test on linux * fix build break * add onnx dependency * add rpath * skip the test for linux training * set ONNX_ML definition * install training python dependency * update * fix format; add eigen include folder * fix format * skip amd build * enable shared provider on training * fix comments in pr Co-authored-by: Ubuntu Co-authored-by: Changming Sun --- cmake/onnxruntime_python.cmake | 4 ++-- cmake/onnxruntime_unittests.cmake | 6 +++--- .../test/python/onnxruntime_test_python.py | 19 ++++++++++++++----- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/cmake/onnxruntime_python.cmake b/cmake/onnxruntime_python.cmake index 1e8697ab26..0760533fe6 100644 --- a/cmake/onnxruntime_python.cmake +++ b/cmake/onnxruntime_python.cmake @@ -367,10 +367,10 @@ add_custom_command( ) if (NOT onnxruntime_MINIMAL_BUILD AND NOT onnxruntime_EXTENDED_MINIMAL_BUILD - AND NOT onnxruntime_ENABLE_TRAINING AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin|iOS" AND NOT (CMAKE_SYSTEM_NAME STREQUAL "Android") - AND NOT onnxruntime_BUILD_WEBASSEMBLY) + AND NOT onnxruntime_USE_ROCM + AND NOT onnxruntime_BUILD_WEBASSEMBLY) add_custom_command( TARGET onnxruntime_pybind11_state POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy diff --git a/cmake/onnxruntime_unittests.cmake b/cmake/onnxruntime_unittests.cmake index b3c2628279..0502d228f7 100644 --- a/cmake/onnxruntime_unittests.cmake +++ b/cmake/onnxruntime_unittests.cmake @@ -1164,7 +1164,7 @@ if (NOT onnxruntime_ENABLE_TRAINING_TORCH_INTEROP) AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin|iOS" AND NOT (CMAKE_SYSTEM_NAME STREQUAL "Android") AND NOT onnxruntime_BUILD_WEBASSEMBLY - AND MSVC) + AND NOT onnxruntime_USE_ROCM) file(GLOB_RECURSE test_execution_provider_srcs "${REPO_ROOT}/onnxruntime/test/testdata/custom_execution_provider_library/*.h" "${REPO_ROOT}/onnxruntime/test/testdata/custom_execution_provider_library/*.cc" @@ -1173,7 +1173,7 @@ if (NOT onnxruntime_ENABLE_TRAINING_TORCH_INTEROP) ) onnxruntime_add_shared_library_module(test_execution_provider ${test_execution_provider_srcs}) - add_dependencies(test_execution_provider onnxruntime_providers_shared) + add_dependencies(test_execution_provider onnxruntime_providers_shared onnx) target_link_libraries(test_execution_provider PRIVATE onnxruntime_providers_shared) target_include_directories(test_execution_provider PRIVATE $) target_include_directories(test_execution_provider PRIVATE $) @@ -1181,7 +1181,7 @@ if (NOT onnxruntime_ENABLE_TRAINING_TORCH_INTEROP) if(APPLE) set_property(TARGET test_execution_provider APPEND_STRING PROPERTY LINK_FLAGS "-Xlinker -exported_symbols_list ${REPO_ROOT}/onnxruntime/test/testdata/custom_execution_provider_library/exported_symbols.lst") elseif(UNIX) - set_property(TARGET test_execution_provider APPEND_STRING PROPERTY LINK_FLAGS "-Xlinker --version-script=${REPO_ROOT}/onnxruntime/test/testdata/custom_execution_provider_library/version_script.lds -Xlinker --gc-sections") + set_property(TARGET test_execution_provider APPEND_STRING PROPERTY LINK_FLAGS "-Xlinker --version-script=${REPO_ROOT}/onnxruntime/test/testdata/custom_execution_provider_library/version_script.lds -Xlinker --gc-sections -Xlinker -rpath=\\$ORIGIN") elseif(WIN32) set_property(TARGET test_execution_provider APPEND_STRING PROPERTY LINK_FLAGS "-DEF:${REPO_ROOT}/onnxruntime/test/testdata/custom_execution_provider_library/symbols.def") else() diff --git a/onnxruntime/test/python/onnxruntime_test_python.py b/onnxruntime/test/python/onnxruntime_test_python.py index e84b6fd3e2..52e34e08fd 100644 --- a/onnxruntime/test/python/onnxruntime_test_python.py +++ b/onnxruntime/test/python/onnxruntime_test_python.py @@ -1065,20 +1065,29 @@ class TestInferenceSession(unittest.TestCase): check_failure([("a", {1: 2})], [{3: 4}]) def testRegisterCustomEPsLibrary(self): - # exclude for macos and linux - if not sys.platform.startswith("win"): + from onnxruntime.capi import _pybind_state as C + available_eps = C.get_available_providers() + #skip amd gpu build + if 'kRocmExecutionProvider' in available_eps: + return + if sys.platform.startswith("win"): + shared_library = 'test_execution_provider.dll' + + elif sys.platform.startswith("darwin"): + # exclude for macos return - shared_library = 'test_execution_provider.dll' + else: + shared_library = './libtest_execution_provider.so' + if not os.path.exists(shared_library): raise FileNotFoundError("Unable to find '{0}'".format(shared_library)) - + this = os.path.dirname(__file__) custom_op_model = os.path.join(this, "testdata", "custom_execution_provider_library", "test_model.onnx") if not os.path.exists(custom_op_model): raise FileNotFoundError("Unable to find '{0}'".format(custom_op_model)) - from onnxruntime.capi import _pybind_state as C session_options = C.get_default_session_options() sess = C.InferenceSession(session_options, custom_op_model, True, True) sess.initialize_session(['my_ep'],