Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
median,avg,p90,p99
Browse files Browse the repository at this point in the history
unused var remove

add parameter

missing arg

add mean, median, p90,p99 to markdown

markdown
  • Loading branch information
ChaiBapchya committed Aug 21, 2019
1 parent cd397a3 commit d226c38
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
2 changes: 1 addition & 1 deletion benchmark/opperf/utils/benchmark_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def _prepare_op_inputs(inputs, run_backward, dtype, ctx):
return args_list, kwargs_list


def _run_nd_operator_performance_test(op, inputs, run_backward, warmup, runs, kwargs_list, profiler):
def _run_nd_operator_performance_test(op, inputs, run_backward, warmup, runs, args_list, kwargs_list, profiler):
if profiler == 'native':
if run_backward:
benchmark_helper_func = cpp_profile(nd_forward_backward_and_profile)
Expand Down
17 changes: 14 additions & 3 deletions benchmark/opperf/utils/common_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ def _prepare_op_benchmark_result(op, op_bench_result, profiler):
max_mem_usage = "---"
inputs = "---"
avg_time = "---"
p50_time = "---"
p90_time = "---"
p99_time = "---"

for key, value in op_bench_result.items():
if "avg_time_forward" in key:
avg_forward_time = value
Expand All @@ -108,12 +112,19 @@ def _prepare_op_benchmark_result(op, op_bench_result, profiler):
inputs = value
elif "avg_time" in key:
avg_time = value
elif "p50_" in key:
p50_time = value
elif "p90_" in key:
p90_time = value
elif "p99_" in key:
p99_time = value

result = ""
if profiler == "native":
result = "| {} | {} | {} | {} | {} |".format(operator_name,
avg_forward_time, avg_backward_time, max_mem_usage, inputs)
elif profiler == "python":
result = "| {} | {} | {} |".format(operator_name, avg_time, inputs)
result = "| {} | {} | {} | {} | {} | {} |".format(operator_name, avg_time, p50_time, p90_time, p99_time, inputs)
return result


Expand All @@ -132,8 +143,8 @@ def _prepare_markdown(results, runtime_features=None, profiler='native'):
" | Inputs |")
elif profiler == 'python':
results_markdown.append(
"| Operator | Avg Time (ms) | Inputs |")
results_markdown.append("| :---: | :---: | :---: |")
"| Operator | Avg Time (ms) | P50 Time (ms) | P90 Time (ms) | P99 Time (ms) | Inputs |")
results_markdown.append("| :---: | :---: | :---: | :---: | :---: | :---: |")

for op, op_bench_results in sorted(results.items(), key=itemgetter(0)):
for op_bench_result in op_bench_results:
Expand Down
26 changes: 21 additions & 5 deletions benchmark/opperf/utils/profiler_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import time
import functools
import numpy as np

from .common_utils import merge_map_list
from mxnet import profiler
Expand Down Expand Up @@ -228,10 +229,16 @@ def python_profile(func):

@functools.wraps(func)
def python_profile_it(*args, **kwargs):
start_time = time.perf_counter() # 1
res = func(*args, **kwargs)
end_time = time.perf_counter() # 2
run_time = end_time - start_time # 3
runs = args[1]
modified_args = (args[0], 1, args[2])
times = []

for _ in range(runs):
start_time = time.perf_counter() # 1
res = func(*modified_args, **kwargs)
end_time = time.perf_counter() # 2
run_time = (end_time - start_time)*1000 # 3
times.append(run_time)

# NOTE : same as cpp_profile_it
if len(args) > 0:
Expand All @@ -241,6 +248,15 @@ def python_profile_it(*args, **kwargs):
else:
raise ValueError("Unable to identify operator name to extract profiler output!")

profiler_output = {'avg_time_'+str(operator_name): run_time}
avg_run_time = np.mean(times)
p50_run_time = np.percentile(times, 50)
p90_run_time = np.percentile(times, 90)
p99_run_time = np.percentile(times, 99)

profiler_output = {'avg_time_'+str(operator_name): avg_run_time,
'p50_'+str(operator_name): p50_run_time,
'p90_'+str(operator_name): p90_run_time,
'p99_'+str(operator_name): p99_run_time,
}
return res, profiler_output
return python_profile_it

0 comments on commit d226c38

Please sign in to comment.