Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
MIGraphX
Commits
f4947cb3
Commit
f4947cb3
authored
Aug 03, 2023
by
Alan Turner
Browse files
Add single gemm comparison
parent
028280dc
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
136 additions
and
2 deletions
+136
-2
test/onnx/gen_onnx.py
test/onnx/gen_onnx.py
+30
-0
test/onnx/matmul_half.onnx
test/onnx/matmul_half.onnx
+22
-0
test/onnx/matmul_int8.onnx
test/onnx/matmul_int8.onnx
+19
-0
tools/gemm_perf.py
tools/gemm_perf.py
+65
-2
No files found.
test/onnx/gen_onnx.py
View file @
f4947cb3
...
@@ -3924,6 +3924,36 @@ def matmul_bmbm_test():
...
@@ -3924,6 +3924,36 @@ def matmul_bmbm_test():
return
([
node
],
[
m1
,
m2
],
[
y
])
return
([
node
],
[
m1
,
m2
],
[
y
])
@
onnx_test
()
def
matmul_half
():
m1
=
helper
.
make_tensor_value_info
(
'1'
,
TensorProto
.
FLOAT16
,
[
1
,
1
,
1
])
m2
=
helper
.
make_tensor_value_info
(
'2'
,
TensorProto
.
FLOAT16
,
[
1
,
1
,
1
])
y
=
helper
.
make_tensor_value_info
(
'y'
,
TensorProto
.
FLOAT16
,
[
1
,
1
,
1
])
node
=
onnx
.
helper
.
make_node
(
'MatMul'
,
inputs
=
[
'1'
,
'2'
],
outputs
=
[
'y'
],
)
return
([
node
],
[
m1
,
m2
],
[
y
])
@
onnx_test
()
def
matmul_int8
():
m1
=
helper
.
make_tensor_value_info
(
'1'
,
TensorProto
.
INT8
,
[
1
,
1
,
1
])
m2
=
helper
.
make_tensor_value_info
(
'2'
,
TensorProto
.
INT8
,
[
1
,
1
,
1
])
y
=
helper
.
make_tensor_value_info
(
'y'
,
TensorProto
.
INT8
,
[
1
,
1
,
1
])
node
=
onnx
.
helper
.
make_node
(
'MatMul'
,
inputs
=
[
'1'
,
'2'
],
outputs
=
[
'y'
],
)
return
([
node
],
[
m1
,
m2
],
[
y
])
@
onnx_test
()
@
onnx_test
()
def
matmul_bmv_test
():
def
matmul_bmv_test
():
m1
=
helper
.
make_tensor_value_info
(
'1'
,
TensorProto
.
FLOAT
,
[
3
,
6
,
7
])
m1
=
helper
.
make_tensor_value_info
(
'1'
,
TensorProto
.
FLOAT
,
[
3
,
6
,
7
])
...
...
test/onnx/matmul_half.onnx
0 → 100644
View file @
f4947cb3
matmul_half:k
1
2y"MatMulmatmul_halfZ
1
Z
2
b
y
B
\ No newline at end of file
test/onnx/matmul_int8.onnx
0 → 100644
View file @
f4947cb3
matmul_int8:k
1
2y"MatMulmatmul_int8Z
1
Z
2
b
y
B
\ No newline at end of file
tools/gemm_perf.py
View file @
f4947cb3
import
subprocess
,
csv
,
re
,
datetime
#%matplotlib
import
subprocess
,
csv
,
re
,
datetime
,
argparse
,
os
from
subprocess
import
STDOUT
,
check_output
from
mpl_toolkits.mplot3d
import
Axes3D
import
matplotlib.pyplot
as
plt
from
pylab
import
*
import
random
def
parse_args
():
parser
=
argparse
.
ArgumentParser
(
description
=
"GEMM performance tools"
)
parser
.
add_argument
(
'--bert'
,
action
=
'store_true'
,
help
=
'Run GEMM performance comparisons on BERT model'
)
parser
.
add_argument
(
'--gemm'
,
action
=
'store_true'
,
help
=
'Run performance comparison on a range of GEMM problem sizes'
)
args
=
parser
.
parse_args
()
return
args
class
CSVFile
:
class
CSVFile
:
...
@@ -83,7 +101,7 @@ def run_ck_perf(model, batch_size, int8=False, use_large_k=False):
...
@@ -83,7 +101,7 @@ def run_ck_perf(model, batch_size, int8=False, use_large_k=False):
return
[
total_time
]
+
gemm_times
[
1
:]
return
[
total_time
]
+
gemm_times
[
1
:]
if
__name__
==
"__main__"
:
def
run_bert_perf
()
:
device_id
=
get_device_name
()
device_id
=
get_device_name
()
model
=
"/code/bert_base_cased_1_fp16_gpu.onnx"
model
=
"/code/bert_base_cased_1_fp16_gpu.onnx"
cf
=
CSVFile
()
cf
=
CSVFile
()
...
@@ -152,3 +170,48 @@ if __name__ == "__main__":
...
@@ -152,3 +170,48 @@ if __name__ == "__main__":
# rocBLAS Only
# rocBLAS Only
cf
.
write_row
([
"rocBLAS"
]
+
run_perf
(
model
,
batch_size
,
quantize
))
cf
.
write_row
([
"rocBLAS"
]
+
run_perf
(
model
,
batch_size
,
quantize
))
cf
.
write_row
()
cf
.
write_row
()
def
gemm_perf
(
b
,
m
,
n
,
k
,
fp16
):
print
(
f
"
{
b
}
,
{
m
}
,
{
n
}
,
{
k
}
:"
,
end
=
" "
)
model
=
"../test/onnx/matmul_half.onnx"
if
fp16
else
"../test/onnx/matmul_int8.onnx"
#rocBLAS run
cmd
=
f
"MIGRAPHX_ENABLE_CK=0 ../build/bin/driver perf
{
model
}
--input-dim @1
{
b
}
{
m
}
{
k
}
@2
{
b
}
{
k
}
{
n
}
"
out
=
subprocess
.
run
(
cmd
,
capture_output
=
True
,
check
=
True
,
shell
=
True
)
summary
=
re
.
findall
(
"Summary.*"
,
str
(
out
.
stdout
))[
0
].
replace
(
"
\\
n"
,
"
\n
"
)
# print(summary)
total_time
=
re
.
findall
(
"Total time: \d+\.\d*"
,
summary
)[
0
]
total_time
=
total_time
.
replace
(
"Total time: "
,
""
)
rb_time
=
total_time
cmd
=
f
"../build/bin/driver perf
{
model
}
--input-dim @1
{
b
}
{
m
}
{
k
}
@2
{
b
}
{
k
}
{
n
}
--exhaustive-tune"
try
:
out
=
subprocess
.
run
(
cmd
.
split
(),
capture_output
=
True
,
check
=
True
,
timeout
=
300
,
env
=
dict
(
os
.
environ
,
MIGRAPHX_ENABLE_CK
=
"1"
))
except
:
print
(
"-69.0"
)
return
-
69.0
summary
=
re
.
findall
(
"Summary.*"
,
str
(
out
.
stdout
))[
0
].
replace
(
"
\\
n"
,
"
\n
"
)
# print(summary)
total_time
=
re
.
findall
(
"Total time: \d+\.\d*"
,
summary
)[
0
]
total_time
=
total_time
.
replace
(
"Total time: "
,
""
)
ck_time
=
total_time
diff
=
float
(
ck_time
)
-
float
(
rb_time
)
print
(
f
"
{
diff
}
"
)
return
diff
def
run_gemm_perf
():
batches
=
[
1
]
sizes
=
[
64
,
256
,
384
,
768
,
1024
,
2048
,
2304
,
3072
]
results
=
[(
b
,
m
,
n
,
k
,
gemm_perf
(
b
,
m
,
n
,
k
,
False
))
for
b
in
batches
for
m
in
sizes
for
n
in
sizes
for
k
in
sizes
]
print
(
results
)
with
open
(
"gemm_results.txt"
,
"w+"
)
as
f
:
for
r
in
results
:
f
.
write
(
f
"
{
r
[
0
]
}
,
{
r
[
1
]
}
,
{
r
[
2
]
}
,
{
r
[
3
]
}
,
{
r
[
4
]
}
\n
"
)
if
__name__
==
"__main__"
:
args
=
parse_args
()
if
args
.
bert
:
run_bert_perf
()
if
args
.
gemm
:
run_gemm_perf
()
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment