mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-07-23 19:32:23 +00:00
onnxruntime shared lib inside python package (#21223)
This commit is contained in:
parent
7df97f1987
commit
116398c1a4
3 changed files with 36 additions and 5 deletions
|
|
@ -667,6 +667,15 @@ add_custom_command(
|
|||
$<TARGET_FILE_DIR:${build_output_target}>
|
||||
)
|
||||
|
||||
if (onnxruntime_BUILD_SHARED_LIB)
|
||||
add_custom_command(
|
||||
TARGET onnxruntime_pybind11_state POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
$<TARGET_FILE:onnxruntime>
|
||||
$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/capi/
|
||||
)
|
||||
endif()
|
||||
|
||||
if (onnxruntime_USE_OPENVINO)
|
||||
add_custom_command(
|
||||
TARGET onnxruntime_pybind11_state POST_BUILD
|
||||
|
|
|
|||
21
setup.py
21
setup.py
|
|
@ -297,11 +297,13 @@ if platform.system() == "Linux":
|
|||
"libmklml_gnu.so",
|
||||
"libiomp5.so",
|
||||
"mimalloc.so",
|
||||
"libonnxruntime.so*",
|
||||
]
|
||||
dl_libs = ["libonnxruntime_providers_shared.so"]
|
||||
dl_libs.append(providers_cuda_or_rocm)
|
||||
dl_libs.append(providers_tensorrt_or_migraphx)
|
||||
dl_libs.append(providers_cann)
|
||||
dl_libs.append("libonnxruntime.so*")
|
||||
# DNNL, TensorRT & OpenVINO EPs are built as shared libs
|
||||
libs.extend(["libonnxruntime_providers_shared.so"])
|
||||
libs.extend(["libonnxruntime_providers_dnnl.so"])
|
||||
|
|
@ -313,7 +315,12 @@ if platform.system() == "Linux":
|
|||
if nightly_build:
|
||||
libs.extend(["libonnxruntime_pywrapper.so"])
|
||||
elif platform.system() == "Darwin":
|
||||
libs = ["onnxruntime_pybind11_state.so", "libdnnl.2.dylib", "mimalloc.so"] # TODO add libmklml and libiomp5 later.
|
||||
libs = [
|
||||
"onnxruntime_pybind11_state.so",
|
||||
"libdnnl.2.dylib",
|
||||
"mimalloc.so",
|
||||
"libonnxruntime.dylib*",
|
||||
] # TODO add libmklml and libiomp5 later.
|
||||
# DNNL & TensorRT EPs are built as shared libs
|
||||
libs.extend(["libonnxruntime_providers_shared.dylib"])
|
||||
libs.extend(["libonnxruntime_providers_dnnl.dylib"])
|
||||
|
|
@ -323,7 +330,13 @@ elif platform.system() == "Darwin":
|
|||
if nightly_build:
|
||||
libs.extend(["libonnxruntime_pywrapper.dylib"])
|
||||
else:
|
||||
libs = ["onnxruntime_pybind11_state.pyd", "dnnl.dll", "mklml.dll", "libiomp5md.dll"]
|
||||
libs = [
|
||||
"onnxruntime_pybind11_state.pyd",
|
||||
"dnnl.dll",
|
||||
"mklml.dll",
|
||||
"libiomp5md.dll",
|
||||
"onnxruntime.dll",
|
||||
]
|
||||
# DNNL, TensorRT & OpenVINO EPs are built as shared libs
|
||||
libs.extend(["onnxruntime_providers_shared.dll"])
|
||||
libs.extend(["onnxruntime_providers_dnnl.dll"])
|
||||
|
|
@ -376,7 +389,7 @@ if is_manylinux:
|
|||
dl_libs.append("plugins.xml")
|
||||
dl_libs.append("usb-ma2x8x.mvcmd")
|
||||
data = ["capi/libonnxruntime_pywrapper.so"] if nightly_build else []
|
||||
data += [path.join("capi", x) for x in dl_libs if path.isfile(path.join("onnxruntime", "capi", x))]
|
||||
data += [path.join("capi", x) for x in dl_libs if glob(path.join("onnxruntime", "capi", x))]
|
||||
ext_modules = [
|
||||
Extension(
|
||||
"onnxruntime.capi.onnxruntime_pybind11_state",
|
||||
|
|
@ -384,7 +397,7 @@ if is_manylinux:
|
|||
),
|
||||
]
|
||||
else:
|
||||
data = [path.join("capi", x) for x in libs if path.isfile(path.join("onnxruntime", "capi", x))]
|
||||
data = [path.join("capi", x) for x in libs if glob(path.join("onnxruntime", "capi", x))]
|
||||
ext_modules = []
|
||||
|
||||
# Additional examples
|
||||
|
|
|
|||
|
|
@ -2593,7 +2593,16 @@ def main():
|
|||
if args.build_wheel or args.gen_doc or args.use_tvm or args.enable_training:
|
||||
args.enable_pybind = True
|
||||
|
||||
if args.build_csharp or args.build_nuget or args.build_java or args.build_nodejs:
|
||||
if (
|
||||
args.build_csharp
|
||||
or args.build_nuget
|
||||
or args.build_java
|
||||
or args.build_nodejs
|
||||
or (args.enable_pybind and not args.enable_training)
|
||||
):
|
||||
# If pyhon bindings are enabled, we embed the shared lib in the python package.
|
||||
# If training is enabled, we don't embed the shared lib in the python package since training requires
|
||||
# torch interop.
|
||||
args.build_shared_lib = True
|
||||
|
||||
if args.build_nuget and cross_compiling:
|
||||
|
|
|
|||
Loading…
Reference in a new issue