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
c0e26328
Commit
c0e26328
authored
Mar 22, 2023
by
Paul
Browse files
Add precompile flag to build in parallel
parent
6ad936f1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
14 deletions
+31
-14
tools/tune_ck.py
tools/tune_ck.py
+31
-14
No files found.
tools/tune_ck.py
View file @
c0e26328
import
os
,
json
,
subprocess
,
tempfile
,
sys
,
argparse
,
contextlib
import
os
,
json
,
subprocess
,
tempfile
,
sys
,
argparse
,
contextlib
,
multiprocessing
,
multiprocessing
.
dummy
@
contextlib
.
contextmanager
@
contextlib
.
contextmanager
...
@@ -46,21 +46,23 @@ def get_device_time(s):
...
@@ -46,21 +46,23 @@ def get_device_time(s):
fields
=
s
.
split
(
','
)
fields
=
s
.
split
(
','
)
return
convert_to_float
(
fields
[
-
1
].
strip
())
return
convert_to_float
(
fields
[
-
1
].
strip
())
def
run_driver_ck
(
config
,
tuning
,
iterations
):
b
=
{
'settings'
:
{
'iterations'
:
iterations
},
'compile_op'
:
{
'name'
:
'ck_gemm'
,
'check'
:
True
,
'tuning_val'
:
tuning
,
'inputs'
:
config
}
}
return
run_driver
(
b
)
def
benchmark_ck
(
config
,
tuning
):
def
benchmark_ck
(
config
,
tuning
):
try
:
try
:
b
=
{
for
line
in
run_driver_ck
(
config
,
tuning
,
100
):
'settings'
:
{
'iterations'
:
100
},
'compile_op'
:
{
'name'
:
'ck_gemm'
,
'check'
:
True
,
'tuning_val'
:
tuning
,
'inputs'
:
config
}
}
for
line
in
run_driver
(
b
):
dtime
=
get_device_time
(
line
)
dtime
=
get_device_time
(
line
)
print
(
dtime
)
print
(
dtime
)
return
float
(
dtime
)
return
float
(
dtime
)
...
@@ -69,7 +71,6 @@ def benchmark_ck(config, tuning):
...
@@ -69,7 +71,6 @@ def benchmark_ck(config, tuning):
except
:
except
:
return
sys
.
float_info
.
max
return
sys
.
float_info
.
max
def
benchmark
(
config
,
size
):
def
benchmark
(
config
,
size
):
times
=
[
benchmark_ck
(
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
))
...
@@ -84,6 +85,16 @@ def parse_log(f):
...
@@ -84,6 +85,16 @@ def parse_log(f):
config
=
json
.
loads
(
line
)
config
=
json
.
loads
(
line
)
yield
config
yield
config
def
precompile
(
x
):
try
:
list
(
run_driver_ck
(
x
[
0
],
x
[
1
],
0
))
except
:
pass
def
precompile_log
(
f
,
n
):
solutions
=
((
config
,
i
)
for
config
in
parse_log
(
f
)
for
i
in
range
(
n
))
with
multiprocessing
.
Pool
(
24
)
as
p
:
list
(
p
.
imap
(
precompile
,
solutions
))
def
benchmark_log
(
f
,
n
):
def
benchmark_log
(
f
,
n
):
result
=
[]
result
=
[]
...
@@ -106,12 +117,18 @@ def parse_args():
...
@@ -106,12 +117,18 @@ def parse_args():
type
=
str
,
type
=
str
,
metavar
=
'file'
,
metavar
=
'file'
,
help
=
'Output json file to save tunings'
)
help
=
'Output json file to save tunings'
)
parser
.
add_argument
(
'--precompile'
,
'-p'
,
action
=
'store_true'
,
help
=
'Precompile kernels first in parallel'
)
parser
.
add_argument
(
'-n'
,
type
=
int
,
help
=
'Number of instances to tune'
)
parser
.
add_argument
(
'-n'
,
type
=
int
,
help
=
'Number of instances to tune'
)
args
=
parser
.
parse_args
()
args
=
parser
.
parse_args
()
return
args
return
args
def
run
(
args
):
def
run
(
args
):
if
(
args
.
precompile
):
precompile_log
(
args
.
log
,
args
.
n
)
tuned
=
benchmark_log
(
args
.
log
,
args
.
n
)
tuned
=
benchmark_log
(
args
.
log
,
args
.
n
)
json
.
dump
(
tuned
,
open
(
args
.
out
,
'w+'
))
json
.
dump
(
tuned
,
open
(
args
.
out
,
'w+'
))
...
...
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