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 <chenta@chenta-orttraining-cpu.bxgbzpva45kedp3rhbsbit4phb.jx.internal.cloudapp.net>
Co-authored-by: Changming Sun <chasun@microsoft.com>
This commit is contained in:
Tang, Cheng 2021-07-28 16:58:13 -07:00 committed by GitHub
parent 2e28cbaa64
commit 00d8f8ce95
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 10 deletions

View file

@ -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

View file

@ -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_PROPERTY:onnx,INTERFACE_INCLUDE_DIRECTORIES>)
target_include_directories(test_execution_provider PRIVATE $<TARGET_PROPERTY:onnxruntime_common,INTERFACE_INCLUDE_DIRECTORIES>)
@ -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()

View file

@ -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'],