49 lines
1.5 KiB
Python
49 lines
1.5 KiB
Python
#!/usr/bin/env python3
|
|
import os
|
|
import subprocess
|
|
import shutil
|
|
|
|
# import common util lib
|
|
import sys
|
|
|
|
opt_dir = os.getcwd()
|
|
sys.path.insert(0, opt_dir)
|
|
from utils import util
|
|
from utils import log
|
|
|
|
if __name__ == "__main__":
|
|
|
|
# step 1: get arguments passing from optimize wrapper
|
|
args = util.get_argument_from_wrapper()
|
|
platform = args.platform
|
|
model = args.model
|
|
merge_config = args.config
|
|
output_dir = args.output_dir
|
|
|
|
# step 2: write optimized module code
|
|
# let compiler output to specific path (best_compiler_result/)
|
|
compiler_output = log.Log.get_best_compiler_result(output_dir)
|
|
os.mkdir(compiler_output)
|
|
os.chdir(compiler_output)
|
|
compiler_bin = os.getenv('COMPILER_BIN')
|
|
command = '{} {} {} {} debug'.format(compiler_bin, platform, model, merge_config)
|
|
cmd_args = command.split()
|
|
o = subprocess.run(cmd_args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
|
|
print('run command: "{}"'.format(command))
|
|
if o.returncode != 0:
|
|
print('...failed to run this command')
|
|
|
|
if o.stdout:
|
|
print(o.stdout.decode())
|
|
|
|
if o.stderr:
|
|
print(o.stderr.decode())
|
|
|
|
# step 3: output best_config.json/best_profile_result.txt to specific path
|
|
best_config = log.Log.get_best_config(output_dir)
|
|
shutil.copyfile(merge_config, best_config)
|
|
best_profile_result = log.Log.get_best_profile_result(output_dir)
|
|
ip_eval_result = util.get_ip_eval_result(platform)
|
|
shutil.copyfile(ip_eval_result, best_profile_result)
|