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
ebfbae82
Commit
ebfbae82
authored
May 17, 2022
by
turneram
Browse files
Merge remote-tracking branch 'origin/develop' into transformer-opts
parents
1974671d
a27dd28c
Changes
46
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
67 additions
and
67 deletions
+67
-67
src/adjust_allocation.cpp
src/adjust_allocation.cpp
+6
-6
src/analyze_streams.cpp
src/analyze_streams.cpp
+14
-14
src/auto_contiguous.cpp
src/auto_contiguous.cpp
+8
-8
src/eliminate_allocation.cpp
src/eliminate_allocation.cpp
+4
-4
src/eliminate_common_subexpression.cpp
src/eliminate_common_subexpression.cpp
+5
-5
src/eliminate_concat.cpp
src/eliminate_concat.cpp
+6
-6
src/eliminate_contiguous.cpp
src/eliminate_contiguous.cpp
+4
-4
src/eliminate_identity.cpp
src/eliminate_identity.cpp
+8
-8
src/include/migraphx/adjust_allocation.hpp
src/include/migraphx/adjust_allocation.hpp
+1
-1
src/include/migraphx/analyze_streams.hpp
src/include/migraphx/analyze_streams.hpp
+1
-1
src/include/migraphx/auto_contiguous.hpp
src/include/migraphx/auto_contiguous.hpp
+1
-1
src/include/migraphx/check_context.hpp
src/include/migraphx/check_context.hpp
+1
-1
src/include/migraphx/eliminate_allocation.hpp
src/include/migraphx/eliminate_allocation.hpp
+1
-1
src/include/migraphx/eliminate_common_subexpression.hpp
src/include/migraphx/eliminate_common_subexpression.hpp
+1
-1
src/include/migraphx/eliminate_concat.hpp
src/include/migraphx/eliminate_concat.hpp
+1
-1
src/include/migraphx/eliminate_contiguous.hpp
src/include/migraphx/eliminate_contiguous.hpp
+1
-1
src/include/migraphx/eliminate_identity.hpp
src/include/migraphx/eliminate_identity.hpp
+1
-1
src/include/migraphx/memory_coloring.hpp
src/include/migraphx/memory_coloring.hpp
+1
-1
src/include/migraphx/propagate_constant.hpp
src/include/migraphx/propagate_constant.hpp
+1
-1
src/include/migraphx/rewrite_batchnorm.hpp
src/include/migraphx/rewrite_batchnorm.hpp
+1
-1
No files found.
src/adjust_allocation.cpp
View file @
ebfbae82
...
...
@@ -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 @
ebfbae82
...
...
@@ -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/auto_contiguous.cpp
View file @
ebfbae82
...
...
@@ -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/eliminate_allocation.cpp
View file @
ebfbae82
...
...
@@ -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 @
ebfbae82
...
...
@@ -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
src/eliminate_concat.cpp
View file @
ebfbae82
...
...
@@ -13,9 +13,9 @@
namespace
migraphx
{
inline
namespace
MIGRAPHX_INLINE_NS
{
void
eliminate_concat
::
apply
(
module
&
p
)
const
void
eliminate_concat
::
apply
(
module
&
m
)
const
{
for
(
auto
ins
:
iterator_for
(
p
))
for
(
auto
ins
:
iterator_for
(
m
))
{
// Look for the concat operator
if
(
ins
->
name
()
!=
concat_opt
.
name
())
...
...
@@ -64,22 +64,22 @@ void eliminate_concat::apply(module& p) const
std
::
sort
(
sorted_allocations
.
begin
(),
sorted_allocations
.
end
(),
[
&
](
instruction_ref
x
,
instruction_ref
y
)
{
return
std
::
distance
(
p
.
begin
(),
x
)
<
std
::
distance
(
p
.
begin
(),
y
);
return
std
::
distance
(
m
.
begin
(),
x
)
<
std
::
distance
(
m
.
begin
(),
y
);
});
// Move "super" allocation to the front
auto
first
=
sorted_allocations
.
front
();
auto
super
=
p
.
move_instruction
(
last
,
first
);
auto
super
=
m
.
move_instruction
(
last
,
first
);
// Replace each allocation with a load
std
::
size_t
offset
=
0
;
for
(
auto
alloc
:
allocations
)
{
op
::
load
op
{
alloc
->
get_shape
(),
offset
};
p
.
replace_instruction
(
alloc
,
op
,
{
super
});
m
.
replace_instruction
(
alloc
,
op
,
{
super
});
offset
+=
alloc
->
get_shape
().
bytes
();
}
std
::
vector
<
instruction_ref
>
args
=
{
super
};
std
::
copy
(
ins
->
inputs
().
begin
(),
ins
->
inputs
().
end
()
-
1
,
std
::
back_inserter
(
args
));
p
.
replace_instruction
(
ins
,
migraphx
::
make_op
(
"identity"
),
args
);
m
.
replace_instruction
(
ins
,
migraphx
::
make_op
(
"identity"
),
args
);
}
}
}
...
...
src/eliminate_contiguous.cpp
View file @
ebfbae82
...
...
@@ -69,9 +69,9 @@ static bool try_compute_shape(instruction_ref ins,
return
try_compute_shape
(
ins
,
inputs
,
mods
);
}
void
eliminate_contiguous
::
apply
(
module
&
p
)
const
void
eliminate_contiguous
::
apply
(
module
&
m
)
const
{
for
(
auto
ins
:
iterator_for
(
p
))
for
(
auto
ins
:
iterator_for
(
m
))
{
// return instruction should have inputs with standard shape
if
(
ins
->
name
()
==
"@return"
)
...
...
@@ -96,8 +96,8 @@ void eliminate_contiguous::apply(module& p) const
auto
c
=
op
::
contiguous
{};
auto
r
=
c
.
compute
(
c
.
compute_shape
({
prev
->
get_shape
()}),
{
prev
->
eval
()});
auto
l
=
p
.
add_literal
(
r
.
get_shape
(),
r
.
data
());
p
.
replace_instruction
(
arg
,
l
);
auto
l
=
m
.
add_literal
(
r
.
get_shape
(),
r
.
data
());
m
.
replace_instruction
(
arg
,
l
);
}
}
}
...
...
src/eliminate_identity.cpp
View file @
ebfbae82
...
...
@@ -8,21 +8,21 @@
namespace
migraphx
{
inline
namespace
MIGRAPHX_INLINE_NS
{
void
eliminate_identity
::
apply
(
module
&
p
)
const
void
eliminate_identity
::
apply
(
module
&
m
)
const
{
auto
last
=
std
::
prev
(
p
.
end
());
for
(
auto
ins
:
iterator_for
(
p
))
auto
last
=
std
::
prev
(
m
.
end
());
for
(
auto
ins
:
iterator_for
(
m
))
{
// Skip the first instruction, since we always process the previous
// instruction
if
(
ins
==
p
.
begin
())
if
(
ins
==
m
.
begin
())
continue
;
const
auto
i
=
std
::
prev
(
ins
);
if
(
i
->
name
()
==
"identity"
)
{
p
.
replace_instruction
(
i
,
i
->
inputs
().
front
());
p
.
move_instruction
(
i
,
p
.
end
());
m
.
replace_instruction
(
i
,
i
->
inputs
().
front
());
m
.
move_instruction
(
i
,
m
.
end
());
}
if
(
ins
==
last
)
{
...
...
@@ -31,7 +31,7 @@ void eliminate_identity::apply(module& p) const
const
instruction_ref
&
identity_input
=
ins
->
inputs
().
front
();
if
(
identity_input
->
outputs
().
size
()
==
1
)
{
p
.
move_instruction
(
identity_input
,
i
);
m
.
move_instruction
(
identity_input
,
i
);
// since this is the last instruction, removing it only
// requires changing "last" and calling remove below
last
=
std
::
prev
(
last
);
...
...
@@ -40,7 +40,7 @@ void eliminate_identity::apply(module& p) const
break
;
}
}
p
.
remove_instructions
(
std
::
next
(
last
),
p
.
end
());
m
.
remove_instructions
(
std
::
next
(
last
),
m
.
end
());
}
}
// namespace MIGRAPHX_INLINE_NS
...
...
src/include/migraphx/adjust_allocation.hpp
View file @
ebfbae82
...
...
@@ -13,7 +13,7 @@ struct adjust_allocation
{
allocation_model
model
;
std
::
string
name
()
const
{
return
"adjust_allocation"
;
}
void
apply
(
module
&
p
)
const
;
void
apply
(
module
&
m
)
const
;
};
}
// namespace MIGRAPHX_INLINE_NS
...
...
src/include/migraphx/analyze_streams.hpp
View file @
ebfbae82
...
...
@@ -16,7 +16,7 @@ struct stream_race
instruction_ref
before
;
};
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
);
}
// namespace MIGRAPHX_INLINE_NS
}
// namespace migraphx
...
...
src/include/migraphx/auto_contiguous.hpp
View file @
ebfbae82
...
...
@@ -13,7 +13,7 @@ struct module;
struct
auto_contiguous
{
std
::
string
name
()
const
{
return
"auto_contiguous"
;
}
void
apply
(
module
&
p
)
const
;
void
apply
(
module
&
m
)
const
;
};
}
// namespace MIGRAPHX_INLINE_NS
...
...
src/include/migraphx/check_context.hpp
View file @
ebfbae82
...
...
@@ -33,7 +33,7 @@ struct check_context
};
std
::
string
name
()
const
{
return
"check_context"
;
}
void
apply
(
module
&
p
)
const
{
p
.
insert_instruction
(
p
.
begin
(),
op
{});
}
void
apply
(
module
&
m
)
const
{
m
.
insert_instruction
(
m
.
begin
(),
op
{});
}
};
}
// namespace MIGRAPHX_INLINE_NS
...
...
src/include/migraphx/eliminate_allocation.hpp
View file @
ebfbae82
...
...
@@ -19,7 +19,7 @@ struct eliminate_allocation
std
::
string
allocation_op
{};
std
::
size_t
alignment
=
32
;
std
::
string
name
()
const
{
return
"eliminate_allocation"
;
}
void
apply
(
module
&
p
)
const
;
void
apply
(
module
&
m
)
const
;
};
}
// namespace MIGRAPHX_INLINE_NS
...
...
src/include/migraphx/eliminate_common_subexpression.hpp
View file @
ebfbae82
...
...
@@ -16,7 +16,7 @@ struct module;
struct
eliminate_common_subexpression
{
std
::
string
name
()
const
{
return
"eliminate_common_subexpression"
;
}
void
apply
(
module
&
p
)
const
;
void
apply
(
module
&
m
)
const
;
};
}
// namespace MIGRAPHX_INLINE_NS
...
...
src/include/migraphx/eliminate_concat.hpp
View file @
ebfbae82
...
...
@@ -18,7 +18,7 @@ struct eliminate_concat
{
concat_optimization
concat_opt
;
std
::
string
name
()
const
{
return
"eliminate_concat"
;
}
void
apply
(
module
&
p
)
const
;
void
apply
(
module
&
m
)
const
;
};
}
// namespace MIGRAPHX_INLINE_NS
...
...
src/include/migraphx/eliminate_contiguous.hpp
View file @
ebfbae82
...
...
@@ -17,7 +17,7 @@ struct eliminate_contiguous
{
std
::
string
op_name
;
std
::
string
name
()
const
{
return
"eliminate_contiguous"
;
}
void
apply
(
module
&
p
)
const
;
void
apply
(
module
&
m
)
const
;
};
}
// namespace MIGRAPHX_INLINE_NS
...
...
src/include/migraphx/eliminate_identity.hpp
View file @
ebfbae82
...
...
@@ -18,7 +18,7 @@ struct module;
struct
eliminate_identity
{
std
::
string
name
()
const
{
return
"eliminate_identity"
;
}
void
apply
(
module
&
p
)
const
;
void
apply
(
module
&
m
)
const
;
};
}
// namespace MIGRAPHX_INLINE_NS
...
...
src/include/migraphx/memory_coloring.hpp
View file @
ebfbae82
...
...
@@ -17,7 +17,7 @@ struct memory_coloring
std
::
string
allocation_op
{};
bool
verify
=
false
;
std
::
string
name
()
const
{
return
"memory coloring"
;
}
void
apply
(
module
&
p
)
const
;
void
apply
(
module
&
m
)
const
;
};
}
// namespace MIGRAPHX_INLINE_NS
...
...
src/include/migraphx/propagate_constant.hpp
View file @
ebfbae82
...
...
@@ -15,7 +15,7 @@ struct module;
struct
propagate_constant
{
std
::
string
name
()
const
{
return
"propagate_constant"
;
}
void
apply
(
module
&
p
)
const
;
void
apply
(
module
&
m
)
const
;
};
}
// namespace MIGRAPHX_INLINE_NS
...
...
src/include/migraphx/rewrite_batchnorm.hpp
View file @
ebfbae82
...
...
@@ -16,7 +16,7 @@ struct module;
struct
rewrite_batchnorm
{
std
::
string
name
()
const
{
return
"rewrite_batchnorm"
;
}
void
apply
(
module
&
p
)
const
;
void
apply
(
module
&
m
)
const
;
};
}
// namespace MIGRAPHX_INLINE_NS
...
...
Prev
1
2
3
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