-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
[RUNTIME][REFACTOR] Use new to avoid exit-time de-allocation order #6292
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Ideally all singletons should be created this way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Thanks @tqchen! I will try building this into my code tonight and get back to you tomorrow |
b68f759
to
260fb36
Compare
This still doesnt fix my problem in #5986. But I think its going in the right direction. Now we have a long-lived device object that wont be destroyed. But we cannot access it anymore after the Instead, what if we store the DeviceAPI pointer in the NDArray during creation (or whenever we set/change the context) and then use that pointer inside the deleter? The actual DeviceAPI object on the heap will still be around, so that should work. |
27a810c
to
22b3e7b
Compare
@samskalicky In tihs case the deleter is already long-lived. If the deletion happens during the process of already unloading of vtable or other global objects, then there is little that we can do to solve the problem. Again, in the cases where multiple dlls are involved, the best way is to avoid retaining global objects in python. |
Right, the problem could be that the |
…oblem in DeviceAPI
Since this is definitely something out of our control (shutdown order, varies depending on application usage) and we've decided to rely on the process exiting to free any memory, can we consider clearing the pointers in
And then just make sure that wherever we try and get the |
NOTE that right now the DeviceAPIManager singleton is long-lived now, the value won't be cleared. Even if we choose to instead clear these values, there is no guarantee wrt to the order. So the best way is still to avoid global object in the code(if there are, avoid deleting them, like in this PR) |
Agreed, but thats not always possible given other framework requirements/architecture. Shouldnt we at least be able to guarantee an orderly shutdown for TVM components (runtime/ndarrays/etc) regardless? |
To be clear, I don't think it is the problem of shutdown order(as the objects are now long-lived). It seems that the function is called after the dll get unloaded, so there is little we can do. |
This will not invoke any destructors on exit! What problem is this trying to solve? |
@kparzysz-quic The main problem it tries to resolve is to avoid the problems that can be caused by differnt order destruction of static objects. For example, if a static object takes NDArray, and it get destructed after the DeviceAPI get destructed, then there will be an error. The resources(e.g. in the case of memory etc) will be recycled as OS recycles the process after unloading. |
This will likely cause errors with address sanitizer. We really need a better solution in the long term. |
I'm not against it as a temporary solution. |
I see, not freeing the static global singleton is a common pattern though. Is it possible to somehow provide hints to ASAN to disable the warnings? |
There is a way to turn off the leak sanitizer: define a function Here's the description (from
Btw, for static singleton, the C++ compiler will generate calls to their destructors when |
This is how the leak-suppression function is used in one of the source files in LLVM (in TableGen utility):
|
Sorry, tried to clear the comment window and hit the wrong button. :( |
OK, seems the concensus is to keep this solution for now. Would be great to have more conversations. @kparzysz-quic no worries, glad to see that you now have the committer perm setup correctly :) |
…oblem in DeviceAPI (apache#6292)
…oblem in DeviceAPI (apache#6292)
…oblem in DeviceAPI (apache#6292)
…oblem in DeviceAPI (apache#6292)
…oblem in DeviceAPI (apache#6292)
It is hard to control deallocation order of TVM and other frameworks. So just keep the global state active and rely on OS to recycle the resources