44 lines
1.7 KiB
Python
44 lines
1.7 KiB
Python
from .common import *
|
|
from .helper import prepare_result_folder, prepare_tmp_folder
|
|
|
|
import os
|
|
import shutil
|
|
import subprocess
|
|
|
|
def run_compiler_720(input_model_path: str, radix_json_path: str=None) -> str:
|
|
logging.info('Preparing compile environment...')
|
|
output_path = prepare_result_folder('compiler')
|
|
prepare_tmp_folder()
|
|
|
|
# Prepare config
|
|
logging.info('Preparing compile config...')
|
|
if radix_json_path is not None:
|
|
additional_json = '{{\"run_ip_evaluator\": true, \"ip_evaluator_cfg\": \"{}\", \"dynamic_fp\": true, \"dynamic_json_path\": \"{}\"}}'.format(RES_FOLDER + '/ip_config_720.json', radix_json_path)
|
|
else:
|
|
additional_json = '{{\"run_ip_evaluator\": true, \"ip_evaluator_cfg\": \"{}\"}}'.format(RES_FOLDER + '/ip_config_720.json')
|
|
|
|
subprocess.run(['python', LIBS_FOLDER + '/compiler/gen_config.py',
|
|
'-t', '720',
|
|
'-v', 'model_rel',
|
|
'-o', TMP_FOLDER + '/config_compiler.json',
|
|
'-a',
|
|
additional_json])
|
|
|
|
# Run compiler
|
|
logging.info('Running compiler...')
|
|
os.chdir(TMP_FOLDER)
|
|
subprocess.run([LIBS_FOLDER + '/compiler/compile',
|
|
'720',
|
|
input_model_path,
|
|
TMP_FOLDER + '/config_compiler.json',
|
|
'warning',
|
|
'compile.log'], check=True)
|
|
|
|
shutil.copy2(TMP_FOLDER + '/setup.bin', output_path)
|
|
shutil.copy2(TMP_FOLDER + '/weight.bin', output_path)
|
|
shutil.copy2(TMP_FOLDER + '/command.bin', output_path)
|
|
shutil.copy2(TMP_FOLDER + '/ioinfo.json', output_path)
|
|
shutil.copy2(TMP_FOLDER + '/ProfileResult.txt', output_path)
|
|
|
|
return output_path
|