"""
本脚本有 2 种执行模式:
1. CI批跑时, 由 cmake/scripts/golden_ctrl.py 调用, 为避免日志过多, 此时 logging 级别为 logging.INFO;
2. 单独调试时, 本脚本单独被调用, 此时 logging 级别为 logging.DEBUG;
"""
import sys
import logging
from pathlib import Path
from typing import List
import numpy as np
if __name__ == "__main__":
""" 单独调试时配置 """
logging.basicConfig(format='%(asctime)s - %(filename)s:%(lineno)d - %(levelname)s: %(message)s',
level=logging.DEBUG)
g_src_root: Path = Path(Path(__file__).parent, "../../../../../").resolve()
logging.debug("SrcRoot: %s", g_src_root)
g_ctrl_path: Path = Path(g_src_root, "cmake/scripts")
if str(g_ctrl_path) not in sys.path:
sys.path.append(str(g_ctrl_path))
from golden_register import GoldenRegister
else:
from golden_register import GoldenRegister
@GoldenRegister.reg_golden_func(
case_names=[
"OnBoardTestAstApi.test_add_sub_all2all_torchapi_multi_function",
]
)
def add_sub_main(case_name: str, output: Path) -> bool:
row = 64
col = 64
shape_i = [row, col]
shape_o = [shape_i[0], shape_i[1]]
dtype = np.float32
x = np.random.uniform(-1, 1, shape_i).astype(dtype)
x.tofile(Path(output, 'x.bin'))
y = np.random.uniform(-1, 1, shape_i).astype(dtype)
y.tofile(Path(output, 'y.bin'))
a = x + y
a.tofile(Path(output, 'res.bin'))
sub = x - y
sub.tofile(Path(output, 'res_sub.bin'))
logging.debug("gen add sub golden success!!!")
logging.debug("row is %s, col is %s", row, col)
return True
def main() -> bool:
"""
单独调试 入口函数
"""
case_name_list: List[str] = [
"ExpandOnBoardTest.test_expand_32_1_to_32_32",
]
ret: bool = True
for cs in case_name_list:
output: Path = Path(g_src_root, "build/output/bin/golden", cs).resolve()
output.mkdir(parents=True, exist_ok=True)
ret = add_sub_main(case_name=cs, output=output)
return ret
if __name__ == "__main__":
exit(0 if main() else 1)