2026-01-28 06:16:04 +00:00

76 lines
1.8 KiB
Python

import os
import json
import copy
import argparse
import re
def check_file_exist(path):
return path and os.path.exists(path)
def is_file_name_valid(name):
return False if (name and re.match(r'^\.{1,2}/{0,1}', name)) else True
def load_json_file(path):
with open(path) as f:
return json.load(f)
def save_json_file(path, cfg):
with open(path, "w") as fp:
json.dump(cfg, fp, indent=4, sort_keys=True)
fp.write('\n')
def get_case_name(top_dir):
arr = []
for name in sorted(os.listdir(top_dir)):
if os.path.isdir(os.path.join(top_dir, name)):
arr.append(name)
return arr
def get_compiler_bin(opt_dir):
if (os.getenv('COMPILER_BIN_DIR')):
return '{}/compile'.format(os.getenv('COMPILER_BIN_DIR'))
else:
return '{}/../../build/bin/compile'.format(opt_dir)
def get_ip_eval_result(platform):
m = {
"520": "ip_eval_prof.txt",
"720": "ProfileResult.txt",
"530": "ProfileResult.txt",
"730": "ProfileResult.txt",
}
return m.get(platform, "ProfileResult.txt")
def merge_dict(src, b):
a = copy.deepcopy(src)
# merges b into src
for key in b:
if key in a:
if isinstance(a[key], dict) and isinstance(b[key], dict):
a[key] = merge_dict(a[key], b[key])
else:
a[key] = b[key]
else:
a[key] = b[key]
return a
def get_argument_from_wrapper():
parser = argparse.ArgumentParser()
parser.add_argument("platform", help="HW platform <520|720|530|730>")
parser.add_argument("model", help="onnx or bie model path")
parser.add_argument("config", help="compiler base config. config.json")
parser.add_argument('output_dir', help='output directory')
return parser.parse_args()