提交 d24f198c 编写于 作者: M Megvii Engine Team

fix(imperative): clear custom op build cache

GitOrigin-RevId: cb145fe1ada24cae7e1553bcb1ce8a371895b7c4
上级 bd3c4a05
......@@ -16,7 +16,7 @@ import sys
import time
from typing import List, Optional, Union
from ..core.ops.custom import load
from ..core.ops.custom import get_custom_op_abi_tag, load
from ..logger import get_logger
......@@ -730,9 +730,10 @@ def build(
"""
# phase 1: prepare config
if abi_tag != None:
global MGE_ABI_VER
MGE_ABI_VER = abi_tag
if abi_tag == None:
abi_tag = get_custom_op_abi_tag()
global MGE_ABI_VER
MGE_ABI_VER = abi_tag
def strlist(args, name):
assert isinstance(args, str) or isinstance(
......
......@@ -37,7 +37,12 @@ def compare(ref, real):
def build_and_clean(test_func):
def wrapper():
cur_dir_path = os.path.dirname(os.path.abspath(__file__))
build_path = os.path.join(cur_dir_path, "custom_opsrc", "build")
build_root_dir = custom_op_tools._get_default_build_root()
build_path = os.path.join(build_root_dir, "custom_opsrc", "build")
if os.path.exists(build_path):
shutil.rmtree(build_path)
mgb_root_path = os.path.dirname(
os.path.dirname(
os.path.dirname(os.path.dirname(os.path.dirname(cur_dir_path)))
......@@ -67,20 +72,21 @@ def build_and_clean(test_func):
else:
custom_opsrc = [os.path.join(cur_dir_path, "custom_opsrc", "elem_add.cpp")]
lib_path = custom_op_tools.build_and_load(
"test_op",
custom_opsrc,
extra_include_paths=extra_include_paths,
extra_ldflags=extra_ld_flags,
build_dir=build_path,
verbose=False,
abi_tag=custom.get_custom_op_abi_tag(),
)
test_func()
try:
lib_path = custom_op_tools.build_and_load(
"test_op",
custom_opsrc,
extra_include_paths=extra_include_paths,
extra_ldflags=extra_ld_flags,
build_dir=build_path,
verbose=False,
)
test_func()
custom.unload(lib_path)
custom.unload(lib_path)
if os.path.exists(build_path):
shutil.rmtree(build_path)
finally:
if os.path.exists(build_path):
shutil.rmtree(build_path)
return wrapper
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册