#########################################################
# Copyright (C) 2020 SiMa Technologies, Inc.
#
# This material is SiMa proprietary and confidential.
#
# This material may not be copied or distributed without
# the express prior written permission of SiMa.
#
# All rights reserved.
#########################################################
# Code owner: Joey Chou
#########################################################
import os
import glob
import shutil
import shlex
import subprocess
from afe.core.configs import ModelConfigs, OptimizationConfigs
from afe.core.utils import save_files, dump_configs_to_yaml
[docs]
def simulate_network(model_config: ModelConfigs,
opt_config: OptimizationConfigs) -> None:
"""
Take in a root folder and search for all MLC files. Generate trace file for each
MLC file using below commandline:
mla-isim --trace={trace_file_name} {mlc_file_name}
Save the YAML, if the SIMA_AFE_SAVED_FILES environmental variables is set to `1`.
:param model_config: A ModelConfigs instance containing model related information and status.
:param op_config: A OptimizationConfigs instance containing quantization scheme information.
"""
trace_output_dir = model_config.output_directory + "/trace"
# Remove the trace folder if existed
shutil.rmtree(trace_output_dir, ignore_errors=True)
os.makedirs(trace_output_dir, exist_ok=True)
# Get all file paths
file_list = glob.glob(model_config.mlc_files + "/*.mlc")
# Remove *_chk.mlc files
mlc_file_list = [filename for filename in file_list if "_chk.mlc" not in filename]
# Execute "mla-isim --trace {trace_file_name} {mlc_file_name}
for mlc_file in mlc_file_list:
trace_file_name = mlc_file[mlc_file.rfind('/') + 1:mlc_file.rfind('.')] + ".trace"
trace_file_name = trace_output_dir + "/" + trace_file_name
command = f"mla-isim --trace={trace_file_name} {mlc_file}"
print(f"====== {command}")
command = shlex.split(command)
subprocess.run(command)
# Save the generated trace file directory
model_config.trace_files = trace_output_dir
# Dump files
if save_files():
dump_configs_to_yaml(model_config, opt_config)