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
efbe9607
Commit
efbe9607
authored
Oct 10, 2022
by
Paul
Browse files
Refactor tuning script
parent
746291a8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
19 deletions
+32
-19
tools/tune_ck.py
tools/tune_ck.py
+32
-19
No files found.
tools/tune_ck.py
View file @
efbe9607
...
@@ -17,8 +17,28 @@ def tmp_file(dump=None):
...
@@ -17,8 +17,28 @@ def tmp_file(dump=None):
def
pretty_print
(
obj
):
def
pretty_print
(
obj
):
print
(
json
.
dumps
(
obj
,
indent
=
2
))
print
(
json
.
dumps
(
obj
,
indent
=
2
))
def
run_driver
(
b
):
print
(
b
)
with
tmp_file
(
lambda
tf
:
json
.
dump
(
b
,
tf
))
as
tf
:
cp
=
subprocess
.
run
(
'./bin/gpu-driver {}'
.
format
(
tf
),
capture_output
=
True
,
shell
=
True
)
for
line
in
cp
.
stdout
.
decode
().
split
(
"
\n
"
):
s
=
line
.
strip
()
if
not
s
:
continue
if
not
']: '
in
s
:
continue
yield
s
.
split
(
']: '
)[
1
].
strip
()
def
convert_to_float
(
s
):
return
s
[:
-
2
]
def
benchmark_one
(
config
,
tuning
):
def
get_device_time
(
s
):
fields
=
s
.
split
(
','
)
return
convert_to_float
(
fields
[
-
1
].
strip
())
def
benchmark_ck
(
config
,
tuning
):
b
=
{
b
=
{
'settings'
:
{
'settings'
:
{
'iterations'
:
100
'iterations'
:
100
...
@@ -29,37 +49,30 @@ def benchmark_one(config, tuning):
...
@@ -29,37 +49,30 @@ def benchmark_one(config, tuning):
'inputs'
:
config
'inputs'
:
config
}
}
}
}
print
(
b
)
for
line
in
run_driver
(
b
):
with
tmp_file
(
lambda
tf
:
json
.
dump
(
b
,
tf
))
as
tf
:
dtime
=
get_device_time
(
line
)
cp
=
subprocess
.
run
(
'./bin/gpu-driver {}'
.
format
(
tf
),
print
(
dtime
)
capture_output
=
True
,
return
dtime
shell
=
True
)
for
line
in
cp
.
stdout
.
decode
().
split
(
"
\n
"
):
s
=
line
.
strip
()
if
not
s
:
continue
if
not
','
in
s
:
continue
fields
=
s
.
split
(
','
)
dtime
=
fields
[
-
1
].
strip
()
print
(
dtime
)
return
float
(
dtime
[:
-
2
])
return
sys
.
float_info
.
max
return
sys
.
float_info
.
max
def
benchmark
(
config
,
size
):
def
benchmark
(
config
,
size
):
times
=
[
benchmark_
one
(
config
,
i
)
for
i
in
range
(
size
)]
times
=
[
benchmark_
ck
(
config
,
i
)
for
i
in
range
(
size
)]
return
times
.
index
(
min
(
times
))
return
times
.
index
(
min
(
times
))
def
benchmark_log
(
f
):
def
parse_log
(
f
):
result
=
[]
for
line
in
open
(
f
).
readlines
():
for
line
in
open
(
f
).
readlines
():
line
=
line
.
strip
()
line
=
line
.
strip
()
if
not
line
.
startswith
(
'ck_gemm:'
):
if
not
line
.
startswith
(
'ck_gemm:'
):
continue
continue
line
=
line
[
len
(
'ck_gemm:'
):].
strip
()
line
=
line
[
len
(
'ck_gemm:'
):].
strip
()
config
=
json
.
loads
(
line
)
config
=
json
.
loads
(
line
)
yield
config
def
benchmark_log
(
f
):
result
=
[]
for
config
in
parse_log
(
f
):
tuned
=
benchmark
(
config
,
13
)
tuned
=
benchmark
(
config
,
13
)
result
.
append
([
config
,
tuned
])
result
.
append
([
config
,
tuned
])
return
result
return
result
...
...
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