Browse Source

fix(imperative): sync command queue at exit

GitOrigin-RevId: c0d6aad275
release-1.1
Megvii Engine Team 4 years ago
parent
commit
5cc043f015
3 changed files with 16 additions and 1 deletions
  1. +5
    -0
      imperative/python/megengine/__init__.py
  2. +8
    -0
      imperative/python/test/conftest.py
  3. +3
    -1
      imperative/src/impl/interpreter_impl.cpp

+ 5
- 0
imperative/python/megengine/__init__.py View File

@@ -10,6 +10,7 @@ import os
import sys import sys
import platform import platform
import ctypes import ctypes
import atexit


if sys.platform == "win32": if sys.platform == "win32":
lib_path = os.path.join(os.path.dirname(__file__), "core/lib") lib_path = os.path.join(os.path.dirname(__file__), "core/lib")
@@ -71,6 +72,7 @@ if sys.platform == "win32":
kernel32.SetErrorMode(old_error_mode) kernel32.SetErrorMode(old_error_mode)


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 .core._imperative_rt.imperative import sync
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
from .serialization import load, save from .serialization import load, save
@@ -83,4 +85,7 @@ _set_fork_exec_path_for_timed_func(
os.path.join(os.path.dirname(__file__), "utils", "_timed_func_fork_exec_entry.py"), os.path.join(os.path.dirname(__file__), "utils", "_timed_func_fork_exec_entry.py"),
) )


atexit.register(sync)

del sync
del _set_fork_exec_path_for_timed_func del _set_fork_exec_path_for_timed_func

+ 8
- 0
imperative/python/test/conftest.py View File

@@ -1,4 +1,12 @@
import os import os
import sys import sys


import pytest

from megengine.core._imperative_rt.imperative import sync

sys.path.append(os.path.join(os.path.dirname(__file__), "helpers")) sys.path.append(os.path.join(os.path.dirname(__file__), "helpers"))


def pytest_runtest_teardown():
sync()

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

@@ -175,7 +175,9 @@ void ChannelImpl::free(TensorInfo* ptr) {
m_pool.free(ptr); m_pool.free(ptr);
} }


ChannelImpl::~ChannelImpl() {}
ChannelImpl::~ChannelImpl() {
close();
}


void ChannelImpl::produce_tensor(TensorInfo* dest, TensorPtr ptr) { void ChannelImpl::produce_tensor(TensorInfo* dest, TensorPtr ptr) {
MGB_LOCK_GUARD(m_mutex); MGB_LOCK_GUARD(m_mutex);


Loading…
Cancel
Save