Browse Source

fix(mge): fix event pool destructor order issue and do full sync at python exit

GitOrigin-RevId: b9fa1f45b1
release-1.2
Megvii Engine Team 4 years ago
parent
commit
6919127fd4
4 changed files with 19 additions and 3 deletions
  1. +4
    -3
      imperative/python/megengine/__init__.py
  2. +1
    -0
      imperative/src/impl/interpreter_impl.cpp
  3. +8
    -0
      imperative/src/impl/physical_tensor.cpp
  4. +6
    -0
      imperative/src/include/megbrain/imperative/physical_tensor.h

+ 4
- 3
imperative/python/megengine/__init__.py View File

@@ -71,7 +71,9 @@ if sys.platform == "win32":


kernel32.SetErrorMode(old_error_mode) kernel32.SetErrorMode(old_error_mode)


from .core._imperative_rt.core2 import release_trace_apply_func, sync, full_sync
from .core._imperative_rt.core2 import full_sync as _full_sync
from .core._imperative_rt.core2 import release_trace_apply_func
from .core._imperative_rt.core2 import sync as _sync
from .core._imperative_rt.utils import _set_fork_exec_path_for_timed_func from .core._imperative_rt.utils import _set_fork_exec_path_for_timed_func
from .device import * from .device import *
from .logger import enable_debug_log, get_logger, set_log_file, set_log_level from .logger import enable_debug_log, get_logger, set_log_file, set_log_level
@@ -89,10 +91,9 @@ _set_fork_exec_path_for_timed_func(
_persistent_cache_impl_ins = persistent_cache.PersistentCacheOnServer() _persistent_cache_impl_ins = persistent_cache.PersistentCacheOnServer()
_persistent_cache_impl_ins.reg() _persistent_cache_impl_ins.reg()


atexit.register(sync)
atexit.register(_full_sync)
atexit.register(release_trace_apply_func) atexit.register(release_trace_apply_func)


del sync
del release_trace_apply_func del release_trace_apply_func
del _set_fork_exec_path_for_timed_func del _set_fork_exec_path_for_timed_func
del _persistent_cache_impl_ins del _persistent_cache_impl_ins


+ 1
- 0
imperative/src/impl/interpreter_impl.cpp View File

@@ -24,6 +24,7 @@ std::unique_ptr<Interpreter::Channel> InterpreterImpl::create_channel() {
} }


Interpreter& Interpreter::inst() { Interpreter& Interpreter::inst() {
Tensor::_static_init();
static InterpreterImpl inst_; static InterpreterImpl inst_;
return inst_; return inst_;
} }


+ 8
- 0
imperative/src/impl/physical_tensor.cpp View File

@@ -56,6 +56,10 @@ protected:
return {}; return {};
} }


AsyncReleaser() {
EventPool::without_timer();
}

public: public:
static AsyncReleaser* inst() { static AsyncReleaser* inst() {
static AsyncReleaser releaser; static AsyncReleaser releaser;
@@ -367,6 +371,10 @@ CompNode::Event* Tensor::get_or_create_event() {
return e; return e;
} }


void Tensor::_static_init() {
EventPool::without_timer();
}

} // namespace imperative } // namespace imperative
} // namespace mgb } // namespace mgb




+ 6
- 0
imperative/src/include/megbrain/imperative/physical_tensor.h View File

@@ -130,6 +130,12 @@ public:


void add_release_callback(CompNode cn); void add_release_callback(CompNode cn);
CompNode::Event* get_or_create_event(); CompNode::Event* get_or_create_event();

// Make sure all static objects required to destruct a tensor has completed
// construction. All static storage duration object that holds tensors must
// call this method before their constructors completes.
static void _static_init();

private: private:


TensorLayout m_layout; TensorLayout m_layout;


Loading…
Cancel
Save