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
4a4f537e
"ldm/models/vscode:/vscode.git/clone" did not exist on "86685e45d17c09a0121293737a653a2353bd486b"
Unverified
Commit
4a4f537e
authored
May 18, 2022
by
Paul Fultz II
Committed by
GitHub
May 18, 2022
Browse files
Merge branch 'develop' into gpu-batch-gemm-bert
parents
adc03be6
a27dd28c
Changes
92
Show whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
109 additions
and
80 deletions
+109
-80
.github/workflows/ci.yaml
.github/workflows/ci.yaml
+6
-5
CMakeLists.txt
CMakeLists.txt
+9
-2
Dockerfile
Dockerfile
+2
-6
cmake/Embed.cmake
cmake/Embed.cmake
+1
-0
cmake/EnableCompilerWarnings.cmake
cmake/EnableCompilerWarnings.cmake
+1
-0
doc/src/reference/py.rst
doc/src/reference/py.rst
+7
-0
examples/nlp/python_bert_squad/BERT-Squad.ipynb
examples/nlp/python_bert_squad/BERT-Squad.ipynb
+1
-1
examples/nlp/python_bert_squad/README.md
examples/nlp/python_bert_squad/README.md
+1
-1
hip-clang.docker
hip-clang.docker
+2
-5
src/adjust_allocation.cpp
src/adjust_allocation.cpp
+6
-6
src/analyze_streams.cpp
src/analyze_streams.cpp
+14
-14
src/api/api.cpp
src/api/api.cpp
+16
-0
src/api/include/migraphx/migraphx.h
src/api/include/migraphx/migraphx.h
+5
-0
src/api/include/migraphx/migraphx.hpp
src/api/include/migraphx/migraphx.hpp
+11
-0
src/api/migraphx.py
src/api/migraphx.py
+3
-0
src/auto_contiguous.cpp
src/auto_contiguous.cpp
+8
-8
src/dead_code_elimination.cpp
src/dead_code_elimination.cpp
+6
-22
src/driver/marker_roctx.cpp
src/driver/marker_roctx.cpp
+1
-1
src/eliminate_allocation.cpp
src/eliminate_allocation.cpp
+4
-4
src/eliminate_common_subexpression.cpp
src/eliminate_common_subexpression.cpp
+5
-5
No files found.
.github/workflows/ci.yaml
View file @
4a4f537e
...
...
@@ -15,7 +15,8 @@ jobs:
steps
:
-
name
:
Free space
run
:
sudo rm -rf /usr/local/android /usr/share/dotnet /usr/local/share/boost /opt/ghc /usr/local/share/chrom* /usr/share/swift /usr/local/julia*
run
:
sudo rm -rf /usr/local/android /usr/share/dotnet /usr/local/share/boost /opt/ghc /usr/local/share/chrom* /usr/share/swift /usr/local/julia* /usr/local/lib/android
-
uses
:
actions/checkout@v2
# In this step, this action saves a list of existing images,
...
...
@@ -63,7 +64,7 @@ jobs:
steps
:
-
name
:
Free space
run
:
sudo rm -rf /usr/local/android /usr/share/dotnet /usr/local/share/boost /opt/ghc /usr/local/share/chrom* /usr/share/swift /usr/local/julia*
run
:
sudo rm -rf /usr/local/android /usr/share/dotnet /usr/local/share/boost /opt/ghc /usr/local/share/chrom* /usr/share/swift /usr/local/julia*
/usr/local/lib/android
-
uses
:
actions/checkout@v2
# In this step, this action saves a list of existing images,
...
...
@@ -108,7 +109,7 @@ jobs:
steps
:
-
name
:
Free space
run
:
sudo rm -rf /usr/local/android /usr/share/dotnet /usr/local/share/boost /opt/ghc /usr/local/share/chrom* /usr/share/swift /usr/local/julia*
run
:
sudo rm -rf /usr/local/android /usr/share/dotnet /usr/local/share/boost /opt/ghc /usr/local/share/chrom* /usr/share/swift /usr/local/julia*
/usr/local/lib/android
-
uses
:
actions/checkout@v2
# In this step, this action saves a list of existing images,
...
...
@@ -143,7 +144,7 @@ jobs:
steps
:
-
name
:
Free space
run
:
sudo rm -rf /usr/local/android /usr/share/dotnet /usr/local/share/boost /opt/ghc /usr/local/share/chrom* /usr/share/swift /usr/local/julia*
run
:
sudo rm -rf /usr/local/android /usr/share/dotnet /usr/local/share/boost /opt/ghc /usr/local/share/chrom* /usr/share/swift /usr/local/julia*
/usr/local/lib/android
-
uses
:
actions/checkout@v2
-
name
:
Set up Python
uses
:
actions/setup-python@v2
...
...
@@ -182,7 +183,7 @@ jobs:
steps
:
-
name
:
Free space
run
:
sudo rm -rf /usr/local/android /usr/share/dotnet /usr/local/share/boost /opt/ghc /usr/local/share/chrom* /usr/share/swift /usr/local/julia*
run
:
sudo rm -rf /usr/local/android /usr/share/dotnet /usr/local/share/boost /opt/ghc /usr/local/share/chrom* /usr/share/swift /usr/local/julia*
/usr/local/lib/android
-
uses
:
actions/checkout@v2
-
name
:
Set up Python
uses
:
actions/setup-python@v2
...
...
CMakeLists.txt
View file @
4a4f537e
...
...
@@ -93,11 +93,14 @@ rocm_enable_clang_tidy(
modernize-*
performance-*
readability-*
-bugprone-signed-char-misuse
-bugprone-easily-swappable-parameters
-bugprone-implicit-widening-of-multiplication-result
-bugprone-macro-parentheses
-bugprone-signed-char-misuse
# Disable the aliased reserved identifiers
-cert-dcl37-c
-cert-dcl51-cpp
-cert-err33-c
-cert-str34-c
# Disable all alpha checks by default
-clang-analyzer-alpha*
...
...
@@ -127,6 +130,7 @@ rocm_enable_clang_tidy(
-cppcoreguidelines-pro-type-union-access
-cppcoreguidelines-pro-type-vararg
-cppcoreguidelines-special-member-functions
-cppcoreguidelines-virtual-class-destructor
-google-readability-*
-google-runtime-int
-google-runtime-references
...
...
@@ -144,8 +148,10 @@ rocm_enable_clang_tidy(
-readability-convert-member-functions-to-static
-readability-else-after-return
-readability-function-cognitive-complexity
-readability-identifier-length
-readability-named-parameter
-readability-redundant-string-init
-readability-suspicious-call-argument
-readability-uppercase-literal-suffix
-*-avoid-c-arrays
-*-explicit-constructor
...
...
@@ -216,6 +222,7 @@ rocm_enable_cppcheck(
CPPCHECK=1
__device__=
__host__=
__global__=
)
enable_testing
()
...
...
Dockerfile
View file @
4a4f537e
FROM
ubuntu:
18
.04
FROM
ubuntu:
20
.04
ARG
PREFIX=/usr/local
...
...
@@ -6,7 +6,7 @@ ARG PREFIX=/usr/local
RUN
dpkg
--add-architecture
i386
# Add rocm repository
RUN
sh
-c
'echo deb [arch=amd64 trusted=yes] http://repo.radeon.com/rocm/apt/
4.5
/ ubuntu main > /etc/apt/sources.list.d/rocm.list'
RUN
sh
-c
'echo deb [arch=amd64 trusted=yes] http://repo.radeon.com/rocm/apt/
5.0.2
/ ubuntu main > /etc/apt/sources.list.d/rocm.list'
# Install dependencies
RUN
apt-get update
&&
DEBIAN_FRONTEND
=
noninteractive apt-get
install
-y
--allow-unauthenticated
\
...
...
@@ -16,16 +16,12 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --allow-
cmake
\
curl
\
doxygen
\
g++-5
\
g++-7
\
gdb
\
git
\
lcov
\
locales
\
pkg-config
\
python
\
python-dev
\
python-pip
\
python3
\
python3-dev
\
python3-pip
\
...
...
cmake/Embed.cmake
View file @
4a4f537e
...
...
@@ -94,5 +94,6 @@ function(add_embed_library EMBED_NAME)
generate_embed_source
(
${
EMBED_NAME
}
SRC
${
SRC_FILE
}
HEADER
${
HEADER_FILE
}
OBJECTS
${
OUTPUT_FILES
}
SYMBOLS
${
SYMBOLS
}
)
add_library
(
${
EMBED_NAME
}
STATIC
${
OUTPUT_FILES
}
"
${
SRC_FILE
}
"
)
target_include_directories
(
${
EMBED_NAME
}
PUBLIC
"
${
EMBED_DIR
}
/include"
)
target_compile_options
(
${
EMBED_NAME
}
PRIVATE -Wno-reserved-identifier
)
set_target_properties
(
${
EMBED_NAME
}
PROPERTIES POSITION_INDEPENDENT_CODE On
)
endfunction
()
cmake/EnableCompilerWarnings.cmake
View file @
4a4f537e
...
...
@@ -96,6 +96,7 @@ else()
-Wno-gnu-zero-variadic-macro-arguments
-Wno-missing-prototypes
-Wno-nested-anon-types
-Wno-option-ignored
-Wno-padded
-Wno-shorten-64-to-32
-Wno-sign-conversion
...
...
doc/src/reference/py.rst
View file @
4a4f537e
...
...
@@ -146,6 +146,13 @@ module
:param list[module] mod_args: optional list of module arguments to the operator.
:rtype instruction
.. py:method:: add_literal(data)
Adds constant or literal data of provided shape into the module from python buffer which includes numpy array.
:param py::buffer data: Python buffer or numpy array
:rtype instruction
.. py:method:: add_parameter(name, shape)
Adds a parameter to the module with provided name and shape.
...
...
examples/nlp/python_bert_squad/BERT-Squad.ipynb
View file @
4a4f537e
...
...
@@ -62,7 +62,7 @@
"metadata": {},
"outputs": [],
"source": [
"!wget -nc https://github.com/onnx/models/
raw/master
/text/machine_comprehension/bert-squad/model/bertsquad-10.onnx"
"!wget -nc https://github.com/onnx/models/
blob/main
/text/machine_comprehension/bert-squad/model/bertsquad-10.onnx"
]
},
{
...
...
examples/nlp/python_bert_squad/README.md
View file @
4a4f537e
...
...
@@ -23,7 +23,7 @@ unzip uncased_L-12_H-768_A-12.zip
```
5) Get BERT ONNX model (bertsquad-10.onnx):
```
wget https://github.com/onnx/models/
raw/master
/text/machine_comprehension/bert-squad/model/bertsquad-10.onnx
wget https://github.com/onnx/models/
blob/main
/text/machine_comprehension/bert-squad/model/bertsquad-10.onnx
```
6) Run the inference, it will compile and run the model on three questions and small data provided in
`inputs.json`
:
```
...
...
hip-clang.docker
View file @
4a4f537e
FROM
ubuntu:
18
.04
FROM
ubuntu:
20
.04
ARG
PREFIX=/usr/local
...
...
@@ -6,7 +6,7 @@ ARG PREFIX=/usr/local
RUN
dpkg
--add-architecture
i386
# Add rocm repository
RUN
sh
-c
'echo deb [arch=amd64 trusted=yes] http://repo.radeon.com/rocm/apt/
4.5
/ ubuntu main > /etc/apt/sources.list.d/rocm.list'
RUN
sh
-c
'echo deb [arch=amd64 trusted=yes] http://repo.radeon.com/rocm/apt/
5.0.2
/ ubuntu main > /etc/apt/sources.list.d/rocm.list'
# Install dependencies
RUN
apt-get update
&&
DEBIAN_FRONTEND
=
noninteractive apt-get
install
-y
--allow-unauthenticated
\
...
...
@@ -20,9 +20,6 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --allow-
git
\
lcov
\
pkg-config
\
python
\
python-dev
\
python-pip
\
python3
\
python3-dev
\
python3-pip
\
...
...
src/adjust_allocation.cpp
View file @
4a4f537e
...
...
@@ -8,9 +8,9 @@
namespace
migraphx
{
inline
namespace
MIGRAPHX_INLINE_NS
{
void
adjust_allocation
::
apply
(
module
&
p
)
const
void
adjust_allocation
::
apply
(
module
&
m
)
const
{
for
(
auto
ins
:
iterator_for
(
p
))
for
(
auto
ins
:
iterator_for
(
m
))
{
// skip instruction with no input
if
(
ins
->
inputs
().
empty
())
...
...
@@ -27,13 +27,13 @@ void adjust_allocation::apply(module& p) const
// of the instruction, reallocate and replace the previous one
if
(
alias_ins
->
get_shape
()
==
ins
->
get_shape
())
continue
;
auto
alloc_ins
=
p
.
insert_instruction
(
ins
,
model
.
allocate
(
ins
->
get_shape
()));
p
.
replace_instruction
(
alias_ins
,
alloc_ins
);
auto
alloc_ins
=
m
.
insert_instruction
(
ins
,
model
.
allocate
(
ins
->
get_shape
()));
m
.
replace_instruction
(
alias_ins
,
alloc_ins
);
// If the memory is an output parameter then copy the memory to the parameter
if
(
alias_ins
->
name
()
==
"@param"
)
{
auto
copy
=
p
.
insert_instruction
(
std
::
next
(
ins
),
make_op
(
model
.
copy
()),
ins
,
alias_ins
);
auto
tail
=
range
(
std
::
next
(
copy
),
p
.
end
());
auto
copy
=
m
.
insert_instruction
(
std
::
next
(
ins
),
make_op
(
model
.
copy
()),
ins
,
alias_ins
);
auto
tail
=
range
(
std
::
next
(
copy
),
m
.
end
());
for
(
auto
i
:
iterator_for
(
tail
))
{
if
(
contains
(
i
->
inputs
(),
ins
))
...
...
src/analyze_streams.cpp
View file @
4a4f537e
...
...
@@ -14,31 +14,31 @@ bool happens_before(const std::vector<std::size_t>& e1, const std::vector<std::s
not
std
::
equal
(
e1
.
begin
(),
e1
.
end
(),
e2
.
begin
(),
e2
.
end
(),
std
::
greater_equal
<>
{});
}
std
::
vector
<
stream_race
>
analyze_streams
(
const
module
&
p
,
const
stream_model
&
m
)
std
::
vector
<
stream_race
>
analyze_streams
(
const
module
&
m
,
const
stream_model
&
strm
m
)
{
using
vector_clock
=
std
::
vector
<
std
::
size_t
>
;
std
::
vector
<
stream_race
>
races
;
auto
nstream
=
m
.
get_nstream
();
auto
nstream
=
strm
m
.
get_nstream
();
std
::
vector
<
vector_clock
>
vclock
(
nstream
,
vector_clock
(
nstream
));
std
::
unordered_map
<
instruction_ref
,
vector_clock
>
timestamp
;
std
::
unordered_map
<
std
::
size_t
,
vector_clock
>
events
;
for
(
auto
ins
:
iterator_for
(
p
))
for
(
auto
ins
:
iterator_for
(
m
))
{
if
(
not
m
.
has_stream
(
ins
))
if
(
not
strm
m
.
has_stream
(
ins
))
continue
;
std
::
size_t
s
=
m
.
get_stream
(
ins
);
std
::
size_t
s
=
strm
m
.
get_stream
(
ins
);
assert
(
s
<
nstream
);
assert
(
vclock
.
size
()
==
nstream
);
assert
(
vclock
[
s
].
size
()
==
nstream
);
if
(
m
.
is_record
(
ins
))
if
(
strm
m
.
is_record
(
ins
))
{
vclock
[
s
][
s
]
++
;
auto
event
=
m
.
get_event_id
(
ins
);
auto
event
=
strm
m
.
get_event_id
(
ins
);
events
[
event
]
=
vclock
[
s
];
}
else
if
(
m
.
is_wait
(
ins
))
else
if
(
strm
m
.
is_wait
(
ins
))
{
auto
event
=
m
.
get_event_id
(
ins
);
auto
event
=
strm
m
.
get_event_id
(
ins
);
if
(
not
contains
(
events
,
event
))
MIGRAPHX_THROW
(
"Event is waited on before being recorded: "
+
std
::
to_string
(
event
));
...
...
@@ -57,21 +57,21 @@ std::vector<stream_race> analyze_streams(const module& p, const stream_model& m)
}
timestamp
[
ins
]
=
vclock
[
s
];
}
for
(
auto
ins
:
iterator_for
(
p
))
for
(
auto
ins
:
iterator_for
(
m
))
{
if
(
not
m
.
has_stream
(
ins
))
if
(
not
strm
m
.
has_stream
(
ins
))
continue
;
if
(
ins
->
inputs
().
empty
())
continue
;
std
::
size_t
s
=
m
.
get_stream
(
ins
);
std
::
size_t
s
=
strm
m
.
get_stream
(
ins
);
// Find inputs from different streams
std
::
vector
<
instruction_ref
>
inputs
;
fix
([
&
](
auto
self
,
auto
start
)
{
for
(
auto
input
:
start
->
inputs
())
{
if
(
not
m
.
has_stream
(
input
))
if
(
not
strm
m
.
has_stream
(
input
))
self
(
input
);
else
if
(
m
.
get_stream
(
input
)
!=
s
)
else
if
(
strm
m
.
get_stream
(
input
)
!=
s
)
inputs
.
push_back
(
input
);
}
})(
ins
);
...
...
src/api/api.cpp
View file @
4a4f537e
...
...
@@ -1072,6 +1072,22 @@ migraphx_module_add_instruction_with_mod_args(migraphx_instruction_t* out,
return
api_error_result
;
}
extern
"C"
migraphx_status
migraphx_module_add_literal
(
migraphx_instruction_t
*
out
,
migraphx_module_t
module
,
const_migraphx_shape_t
shape
,
const
char
*
buffer
)
{
auto
api_error_result
=
migraphx
::
try_
([
&
]
{
if
(
module
==
nullptr
)
MIGRAPHX_THROW
(
migraphx_status_bad_param
,
"Bad parameter module: Null pointer"
);
if
(
shape
==
nullptr
)
MIGRAPHX_THROW
(
migraphx_status_bad_param
,
"Bad parameter shape: Null pointer"
);
*
out
=
allocate
<
migraphx_instruction_t
>
(
(
module
->
object
).
add_literal
((
shape
->
object
),
(
buffer
)));
});
return
api_error_result
;
}
extern
"C"
migraphx_status
migraphx_module_add_parameter
(
migraphx_instruction_t
*
out
,
migraphx_module_t
module
,
const
char
*
name
,
...
...
src/api/include/migraphx/migraphx.h
View file @
4a4f537e
...
...
@@ -258,6 +258,11 @@ migraphx_status migraphx_module_add_instruction_with_mod_args(migraphx_instructi
migraphx_instructions_t
args
,
migraphx_modules_t
module_refs
);
migraphx_status
migraphx_module_add_literal
(
migraphx_instruction_t
*
out
,
migraphx_module_t
module
,
const_migraphx_shape_t
shape
,
const
char
*
buffer
);
migraphx_status
migraphx_module_add_parameter
(
migraphx_instruction_t
*
out
,
migraphx_module_t
module
,
const
char
*
name
,
...
...
src/api/include/migraphx/migraphx.hpp
View file @
4a4f537e
...
...
@@ -314,6 +314,7 @@ struct interface_base : Base
T
**
y
=
reinterpret_cast
<
T
**>
(
out
);
T
*
x
=
reinterpret_cast
<
T
*>
(
input
);
assert
(
x
!=
nullptr
and
y
!=
nullptr
and
*
y
==
nullptr
);
// cppcheck-suppress useSmartPointer
*
y
=
new
T
(
*
x
);
// NOLINT
});
};
...
...
@@ -339,6 +340,7 @@ struct interface_base : Base
template
<
class
T
,
class
Setter
,
class
F
>
void
set_auto_fp
(
Setter
setter
,
F
f
)
{
// cppcheck-suppress constParameter
return
set_fp
<
T
>
(
setter
,
[
=
](
T
&
obj
,
auto
out
,
auto
...
xs
)
{
auto_invoke
(
f
,
out
,
obj
,
auto_convert_param
(
rank
<
2
>
{},
xs
)...);
});
...
...
@@ -760,6 +762,15 @@ struct module
return
instruction
(
op_ins
,
own
{});
}
template
<
typename
T
>
instruction
add_literal
(
const
migraphx
::
shape
&
s
,
T
*
buffer
)
{
migraphx_instruction_t
literal_ins
;
const
auto
*
buffer_ptr
=
reinterpret_cast
<
const
char
*>
(
buffer
);
call
(
&
migraphx_module_add_literal
,
&
literal_ins
,
mm
.
get
(),
s
.
get_handle_ptr
(),
buffer_ptr
);
return
instruction
(
literal_ins
,
own
{});
}
instruction
add_parameter
(
const
std
::
string
&
name
,
shape
s
)
{
migraphx_instruction_t
param_ins
;
...
...
src/api/migraphx.py
View file @
4a4f537e
...
...
@@ -212,6 +212,9 @@ def module(h):
module_refs
=
'std::vector<migraphx::module*>'
),
fname
=
'add_instruction'
,
returns
=
'migraphx::instruction_ref'
)
h
.
method
(
'add_literal'
,
api
.
params
(
shape
=
'const migraphx::shape&'
,
buffer
=
'const char*'
),
returns
=
'migraphx::instruction_ref'
)
h
.
method
(
'add_parameter'
,
api
.
params
(
name
=
'const char*'
,
shape
=
'const migraphx::shape&'
),
returns
=
'migraphx::instruction_ref'
)
...
...
src/auto_contiguous.cpp
View file @
4a4f537e
...
...
@@ -8,10 +8,10 @@
namespace
migraphx
{
inline
namespace
MIGRAPHX_INLINE_NS
{
void
auto_contiguous
::
apply
(
module
&
p
)
const
void
auto_contiguous
::
apply
(
module
&
m
)
const
{
std
::
string
key
=
"require_std_shape"
;
for
(
auto
ins
:
reverse_iterator_for
(
p
))
for
(
auto
ins
:
reverse_iterator_for
(
m
))
{
auto
&&
attr
=
ins
->
get_operator
().
attributes
();
if
((
attr
.
get
(
key
,
false
)))
...
...
@@ -23,18 +23,18 @@ void auto_contiguous::apply(module& p) const
{
return
in
;
}
return
p
.
insert_instruction
(
ins
,
make_op
(
"contiguous"
),
in
);
return
m
.
insert_instruction
(
ins
,
make_op
(
"contiguous"
),
in
);
});
if
(
new_args
!=
args
)
{
p
.
replace_instruction
(
ins
,
ins
->
get_operator
(),
new_args
);
m
.
replace_instruction
(
ins
,
ins
->
get_operator
(),
new_args
);
}
}
}
auto
last
=
std
::
prev
(
p
.
end
());
for
(
auto
ins
:
iterator_for
(
p
))
auto
last
=
std
::
prev
(
m
.
end
());
for
(
auto
ins
:
iterator_for
(
m
))
{
// for last instruction that is NOT a return
if
(
ins
->
outputs
().
empty
()
and
ins
!=
last
)
...
...
@@ -42,8 +42,8 @@ void auto_contiguous::apply(module& p) const
shape
s
=
ins
->
get_shape
();
if
(
not
s
.
standard
()
and
s
.
elements
()
!=
0
)
{
auto
c
=
p
.
insert_instruction
(
std
::
next
(
ins
),
make_op
(
"contiguous"
),
ins
);
p
.
replace_instruction
(
ins
,
c
);
auto
c
=
m
.
insert_instruction
(
std
::
next
(
ins
),
make_op
(
"contiguous"
),
ins
);
m
.
replace_instruction
(
ins
,
c
);
}
}
}
...
...
src/dead_code_elimination.cpp
View file @
4a4f537e
...
...
@@ -9,26 +9,6 @@
namespace
migraphx
{
inline
namespace
MIGRAPHX_INLINE_NS
{
template
<
class
Range
,
class
Iterator
>
std
::
ptrdiff_t
bidistance
(
const
Range
&
r
,
Iterator
start
,
Iterator
last
)
{
auto
start_forward
=
start
;
auto
start_backwards
=
start
;
std
::
size_t
n
=
0
;
while
(
start_forward
!=
last
and
start_backwards
!=
last
)
{
n
++
;
if
(
start_forward
!=
r
.
end
())
start_forward
++
;
if
(
start_backwards
!=
r
.
begin
())
start_backwards
--
;
}
if
(
start_forward
==
last
)
return
n
;
else
return
-
n
;
}
void
dead_code_elimination
::
apply
(
program
&
p
)
const
{
p
.
remove_unused_modules
();
}
void
dead_code_elimination
::
apply
(
module
&
m
)
const
...
...
@@ -48,17 +28,21 @@ void dead_code_elimination::apply(module& m) const
if
(
i
->
get_shape
().
elements
()
==
0
and
i
->
name
().
front
()
!=
'@'
and
i
->
name
()
!=
"undefined"
and
i
->
name
()
!=
"identity"
)
continue
;
assert
(
bidistance
(
m
,
i
,
last
)
>
0
);
assert
(
std
::
distance
(
m
.
begin
(),
i
)
<=
std
::
distance
(
m
.
begin
(),
last
));
std
::
unordered_set
<
instruction_ref
>
visited
;
fix
([
&
](
auto
self
,
auto
leaf
)
{
if
(
not
m
.
has_instruction
(
leaf
))
return
;
if
(
leaf
->
outputs
().
empty
())
{
// Dont visit inputs twice
if
(
not
visited
.
insert
(
leaf
).
second
)
return
;
std
::
unordered_set
<
instruction_ref
>
args
(
leaf
->
inputs
().
begin
(),
leaf
->
inputs
().
end
());
leaf
->
clear_arguments
();
assert
(
bi
distance
(
m
,
last
,
leaf
)
<
0
);
assert
(
std
::
distance
(
m
.
begin
(),
leaf
)
<
std
::
distance
(
m
.
begin
(),
last
)
);
assert
(
leaf
!=
ins
);
if
(
leaf
->
name
()
!=
"@param"
)
m
.
move_instruction
(
leaf
,
m
.
end
());
...
...
src/driver/marker_roctx.cpp
View file @
4a4f537e
...
...
@@ -17,7 +17,7 @@ class marker_roctx
std
::
function
<
int
(
const
char
*
)
>
sym_roctx_range_push
;
std
::
function
<
int
()
>
sym_roctx_range_pop
;
uint64_t
range_id
;
uint64_t
range_id
=
0
;
public:
marker_roctx
()
...
...
src/eliminate_allocation.cpp
View file @
4a4f537e
...
...
@@ -13,13 +13,13 @@
namespace
migraphx
{
inline
namespace
MIGRAPHX_INLINE_NS
{
void
eliminate_allocation
::
apply
(
module
&
p
)
const
void
eliminate_allocation
::
apply
(
module
&
m
)
const
{
assert
(
alignment
>
0
);
std
::
size_t
n
=
0
;
std
::
vector
<
std
::
pair
<
instruction_ref
,
std
::
size_t
>>
allocs
;
for
(
auto
ins
:
iterator_for
(
p
))
for
(
auto
ins
:
iterator_for
(
m
))
{
if
(
ins
->
name
()
!=
allocation_op
)
continue
;
...
...
@@ -30,13 +30,13 @@ void eliminate_allocation::apply(module& p) const
}
if
(
n
>
0
)
{
auto
mem
=
p
.
add_parameter
(
"memory"
,
shape
{
shape
::
int8_type
,
{
n
}});
auto
mem
=
m
.
add_parameter
(
"memory"
,
shape
{
shape
::
int8_type
,
{
n
}});
for
(
auto
&&
pp
:
allocs
)
{
auto
ins
=
pp
.
first
;
auto
s
=
ins
->
get_shape
();
auto
offset
=
pp
.
second
;
p
.
replace_instruction
(
m
.
replace_instruction
(
ins
,
make_op
(
"load"
,
{{
"shape"
,
to_value
(
s
)},
{
"offset"
,
offset
}}),
mem
);
}
}
...
...
src/eliminate_common_subexpression.cpp
View file @
4a4f537e
...
...
@@ -11,7 +11,7 @@ namespace migraphx {
inline
namespace
MIGRAPHX_INLINE_NS
{
template
<
class
Range
>
void
cse_range
(
module
&
p
,
Range
&&
r
)
void
cse_range
(
module
&
m
,
Range
&&
r
)
{
std
::
unordered_multimap
<
std
::
string
,
instruction_ref
>
instructions
;
std
::
unordered_set
<
instruction_ref
>
processed_ins
;
...
...
@@ -30,24 +30,24 @@ void cse_range(module& p, Range&& r)
continue
;
if
(
*
eq
!=
*
ins
)
continue
;
p
.
replace_instruction
(
ins
,
eq
);
m
.
replace_instruction
(
ins
,
eq
);
processed_ins
.
emplace
(
ins
);
std
::
vector
<
instruction_ref
>
outputs
;
std
::
copy_if
(
eq
->
outputs
().
begin
(),
eq
->
outputs
().
end
(),
std
::
back_inserter
(
outputs
),
[
&
](
auto
x
)
{
return
p
.
has_instruction
(
x
);
});
[
&
](
auto
x
)
{
return
m
.
has_instruction
(
x
);
});
std
::
sort
(
outputs
.
begin
(),
outputs
.
end
(),
[
&
](
auto
x
,
auto
y
)
{
return
std
::
distance
(
eq
,
x
)
<
std
::
distance
(
eq
,
y
);
});
cse_range
(
p
,
outputs
);
cse_range
(
m
,
outputs
);
}
instructions
.
emplace
(
ins
->
name
(),
ins
);
}
}
void
eliminate_common_subexpression
::
apply
(
module
&
p
)
const
{
cse_range
(
p
,
iterator_for
(
p
));
}
void
eliminate_common_subexpression
::
apply
(
module
&
m
)
const
{
cse_range
(
m
,
iterator_for
(
m
));
}
}
// namespace MIGRAPHX_INLINE_NS
}
// namespace migraphx
Prev
1
2
3
4
5
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