Skip to content

Commit

Permalink
add primitive single matmul bench
Browse files Browse the repository at this point in the history
  • Loading branch information
yifeizh2 committed Aug 16, 2023
1 parent 4cad311 commit fa4b115
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
15 changes: 15 additions & 0 deletions bench_primitive_single_matmul.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
set -e
set -x

if [ -z "${WORKLOAD_BENCH_ROOT_PATH}" ]; then
echo "WORKLOAD_BENCH_ROOT_PATH unset, by default set to ${PWD}"
WORKLOAD_BENCH_ROOT_PATH=${PWD}
fi

# collecting oneDNN primitive performance
_DNNL_GRAPH_DISABLE_COMPILER_BACKEND=1 ONEDNN_GRAPH_VERBOSE=1 bash ${WORKLOAD_BENCH_ROOT_PATH}/run_benchdnn_graph.sh MLP > ${WORKLOAD_BENCH_ROOT_PATH}/primitive.log

# aggregate data
python ${WORKLOAD_BENCH_ROOT_PATH}/scripts/onednn_verbose_parser.py --log_dir ${WORKLOAD_BENCH_ROOT_PATH}
echo "Performance data dumped to ${WORKLOAD_BENCH_ROOT_PATH}/primitive_single_matmul.csv"
46 changes: 46 additions & 0 deletions scripts/onednn_verbose_parser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import argparse
import re
import csv

def main():
args_parser = argparse.ArgumentParser(description='onednn verbose parser')
args_parser.add_argument('--log_dir', help='path to input files')
args = args_parser.parse_args()

# as order of "M, K, N"
mlp_shapes = [[13, 512, 256, 128], [479, 1024, 1024, 512, 256, 1]]
batch_sizes = [32, 64, 128, 256, 512]
matmul_shapes = []
for mlp_shape in mlp_shapes:
for i in range(len(mlp_shape) - 1):
for bs in batch_sizes:
matmul_shapes.append(", ".join([str(bs), str(mlp_shape[i]), str(mlp_shape[i + 1])]))

execution_time_dict = {"f32": {}, "int8": {}}
with open(args.log_dir + "/primitive.log", "r") as file:
lines = file.readlines()
for line in lines:
if line.startswith("onednn_graph_verbose,exec,cpu"):
verbose_seg = line.split(",")
time = float(verbose_seg[-1])
shapes = verbose_seg[7]
result = re.findall(r"([0-9]+)x([0-9]+)", shapes)
dtype = "int8" if "u8" in shapes else "f32"
matmul_shape = ", ".join([str(result[0][0]), str(result[0][1]), str(result[1][1])])
if matmul_shape in execution_time_dict[dtype]:
execution_time_dict[dtype][matmul_shape].append(time)
else:
execution_time_dict[dtype][matmul_shape] = [time]

with open(args.log_dir + "/primitive_single_matmul.csv", "w+") as f:
writer = csv.writer(f)
writer.writerow(["data type", "m, k, n", "time (ms)"])
for dtype in ["f32", "int8"]:
for shape in matmul_shapes:
length = len(execution_time_dict[dtype][shape]) // 10 * 9
avg_time = sum(execution_time_dict[dtype][shape][-length:]) / length
writer.writerow([dtype, shape, avg_time])


if __name__ == "__main__":
main()

0 comments on commit fa4b115

Please sign in to comment.