Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onnxruntime shared lib inside python package #21223

Merged
merged 2 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions cmake/onnxruntime_python.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ def finalize_options(self):
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"])
Expand All @@ -310,6 +311,7 @@ def finalize_options(self):
libs.append(providers_cuda_or_rocm)
libs.append(providers_tensorrt_or_migraphx)
libs.append(providers_cann)
libs.append("libonnxruntime.so*")
if nightly_build:
libs.extend(["libonnxruntime_pywrapper.so"])
elif platform.system() == "Darwin":
Expand All @@ -320,10 +322,11 @@ def finalize_options(self):
libs.extend(["libonnxruntime_providers_tensorrt.dylib"])
libs.extend(["libonnxruntime_providers_cuda.dylib"])
libs.extend(["libonnxruntime_providers_vitisai.dylib"])
libs.append("libonnxruntime.dylib*")
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"])
Expand Down Expand Up @@ -376,15 +379,15 @@ def finalize_options(self):
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",
["onnxruntime/capi/onnxruntime_pybind11_state_manylinux1.so"],
),
]
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
Expand Down
5 changes: 4 additions & 1 deletion tools/ci_build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -2591,7 +2591,10 @@ 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change broken our "Windows GPU Reduced Ops CI Pipeline", because previously the "--build_shared_lib" was not specified and C API related tests were not run.
@skottmckay, how should we handle this?

args.build_shared_lib = True

if args.build_nuget and cross_compiling:
Expand Down
Loading