Browse Source

fix(imperative): clear custom op build cache

GitOrigin-RevId: cb145fe1ad
tags/v1.8.0
Megvii Engine Team 3 years ago
parent
commit
d24f198cfa
2 changed files with 25 additions and 18 deletions
  1. +5
    -4
      imperative/python/megengine/utils/custom_op_tools.py
  2. +20
    -14
      imperative/python/test/unit/core/test_custom_op.py

+ 5
- 4
imperative/python/megengine/utils/custom_op_tools.py View File

@@ -16,7 +16,7 @@ import sys
import time import time
from typing import List, Optional, Union 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 from ..logger import get_logger




@@ -730,9 +730,10 @@ def build(
""" """


# phase 1: prepare config # 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): def strlist(args, name):
assert isinstance(args, str) or isinstance( assert isinstance(args, str) or isinstance(


+ 20
- 14
imperative/python/test/unit/core/test_custom_op.py View File

@@ -37,7 +37,12 @@ def compare(ref, real):
def build_and_clean(test_func): def build_and_clean(test_func):
def wrapper(): def wrapper():
cur_dir_path = os.path.dirname(os.path.abspath(__file__)) 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( mgb_root_path = os.path.dirname(
os.path.dirname( os.path.dirname(
os.path.dirname(os.path.dirname(os.path.dirname(cur_dir_path))) os.path.dirname(os.path.dirname(os.path.dirname(cur_dir_path)))
@@ -67,20 +72,21 @@ def build_and_clean(test_func):
else: else:
custom_opsrc = [os.path.join(cur_dir_path, "custom_opsrc", "elem_add.cpp")] 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 return wrapper




Loading…
Cancel
Save