-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[tools] supports mlir trunc by compare results automatically
Firstly, use npz_tool.py to get compare.csv as compare results npz_tool.py exp.npz got.npz -a -s compare.csv Then use the following command to make a mlir file with a error graph mlir_truncio.py -c compare.csv -i input.mlir -o output.mlir Change-Id: Ieeeaa5dbdf812de05b506135f9c0051a1c643b17
- Loading branch information
Showing
2 changed files
with
47 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/usr/bin/env python3 | ||
# ============================================================================== | ||
# | ||
# Copyright (C) 2022 Sophgo Technologies Inc. All rights reserved. | ||
# | ||
# TPU-MLIR is licensed under the 2-Clause BSD License except for the | ||
# third-party components. | ||
# | ||
# ============================================================================== | ||
|
||
def mlir_truncio(compare_result_file: str, input_mlir_file: str, output_mlir_file: str): | ||
import pandas as pd | ||
df = pd.read_csv(compare_result_file, sep=', ', header=0, engine='python') | ||
names = df['name'] | ||
passes = df['pass'] | ||
inputs = list(names[passes == True]) | ||
outputs = list(names[passes == False]) | ||
if len(inputs) == len(passes): | ||
print("[WARNING] no error") | ||
return | ||
cmd = f"tpuc-tool {input_mlir_file} --trunc-io='inputs=" | ||
for i in range(len(inputs)): | ||
cmd += inputs[i] | ||
if i != len(inputs) - 1: | ||
cmd += "," | ||
cmd += " outputs=" | ||
for i in range(len(outputs)): | ||
cmd += outputs[i] | ||
if i != len(outputs) - 1: | ||
cmd += "," | ||
cmd += f"' -o {output_mlir_file}" | ||
import os | ||
os.system(cmd) | ||
|
||
|
||
if __name__ == '__main__': | ||
# yapf: disable | ||
import argparse | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("--comp_file", "-c", required=True, help="compare result file") | ||
parser.add_argument("--input_mlir_file", "-i", type=str, required=True, help="input mlir file") | ||
parser.add_argument("--output_mlir_file", "-o", type=str, required=True, help="output mlir file") | ||
# yapf: enable | ||
args = parser.parse_args() | ||
mlir_truncio(args.comp_file, args.input_mlir_file, args.output_mlir_file) | ||
|