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

default_obj_ of Device and Graph should be instantiated in one place. #211

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

mattn
Copy link

@mattn mattn commented Dec 11, 2019

Current implementation of primitiv defines default_obj_ in header file device.h/graph.h.

This works almost cases. But when building DLL&EXE on Windows, default_obj_ is instantiated in two places.

`default_obj_` in the DLL is set via set_default but `default_obj_` in the executable always NOT be updated. So the Windows application using primitiv always crash when constructor of Parameter/Input/Node is called. To fix this issue, an instantiation of `default_obj_` should be at a place. This change remove the definitions of `default_obj_`. And `Device::default_obj_` and `Graph::default_obj_` are instantiated via definition of dummy function. These instances are embedded in DLL, and code of application do not need to use any hacks(ex: define PRIMITIV_MAKE_INSTANCE in main.cc) to instantiate them.

I confirmed this works on Windows & Linux. Thanks.

@mattn
Copy link
Author

mattn commented Dec 11, 2019

Ah, this can be more easily to do. Will fix

Signed-off-by: Yasuhiro Matsumoto <mattn.jp@gmail.com>
@mattn
Copy link
Author

mattn commented Dec 11, 2019

I changed this patch to NOT export default_obj_ to executable.

I confirmed this works on Windows & Linux & FreeBSD.

image

image

image

I don't understand why duplicate symbol error not occured.

@odashi
Copy link
Member

odashi commented Dec 13, 2019

@vbkaisetsu Please check if this change is consistent with #47 discussion.

@vbkaisetsu
Copy link
Contributor

Thank you very much.
This bug is same with #47, and it was fixed in #48, but the fix was removed in #99.

I think this pull request is simple and better than the previous change.

odashi
odashi previously approved these changes Dec 17, 2019
Copy link
Contributor

@vbkaisetsu vbkaisetsu left a comment

Choose a reason for hiding this comment

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

LGTM.

Copy link
Contributor

@vbkaisetsu vbkaisetsu left a comment

Choose a reason for hiding this comment

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

mixins_test fails.
I think PRIMITIV_BUILD_LIBRARY should be enabled in mixins_test.

@mattn
Copy link
Author

mattn commented Dec 18, 2019

Thanks. Will look into it in later.

@mattn
Copy link
Author

mattn commented Dec 18, 2019

All tests passed on Windows.

@odashi
Copy link
Member

odashi commented Dec 18, 2019

This seems the change introduces another environment dependent behavior. I guessed we need to use some predefined macros by the Windows compilers (e.g., _WIN32) instead of one we defined.

@mattn
Copy link
Author

mattn commented Dec 18, 2019

Make sense. Do you need some comments?

@odashi
Copy link
Member

odashi commented Dec 18, 2019

It would be fine to put a link to this issue (and some short comments).

examples/mnist/mnist.cc Outdated Show resolved Hide resolved
test/mixins_test.cc Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants