Skip to content

Commit

Permalink
Added mesurement only on middle 2 quartile, default for simd analysis…
Browse files Browse the repository at this point in the history
… with tags (#2527)

Signed-off-by: Alexandre Eichenberger <[email protected]>
  • Loading branch information
AlexandreEichenberger authored Sep 23, 2023
1 parent dd7a375 commit 1757a06
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
23 changes: 17 additions & 6 deletions utils/RunONNXModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,13 @@ def check_non_negative(argname, value):
" E.g. --upper-bound=int64:10,float32:0.2,uint8:9."
" Supported types are bool, uint8, int8, uint16, int16, uint32, int32,"
" uint64, int64, float16, float32, float64")
parser.add_argument('--warmup',
parser.add_argument('-w',
'--warmup',
type=lambda s: check_non_negative("--warmup", s),
default=0,
help="The number of warmup inference runs")
parser.add_argument('--n-iteration',
parser.add_argument('-n',
'--n-iteration',
type=lambda s: check_positive("--n-iteration", s),
default=1,
help="The number of inference runs excluding warmup")
Expand Down Expand Up @@ -495,6 +497,10 @@ def verify_outs(actual_outs, ref_outs):
def warning(msg):
print("Warning:", msg)

def data_without_top_bottom_quartile(data, percent):
data = np.array(sorted(data))
trim = int(percent*data.size/100.0)
return data[trim:-trim]

def main():
if not (args.model or args.load_so):
Expand Down Expand Up @@ -646,14 +652,19 @@ def main():
end = time.perf_counter()
elapsed = end - start
perf_results += [elapsed]
print(" {} iteration: {} seconds".format(ordinal(i+1), elapsed))
print(" {} iteration, {}, seconds".format(ordinal(i+1), elapsed))

# Print statistics info, e.g., min/max/stddev inference time.
if args.n_iteration > 1 :
print(" Statistics (excluding warmup):"
" min {}, max {}, mean {}, stddev {}".format(
print(" Statistics 1 (excluding warmup),"
" min, {:.6e}, max, {:.6e}, mean, {:.6e}, stdev, {:.6e}".format(
np.min(perf_results), np.max(perf_results),
np.mean(perf_results), np.std(perf_results, dtype=np.float64)))
np.mean(perf_results),np.std(perf_results, dtype=np.float64)))
t_perf_results = data_without_top_bottom_quartile(perf_results, 25)
print(" Statistics 2 (no warmup/quart.),"
" min, {:.6e}, max, {:.6e}, mean, {:.6e}, stdev, {:.6e}".format(
np.min(t_perf_results), np.max(t_perf_results),
np.mean(t_perf_results),np.std(t_perf_results, dtype=np.float64)))


# Print the output if required.
Expand Down
12 changes: 10 additions & 2 deletions utils/analyze-simd.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import re
import io
import subprocess
from pathlib import Path

################################################################################
# Usage.
Expand All @@ -25,7 +26,7 @@ def print_usage(msg = ""):
dprint("")
if msg:
dprint("ERROR: " + msg + "\n")
dprint("analyze-simd [-a <arch>] (-c|-m|-o)+ [-n num] [-f pattern] [-dhlp] file")
dprint("analyze-simd [-t <arch>] (-a|-c|-m|-o)+ [-n num] [-f pattern] [-dhlp] file")
dprint(" Utility to analyze and print SIMD code located in functions")
dprint("")
dprint("Pattern:")
Expand Down Expand Up @@ -59,7 +60,7 @@ def print_usage(msg = ""):
print_code = False
print_listing = False
print_details = False
fct_match_str = r'^main_graph$'
fct_match_str = ""
op_dict = {}
aggr_dict = {}
op_name = {}
Expand Down Expand Up @@ -426,13 +427,20 @@ def main(argv):
# All commands after the file name seems to be added here!!!
print_usage("Need an single input file as last option: ", args, ".")
filename = args[0]

name_stub = Path(filename).stem
if not fct_match_str:
fct_match_str = r'^main_graph_' + name_stub + '$'
print("# search default function: main_graph with default tag \""+fct_match_str+"\"")

match_binary = re.match(r'(.*)\.so$', filename)
if match_binary:
asm_filename = match_binary.group(1) + ".s"
cmd = "objdump -S ./" + filename + " > ./" + asm_filename
dprint("# generate asm file with: " + cmd)
ret = subprocess.call(cmd, shell=True)
filename = asm_filename

scan_basic_blocks(filename)
buff = scan_for_simd(filename, pattern, num)
return
Expand Down

0 comments on commit 1757a06

Please sign in to comment.