76 lines
2.3 KiB
Python
76 lines
2.3 KiB
Python
#!/usr/bin/env python
|
|
# coding: utf-8
|
|
|
|
import os
|
|
from scipy import spatial
|
|
import numpy as np
|
|
import argparse
|
|
|
|
def main_(args):
|
|
case_folder_path = args.input_folder
|
|
hardware_validate_720(os.path.join(case_folder_path, "dynasty"),
|
|
os.path.join(case_folder_path, "hw_c_sim"))
|
|
|
|
def hardware_validate_720(dynasty_folder_path, hw_c_sim_folder_path):
|
|
assert os.path.exists(dynasty_folder_path) and os.path.exists(hw_c_sim_folder_path), "[Error] validating result does not exists"
|
|
|
|
dynasty_file_list = []
|
|
for file in os.listdir(dynasty_folder_path):
|
|
if file.startswith("layer_output") and file.endswith("fx.txt"):
|
|
dynasty_file_list.append(os.path.join(dynasty_folder_path, file))
|
|
|
|
# for ele in dynasty_file_list:
|
|
# print(ele)
|
|
|
|
hw_c_sim_file_list = []
|
|
for file in os.listdir(hw_c_sim_folder_path):
|
|
if "dma2seq" in file and file.endswith('.seq'):
|
|
hw_c_sim_file_list.append(os.path.join(hw_c_sim_folder_path, file))
|
|
|
|
|
|
assert len(hw_c_sim_file_list) == len(dynasty_file_list), "[Error] number of outputs not match"
|
|
|
|
assert len(dynasty_file_list) != 0, "[Error] no output file"
|
|
|
|
|
|
for dynasty_file in dynasty_file_list:
|
|
dynasty_list = [float(line.strip()) for line in open(dynasty_file).readlines()]
|
|
match = False
|
|
result_list = []
|
|
for hw_c_sim_file in hw_c_sim_file_list:
|
|
hw_c_sim_list = [float(line.strip()) for line in open(hw_c_sim_file).readlines()]
|
|
if len(hw_c_sim_list) == len(dynasty_list):
|
|
result = 0
|
|
if sum(hw_c_sim_list) == sum(dynasty_list) == 0:
|
|
result = 1
|
|
else:
|
|
result = 1 - spatial.distance.cosine(hw_c_sim_list, dynasty_list)
|
|
if result > 0.95:
|
|
match = True
|
|
break
|
|
else:
|
|
result_list.append(result)
|
|
assert match, "[Error] hardware validating fails!"
|
|
print("[info] hardware validating successes!")
|
|
|
|
if __name__ == "__main__":
|
|
argparser = argparse.ArgumentParser(
|
|
description="convert emulator result to box and score"
|
|
)
|
|
|
|
argparser.add_argument(
|
|
'-i',
|
|
'--input_folder',
|
|
help="path of input folder, the case folder"
|
|
)
|
|
|
|
args = argparser.parse_args()
|
|
|
|
main_(args)
|
|
|
|
|
|
|
|
|
|
|
|
|