kneron_model_converter/scripts/utils/run_compiler_520.py
2026-01-28 06:16:04 +00:00

42 lines
1.6 KiB
Python

from .common import *
from .helper import prepare_result_folder, prepare_tmp_folder
import os
import shutil
import subprocess
def run_compiler_520(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 = '{{\"ip_evaluator_cfg\": \"{}\", \"dynamic_fp\": true, \"dynamic_json_path\": \"{}\"}}'.format(RES_FOLDER + '/ip_config_520.json', radix_json_path)
else:
additional_json = '{{\"ip_evaluator_cfg\": \"{}\"}}'.format(RES_FOLDER + '/ip_config_520.json')
subprocess.run(['python', LIBS_FOLDER + '/compiler/gen_config.py',
'-t', '520',
'-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',
'520',
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.csv', output_path)
shutil.copy2(TMP_FOLDER + '/ip_eval_prof.txt', output_path)
return output_path