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
8d32c6b8
Commit
8d32c6b8
authored
Oct 17, 2023
by
Paul
Browse files
Merge branch 'develop' into blas_tuning
parents
23cb7917
f25606f9
Changes
386
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
120 additions
and
9 deletions
+120
-9
tools/download_models.sh
tools/download_models.sh
+5
-0
tools/generate.py
tools/generate.py
+88
-0
tools/install_prereqs.sh
tools/install_prereqs.sh
+4
-3
tools/license_stamper.py
tools/license_stamper.py
+2
-2
tools/te.py
tools/te.py
+6
-3
tools/test_runner.py
tools/test_runner.py
+15
-1
No files found.
tools/download_models.sh
View file @
8d32c6b8
...
@@ -49,3 +49,8 @@ do
...
@@ -49,3 +49,8 @@ do
curl https://download.onnxruntime.ai/onnx/models/
$name
.tar.gz
--output
$tmp_dir
/
$name
.tar.gz
curl https://download.onnxruntime.ai/onnx/models/
$name
.tar.gz
--output
$tmp_dir
/
$name
.tar.gz
tar
-xzvf
$tmp_dir
/
$name
.tar.gz
--directory
$model_dir
&&
rm
$tmp_dir
/
$name
.tar.gz
tar
-xzvf
$tmp_dir
/
$name
.tar.gz
--directory
$model_dir
&&
rm
$tmp_dir
/
$name
.tar.gz
done
done
# CI jobs can run as a different user then the docker image builder.
# Allow read/write access to the models
chmod
777
$model_dir
tools/generate.py
0 → 100644
View file @
8d32c6b8
#####################################################################################
# The MIT License (MIT)
#
# Copyright (c) 2015-2023 Advanced Micro Devices, Inc. All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#####################################################################################
import
api
,
argparse
,
os
,
runpy
,
subprocess
,
sys
,
te
from
pathlib
import
Path
clang_format_path
=
Path
(
'clang-format.exe'
if
os
.
name
==
'nt'
else
'/opt/rocm/llvm/bin/clang-format'
)
work_dir
=
Path
().
cwd
()
src_dir
=
(
work_dir
/
'../src'
).
absolute
()
migraphx_py_path
=
src_dir
/
'api/migraphx.py'
def
clang_format
(
buffer
,
**
kwargs
):
return
subprocess
.
run
(
f
'
{
clang_format_path
}
-style=file'
,
capture_output
=
True
,
shell
=
True
,
check
=
True
,
input
=
buffer
.
encode
(
'utf-8'
),
cwd
=
work_dir
,
**
kwargs
).
stdout
.
decode
(
'utf-8'
)
def
api_generate
(
input_path
:
Path
,
output_path
:
Path
):
with
open
(
output_path
,
'w'
)
as
f
:
f
.
write
(
clang_format
(
api
.
run
(
input_path
)))
def
te_generate
(
input_path
:
Path
,
output_path
:
Path
):
with
open
(
output_path
,
'w'
)
as
f
:
f
.
write
(
clang_format
(
te
.
run
(
input_path
)))
def
main
():
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
'-f'
,
'--clang-format'
,
type
=
Path
)
args
=
parser
.
parse_args
()
global
clang_format_path
if
args
.
clang_format
:
clang_format_path
=
args
.
clang_format
if
not
clang_format_path
.
is_file
():
print
(
f
"
{
clang_format_path
}
: invalid path or not installed"
,
file
=
sys
.
stderr
)
return
try
:
files
=
Path
(
'include'
).
absolute
().
iterdir
()
for
f
in
[
f
for
f
in
files
if
f
.
is_file
()]:
te_generate
(
f
,
src_dir
/
f
'include/migraphx/
{
f
.
name
}
'
)
runpy
.
run_path
(
str
(
migraphx_py_path
))
api_generate
(
work_dir
/
'api/migraphx.h'
,
src_dir
/
'api/include/migraphx/migraphx.h'
)
print
(
'Finished generating header migraphx.h'
)
api_generate
(
work_dir
/
'api/api.cpp'
,
src_dir
/
'api/api.cpp'
)
print
(
'Finished generating source api.cpp'
)
except
subprocess
.
CalledProcessError
as
ex
:
if
ex
.
stdout
:
print
(
ex
.
stdout
.
decode
(
'utf-8'
))
if
ex
.
stderr
:
print
(
ex
.
stdout
.
decode
(
'utf-8'
))
print
(
f
"Command '
{
ex
.
cmd
}
' returned
{
ex
.
returncode
}
"
)
raise
if
__name__
==
"__main__"
:
main
()
tools/install_prereqs.sh
View file @
8d32c6b8
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
#####################################################################################
#####################################################################################
# The MIT License (MIT)
# The MIT License (MIT)
#
#
# Copyright (c) 2015-202
2
Advanced Micro Devices, Inc. All rights reserved.
# Copyright (c) 2015-202
3
Advanced Micro Devices, Inc. All rights reserved.
#
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# of this software and associated documentation files (the "Software"), to deal
...
@@ -51,6 +51,7 @@ else
...
@@ -51,6 +51,7 @@ else
openmp-extras
\
openmp-extras
\
python3-dev
\
python3-dev
\
python3-pip
\
python3-pip
\
python3-venv
\
rocblas-dev
\
rocblas-dev
\
rocm-cmake
rocm-cmake
fi
fi
...
@@ -80,8 +81,8 @@ rbuild prepare -d $PREFIX -s develop
...
@@ -80,8 +81,8 @@ rbuild prepare -d $PREFIX -s develop
if
[[
(
"
${
ID
}
"
!=
"sles"
)
]]
;
then
if
[[
(
"
${
ID
}
"
!=
"sles"
)
]]
;
then
export
CMAKE_ARGS
=
"-DONNX_USE_PROTOBUF_SHARED_LIBS=ON"
export
CMAKE_ARGS
=
"-DONNX_USE_PROTOBUF_SHARED_LIBS=ON"
pip3
install
onnx
==
1.1
0.2
numpy
==
1.21.6
typing
==
3.7.4
pytest
==
6.0.1
packaging
==
23.0
pip3
install
onnx
==
1.1
4.1
numpy
==
1.21.6
typing
==
3.7.4
pytest
==
6.0.1
packaging
==
23.0
# pin version of protobuf in Python for onnx runtime unit tests between dist versions
# pin version of protobuf in Python for onnx runtime unit tests between dist versions
pip3
install
protobuf
==
3.20.
0
pip3
install
protobuf
==
3.20.
2
fi
fi
tools/license_stamper.py
View file @
8d32c6b8
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
#####################################################################################
#####################################################################################
# The MIT License (MIT)
# The MIT License (MIT)
#
#
# Copyright (c) 2015-202
2
Advanced Micro Devices, Inc. All rights reserved.
# Copyright (c) 2015-202
3
Advanced Micro Devices, Inc. All rights reserved.
#
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# of this software and associated documentation files (the "Software"), to deal
...
@@ -38,7 +38,7 @@ def getipynb_markdownBlockAsList():
...
@@ -38,7 +38,7 @@ def getipynb_markdownBlockAsList():
'
\t\t
"cell_type": "code",
\n
'
,
'
\t\t
"execution_count": null,
\n
'
,
'
\t\t
"cell_type": "code",
\n
'
,
'
\t\t
"execution_count": null,
\n
'
,
'
\t\t
"metadata": {},
\n
'
,
'
\t\t
"outputs": [],
\n
'
,
'
\t\t
"source": [
\n
'
,
'
\t\t
"metadata": {},
\n
'
,
'
\t\t
"outputs": [],
\n
'
,
'
\t\t
"source": [
\n
'
,
'
\t\t\t\"
# The MIT License (MIT)
\\
n
\"
,
\n
'
,
'
\t\t\t\"
#
\\
n
\"
,
\n
'
,
'
\t\t\t\"
# The MIT License (MIT)
\\
n
\"
,
\n
'
,
'
\t\t\t\"
#
\\
n
\"
,
\n
'
,
'
\t\t\t\"
# Copyright (c) 2015-202
2
Advanced Micro Devices, Inc. All rights reserved.
\\
n
\"
,
\n
'
,
'
\t\t\t\"
# Copyright (c) 2015-202
3
Advanced Micro Devices, Inc. All rights reserved.
\\
n
\"
,
\n
'
,
'
\t\t\t\"
#
\\
n
\"
,
\n
'
,
'
\t\t\t\"
#
\\
n
\"
,
\n
'
,
'
\t\t\t\"
# Permission is hereby granted, free of charge, to any person obtaining a copy
\\
n
\"
,
\n
'
,
'
\t\t\t\"
# Permission is hereby granted, free of charge, to any person obtaining a copy
\\
n
\"
,
\n
'
,
'
\t\t\t\"
# of this software and associated documentation files (the
\'
Software
\'
), to deal
\\
n
\"
,
\n
'
,
'
\t\t\t\"
# of this software and associated documentation files (the
\'
Software
\'
), to deal
\\
n
\"
,
\n
'
,
...
...
tools/te.py
View file @
8d32c6b8
...
@@ -431,6 +431,9 @@ def template_eval(template, **kwargs):
...
@@ -431,6 +431,9 @@ def template_eval(template, **kwargs):
return
template
return
template
f
=
open
(
sys
.
argv
[
1
]).
read
()
def
run
(
p
):
r
=
template_eval
(
f
)
return
template_eval
(
open
(
p
).
read
())
sys
.
stdout
.
write
(
r
)
if
__name__
==
'__main__'
:
sys
.
stdout
.
write
(
run
(
sys
.
argv
[
1
]))
tools/test_runner.py
View file @
8d32c6b8
...
@@ -39,6 +39,15 @@ def parse_args():
...
@@ -39,6 +39,15 @@ def parse_args():
type
=
str
,
type
=
str
,
default
=
'gpu'
,
default
=
'gpu'
,
help
=
'Specify where the tests execute (ref, gpu)'
)
help
=
'Specify where the tests execute (ref, gpu)'
)
parser
.
add_argument
(
'--fp16'
,
action
=
'store_true'
,
help
=
'Quantize to fp16'
)
parser
.
add_argument
(
'--atol'
,
type
=
float
,
default
=
1e-3
,
help
=
'The absolute tolerance parameter'
)
parser
.
add_argument
(
'--rtol'
,
type
=
float
,
default
=
1e-3
,
help
=
'The relative tolerance parameter'
)
args
=
parser
.
parse_args
()
args
=
parser
.
parse_args
()
return
args
return
args
...
@@ -257,6 +266,8 @@ def main():
...
@@ -257,6 +266,8 @@ def main():
# read and compile model
# read and compile model
model
=
migraphx
.
parse_onnx
(
model_path_name
,
map_input_dims
=
param_shapes
)
model
=
migraphx
.
parse_onnx
(
model_path_name
,
map_input_dims
=
param_shapes
)
if
args
.
fp16
:
migraphx
.
quantize_fp16
(
model
)
model
.
compile
(
migraphx
.
get_target
(
target
))
model
.
compile
(
migraphx
.
get_target
(
target
))
# get test cases
# get test cases
...
@@ -279,7 +290,10 @@ def main():
...
@@ -279,7 +290,10 @@ def main():
output_data
=
run_one_case
(
model
,
input_data
)
output_data
=
run_one_case
(
model
,
input_data
)
# check output correctness
# check output correctness
ret
=
check_correctness
(
gold_outputs
,
output_data
)
ret
=
check_correctness
(
gold_outputs
,
output_data
,
atol
=
args
.
atol
,
rtol
=
args
.
rtol
)
if
ret
:
if
ret
:
correct_num
+=
1
correct_num
+=
1
...
...
Prev
1
…
16
17
18
19
20
Next
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