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

onnx_proto symbols visibility clean-up #3371

Closed
wants to merge 7 commits into from

Conversation

mbencer
Copy link

@mbencer mbencer commented Mar 30, 2021

The problem was described in #3319
In short, currently, there is no possibility for import onnx_proto symbols on Windows (when we build onnx_proto as shared lib).

The basic solution was introduced in #3335, but there are many doubts around this topic.
The main problem seems to be specifying onnx_proto visibility both in onnx_pb.h header and in cmake.

My proposition is unification and one place to defining symbols visibility strategy - cmake file.

ONNX_BUILD_SHARED_LIBS flag seems to be unuseful - a way of building is determined by BUILD_SHARED_LIBS so it was removed, but please let me know if there are some scenarios to use it.

Signed-off-by: mbencer <mateusz.bencer@intel.com>
Signed-off-by: mbencer <mateusz.bencer@intel.com>
@mbencer mbencer force-pushed the mbencer/OnnxProtoSymbolsVisibility branch from c2a0383 to 700545e Compare March 30, 2021 08:10
@mbencer mbencer marked this pull request as ready for review March 30, 2021 11:33
@mbencer mbencer requested a review from a team as a code owner March 30, 2021 11:33
@mbencer
Copy link
Author

mbencer commented Mar 31, 2021

@askhade Do you maybe know why ONNX_BUILD_SHARED_LIBS is needed?
I don't see a scenario when it is needed (it seems to be equivalent to BUILD_SHARED_LIBS in this case)

@askhade
Copy link
Contributor

askhade commented May 19, 2021

@mbencer: Some of the cmake options are legacy and I am not sure why they were added. I need to take a thorough look at this PR before I can approve it. Will add my comments by today or tomorrow

@ilyachur
Copy link

@askhade Do you have an update for this PR?

@@ -414,7 +429,8 @@ if(CMAKE_SYSTEM_NAME STREQUAL "AIX")
# So, create a object library
add_library(onnx OBJECT ${ONNX_SRCS})
else()
add_library(onnx ${ONNX_SRCS})
# onnx target doesn't export symbols and should be built as static lib
add_library(onnx STATIC ${ONNX_SRCS})
Copy link
Contributor

Choose a reason for hiding this comment

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

can we keep this default meaning let BUILD_SHARED_LIBS control whether we use STATIC or SHARED

what is the problem with building shared lib when build_shared_lib is set?

Copy link
Author

Choose a reason for hiding this comment

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

The features (classes/members/functions) from onnx library don't use decorators to control visibility.
It is especially required for Windows - __declspec.
So the idea behind it was to block building shared onnx if it is not supported.

set(ONNX_API_DEFINE "-DONNX_API=__attribute__\(\(__visibility__\(\"default\"\)\)\)")
set_target_properties(onnx_proto PROPERTIES CXX_VISIBILITY_PRESET hidden)
set_target_properties(onnx_proto PROPERTIES VISIBILITY_INLINES_HIDDEN 1)
target_compile_definitions(onnx_proto PUBLIC "ONNX_API=__attribute__\(\(__visibility__\(\"default\"\)\)\)")
Copy link
Contributor

Choose a reason for hiding this comment

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

what is the difference between original set vs the PR version target_compile_definitions(onnx_proto ?

is set global ?

Copy link
Author

Choose a reason for hiding this comment

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

Previous version set value on directory level - it will be visible in current directory scope.
In the current version, we match it only with the target which uses it (it will be visible for onnx_proto code and for targets which use onnx_proto).
So from a functional point of view, it's rather not a big difference.

CMakeLists.txt Outdated
# onnx_proto symbols visibility
if(MSVC)
if(ONNX_BUILD_MAIN_LIB)
# ONNX_BUILD_MAIN_LIB can be be set if onnx_proto is static,
Copy link
Contributor

Choose a reason for hiding this comment

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

typo: be be

@askhade
Copy link
Contributor

askhade commented Jul 16, 2021

FYI -
https://github.com/protocolbuffers/protobuf/blob/master/cmake/README.md#dlls-vs-static-linking

If your project is itself a DLL intended for use by third-party software, we recommend that you do NOT expose protocol buffer objects in your library's public interface, and that you statically link protocol buffers into your library.

@gramalingam
Copy link
Contributor

There is a long thread relating to this in a previous PR: please see: #1938 . Among other things, there is a comment towards the end of the thread that defining the preprocessors macros in the cmake breaks the pytorch build.

@gramalingam
Copy link
Contributor

I did not fully understand the context here. Is the goal to produce an ONNX dll that statically links onnx_proto as well as protobuf? Or, is it something else?

@mbencer
Copy link
Author

mbencer commented Jul 19, 2021

I did not fully understand the context here. Is the goal to produce an ONNX dll that statically links onnx_proto as well as protobuf? Or, is it something else?

The goal for us was to build: shared protobuf, shared onnx_proto, and static onnx.
We had two separate libraries which depend on onnx-related staff (protobuf, onnx_proto`) in one application. More details in: #3319

@mbencer mbencer force-pushed the mbencer/OnnxProtoSymbolsVisibility branch 2 times, most recently from 8f6c4cd to b514ae3 Compare July 20, 2021 10:30
…SymbolsVisibility

Signed-off-by: mbencer <mateusz.bencer@intel.com>
@mbencer mbencer force-pushed the mbencer/OnnxProtoSymbolsVisibility branch from b514ae3 to 2781c41 Compare July 21, 2021 12:54
@mbencer mbencer closed this Aug 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants