This commit is contained in:
Chranos
2026-02-04 17:39:32 +08:00
parent 8511fe8530
commit 79dfc69789
299 changed files with 55927 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
#!/usr/bin/env python3
import numpy as np
import sys
def check(x: np.ndarray, y: np.ndarray) -> tuple:
error = np.abs(x - y)
diff1 = np.sum(error)/np.sum(np.abs(x))
diff2 = np.sqrt(np.sum(error**2)/np.sum(x**2))
max = np.max(error)
mean = np.mean(error)
return diff1, diff2, max, mean
if "__main__" == __name__:
# read command line arguments
x = np.loadtxt(sys.argv[1])
y = np.loadtxt(sys.argv[2])
# compute mean squared error
diff1, diff2, max, mean = check(x, y)
print("diff1: ", diff1)
print("diff2: ", diff2)
print("max error: ", max)
print("mean error: ", mean)

View File

@@ -0,0 +1,91 @@
import argparse
import logging
import sys
import os
import re
copyright = "/" + "*" * 73 + "\n"
copyright += " * Copyright (C) [2023-2024] by Cambricon, Inc.\n"
copyright += " *\n"
copyright += " * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS\n"
copyright += " * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n"
copyright += " * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\n"
copyright += " * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\n"
copyright += " * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\n"
copyright += " * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\n"
copyright += " * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n"
copyright += " " + "*" * 73 + "/\n"
tmo_path = os.path.abspath(sys.path[0] + "../..")
def arg():
""" Argparser. """
parser = argparse.ArgumentParser('''
A format script for checking cc/h is following llvm format
or not.''')
parser.add_argument(
"--path", help="Location of .h/.cpp file to generate template.")
return parser.parse_args()
class Header(object):
""" Object to gen/check header. """
def __init__(self, path):
""" Init function with args. """
# Check path first.
self.__path = os.path.abspath(path)
self.filename = os.path.split(path)[1]
if path.endswith(".cpp") or path.endswith(".cc"):
self.__has_macro = False
elif path.endswith(".h") or path.endswith(".mluh"):
self.__has_macro = True
else:
logging.info("Skip: format_checker is only for .cpp/.cc/.h")
logging.info("But met " + self.__path)
sys.exit(0)
if not self.__path.startswith(tmo_path):
logging.info("Skip: format_checker is only for genesis file")
sys.exit(0)
# Gen header.
self.__regex = copyright.replace(
"(", "\(").replace(")", "\)").replace("[", "\[").replace(
"]", "\]").replace("-", "\-").replace("*", "\*")
if self.__has_macro:
file_macro = self.__path.replace(tmo_path + "/", "").replace(
"/", "_").replace(".", "_").upper()+"_"
self.__macro = "#ifndef " + file_macro + "\n"
self.__macro += "#define " + file_macro + "\n"
self.__macro += "#endif // " + file_macro + "\n"
def check(self):
""" To check header/macro. """
fo = open(self.__path, "r")
file_string = fo.read()
fo.close()
ptrn_header = re.compile(self.__regex, re.DOTALL)
h_r = ptrn_header.match(file_string)
if not h_r:
logging.error(args.path +
" header mismatch, pattern should be like:")
logging.error("\n" + self.__regex)
sys.exit(-1)
if self.__has_macro:
ptrn_macro = re.compile(".*" + self.__macro.replace("\n", "\n.*"),
re.DOTALL)
m_r = ptrn_macro.match(file_string)
if not m_r:
logging.error(args.path +
" macro mismatch, pattern should be like:")
logging.error("\n" + self.__macro)
sys.exit(-1)
if __name__ == "__main__":
args = arg()
logging.basicConfig(level=logging.INFO)
if not os.path.exists(args.path):
logging.info("Skip: no such file")
sys.exit(0)
h = Header(args.path)
h.check()

View File

@@ -0,0 +1,3 @@
[run]
omit =
/tmp/*

View File

@@ -0,0 +1,11 @@
## PYTEST覆盖率脚本使用方式
```bash
bash run_test.sh
```
- 必须在Torch-MLU-Ops docker容器内运行。
- 脚本原理是使用coverage命令收集py文件运行时的覆盖率数据所以脚本依托于`tests/kernels_pytest/run_test.sh``tests/ops_pytest/run_test.sh`运行。
- 脚本统计的是`tests/kernels_pytest``tests/ops_pytest`下py文件的覆盖率数据。

View File

@@ -0,0 +1,22 @@
KERNELS_PYTEST_DIR="$( cd "$( dirname "$0" )/../../tests/kernels_pytest" && pwd )"
OPS_PYTEST="$( cd "$( dirname "$0" )/../../tests/ops_pytest" && pwd )"
if ! command -v coverage &> /dev/null
then
echo "install coverage..."
pip install coverage
if [ $? -eq 0 ]; then
echo "install coverage success"
else
echo "install coverage failure"
exit 1
fi
fi
${KERNELS_PYTEST_DIR}/build.sh
${KERNELS_PYTEST_DIR}/run_test.sh coverage
${OPS_PYTEST}/run_test.sh coverage
coverage report
coverage html