[cpp-package] Fix multiple definition issue#5545
[cpp-package] Fix multiple definition issue#5545piiswrong merged 4 commits intoapache:masterfrom sifmelcara:master
Conversation
|
I'm considering changing kvstore to singleton because current implementation will break when two kvstore instances are created. Or if we could make controller a dynamic function pointer which I don't believe is possible in C++. Either way, we don't need controller and updater to be static, right? |
When mxnet hpp headers being included in different translation units, link error occurs because there are multiple (duplicate) definition of functions in different translation units. This commit inlines mxnet cpp functions to follow the one definition rule.
|
In order to let user create multiple I will test the runtime behavior and correctness of these code when I have time. |
|
Oops, it seem I totally misunderstood how is the "name" of KVStore being used. So it may make sense to let KVStore be singleton. |
|
KVStore name is its type actually (like |
|
So, if we implement KVStore as a singleton, user should use KVStore like this Am I right? |
|
Yes |
|
So, the usage of KVStore now looks like this: I have tested the basic Push and Pull functionality, please tell me if everything looks fine, thank you very much. |
|
Static class is different from singleton. For example, sometimes we need to test different kvstore implementations, and it's difficult to do it with static class. And I think static methods do not have external linkage, which is the main issue you want to solve in this pull request. |
If we implement kvstore as a singleton, isn't it also hard to test different implementations? I think I'm missing something here, I would appreciated it if you could give some example.
They do have external linkage, since the
The main issue I want to solve is, currently, when user |
|
For example, to test another implementation, we just need to modify For static methods, I'm not sure if they will create multiple definitions in serverl source files. If they don't, then there is no problem. |
|
I tried to define another class called These codes work fine.
Although these static methods create multiple definitions in several source files, they are |
|
In this part, You need to replace all |
|
If what you are worrying is that developer needs to modify many code to test new KVStore implementation, I think Then we only need to change |
|
@piiswrong This PR LGTM. Can you help merge it? Thank you! |
|
@yajiedesign |
|
@piiswrong because this bug #5598, now it can change to ThreadEngine. |
|
Could you do the fix? Or is it already done? @yajiedesign |
|
@piiswrong ok fixed.and rebuild. |
|
@piiswrong and please update branch |
* [cpp-package] Fix multiple definition issue When mxnet hpp headers being included in different translation units, link error occurs because there are multiple (duplicate) definition of functions in different translation units. This commit inlines mxnet cpp functions to follow the one definition rule. * [cpp-package] Define KVStore as a singleton
Currently, if we include
MxNetCpp.hin several.cppfiles, linker will complains that there are multiple definition of mxnet.cpp functions, because of one definition rule.This commit do several modifications to obey the one definition rule:
inlinekeyword to functions.optimizer.hpp, I delayed the registration of sgd optimizer to the first call of OptimizerRegistry::Find.kvstore.hpp, two callback functions (updaterandcontroller) are nowKVStore's static member functions. Also,extern "C"is removed because I think it is not necessary when the function is callbacked by function pointer (However, I'm not 100% sure on this point, please correct me if I'm wrong).cc @lx75249 , thank you