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
48847a29
Commit
48847a29
authored
Aug 29, 2018
by
mei-ye
Browse files
merge
parent
57511a21
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
24 additions
and
39 deletions
+24
-39
CMakeLists.txt
CMakeLists.txt
+2
-1
src/include/migraph/operators.hpp
src/include/migraph/operators.hpp
+1
-1
src/opt/common_header.hpp
src/opt/common_header.hpp
+0
-1
src/opt/memory_coloring_impl.cpp
src/opt/memory_coloring_impl.cpp
+15
-15
src/opt/memory_coloring_impl.hpp
src/opt/memory_coloring_impl.hpp
+6
-21
No files found.
CMakeLists.txt
View file @
48847a29
...
...
@@ -18,7 +18,8 @@ else()
set
(
MIGRAPH_ENABLE_GPU Off CACHE BOOL
""
)
endif
()
add_compile_options
(
-std=c++14 -g -O0
)
#add_compile_options(-std=c++14 -g -O0)
add_compile_options
(
-std=c++14
)
list
(
APPEND CMAKE_MODULE_PATH
${
CMAKE_CURRENT_SOURCE_DIR
}
/cmake
)
include
(
EnableCompilerWarnings
)
...
...
src/include/migraph/operators.hpp
View file @
48847a29
...
...
@@ -551,7 +551,7 @@ struct write_literal
shape
compute_shape
(
std
::
vector
<
shape
>
inputs
)
const
{
return
inputs
.
at
(
2
);
}
argument
compute
(
context
&
,
shape
,
std
::
vector
<
argument
>
)
const
{
assert
(
false
);
MIGRAPH_THROW
(
"not computable"
);
}
};
...
...
src/opt/common_header.hpp
View file @
48847a29
...
...
@@ -5,7 +5,6 @@
#include <migraph/instruction.hpp>
#include <migraph/operators.hpp>
#include <migraph/iterator_for.hpp>
#include <migraph/manage_ptr.hpp>
#include <set>
#include <list>
...
...
src/opt/memory_coloring_impl.cpp
View file @
48847a29
...
...
@@ -28,7 +28,7 @@ bool memory_coloring_impl::allocate(interval_ptr interval)
if
(
size
==
0
)
return
false
;
std
::
size_t
element_size
=
size
/
s
.
elements
();
live_range
&
segment
=
interval
->
segment
;
live_range
&
segment
=
interval
->
segment
;
int
vn
=
segment
.
vn
;
std
::
priority_queue
<
live_range
*
,
std
::
vector
<
live_range
*>
,
ordering
>
conflict_queue
;
std
::
unordered_map
<
long
long
,
live_range
*>
offset2_live
;
...
...
@@ -38,9 +38,9 @@ bool memory_coloring_impl::allocate(interval_ptr interval)
{
std
::
set
<
int
>&
vn_set
=
conflict_table
[
vn
];
for
(
auto
&
iter
:
vn_set
)
{
{
live_range
*
range
=
live_ranges
[
iter
];
long
long
offset
=
range
->
offset
;
long
long
offset
=
range
->
offset
;
if
(
offset
!=
InvalidOffset
)
{
conflict_queue
.
push
(
range
);
...
...
@@ -62,7 +62,7 @@ bool memory_coloring_impl::allocate(interval_ptr interval)
long
long
offset
=
0
;
while
(
!
conflict_queue
.
empty
())
{
live_range
*
range
=
conflict_queue
.
top
();
live_range
*
range
=
conflict_queue
.
top
();
long
long
cur_offset
=
range
->
offset
;
if
(
offset2_live
[
cur_offset
]
==
range
)
{
...
...
@@ -93,6 +93,7 @@ void memory_coloring_impl::build()
std
::
vector
<
instruction_ref
>
dead_instrs
;
std
::
set
<
int
>
live_set
;
// Build live intervals.
live_intervals
.
resize
(
num_of_instrs
);
do
{
const
instruction
*
p_iter
=
&
(
*
iter
);
...
...
@@ -104,8 +105,8 @@ void memory_coloring_impl::build()
bool
is_lit
=
is_literal
(
iter
);
if
(
is_allocate
(
iter
)
||
is_lit
)
{
live_range
&
range
=
def_interval
->
segment
;
def_interval
->
result
=
iter
->
result
;
live_range
&
range
=
def_interval
->
segment
;
def_interval
->
result
=
iter
->
result
;
def_interval
->
is_literal
=
is_lit
;
alloc_queue
.
push
(
def_interval
);
range
.
begin
=
cur_points
;
...
...
@@ -142,8 +143,8 @@ void memory_coloring_impl::build()
else
if
(
instr2_live
.
find
(
p_arg
)
==
instr2_live
.
end
())
{
// First time see a use, create a live interval.
int
id
=
num_of_lives
++
;
interval_ptr
interval
(
new
live_interval
()
);
int
id
=
num_of_lives
++
;
interval_ptr
interval
=
&
(
live_interval
s
[
id
]
);
interval
->
id
=
id
;
interval
->
segment
.
end
=
cur_points
;
interval
->
segment
.
vn
=
++
max_value_number
;
...
...
@@ -151,7 +152,6 @@ void memory_coloring_impl::build()
instr2_live
[
p_arg
]
=
interval
;
add_conflicts
(
live_set
,
max_value_number
);
live_set
.
insert
(
max_value_number
);
live_intervals
[
id
]
=
interval
;
live_ranges
[
max_value_number
]
=
&
(
interval
->
segment
);
}
else
...
...
@@ -220,8 +220,8 @@ void memory_coloring_impl::dump_intervals()
std
::
cout
<<
"---live intervals ---"
<<
std
::
endl
;
for
(
int
i
=
0
;
i
<
num_of_lives
;
++
i
)
{
interval
_ptr
interval
=
live_intervals
[
i
];
interval
->
dump
();
live_
interval
&
interval
=
live_intervals
[
i
];
interval
.
dump
();
}
std
::
cout
<<
"---conflict table---"
<<
std
::
endl
;
for
(
int
i
=
0
;
i
<=
max_value_number
;
++
i
)
...
...
@@ -244,8 +244,8 @@ void memory_coloring_impl::verify()
{
for
(
int
i
=
0
;
i
<
num_of_lives
;
++
i
)
{
interval
_ptr
interval
=
live_intervals
[
i
];
live_range
&
segment
=
interval
->
segment
;
live_
interval
&
interval
=
live_intervals
[
i
];
live_range
&
segment
=
interval
.
segment
;
if
(
segment
.
offset
==
InvalidOffset
)
continue
;
int
vn
=
segment
.
vn
;
...
...
@@ -265,12 +265,12 @@ void memory_coloring_impl::verify()
}
}
#define GET_INS_ENUM(x) (
((x) > 0) ? (((x) >> 1) - 1) : InvalidOffset)
#define GET_INS_ENUM(x) (((x) > 0) ? (((x) >> 1) - 1) : InvalidOffset)
void
live_range
::
dump
()
{
std
::
cout
<<
" segment:"
<<
vn
;
std
::
cout
<<
" ["
<<
GET_INS_ENUM
(
begin
)
<<
", "
<<
GET_INS_ENUM
(
end
)
<<
"]"
;
std
::
cout
<<
" ["
<<
GET_INS_ENUM
(
begin
)
<<
", "
<<
GET_INS_ENUM
(
end
)
<<
"]"
;
if
(
offset
!=
InvalidOffset
)
{
std
::
cout
<<
" mem:"
;
...
...
src/opt/memory_coloring_impl.hpp
View file @
48847a29
...
...
@@ -20,13 +20,11 @@ struct live_range
struct
live_interval
{
live_interval
()
live_interval
()
:
segment
({
-
1
,
-
1
,
InvalidOffset
,
-
1
,
0
})
{
id
=
-
1
;
id
=
-
1
;
is_literal
=
false
;
segment
=
{
-
1
,
-
1
,
InvalidOffset
,
-
1
,
0
};
}
~
live_interval
()
{}
void
add_use
(
int
use
)
{
use_points
.
push_front
(
use
);
}
int
get_begin
()
const
{
return
segment
.
begin
;
}
...
...
@@ -44,23 +42,14 @@ struct live_interval
bool
is_literal
;
};
// #define unique_interval_ptr std::unique_ptr<live_interval>
#define interval_ptr live_interval*
struct
memory_coloring_impl
{
memory_coloring_impl
()
{
init
();
}
memory_coloring_impl
(
program
*
p
)
:
p_program
(
p
)
memory_coloring_impl
(
program
*
p
)
:
p_program
(
p
)
{
init
();
}
void
init
(
)
{
init
();
}
~
memory_coloring_impl
()
{
for
(
int
i
=
0
;
i
<
num_of_lives
;
++
i
)
free
(
live_intervals
[
i
]);
}
void
init
()
{
instr2_live
.
clear
();
live_intervals
.
clear
();
live_ranges
.
clear
();
conflict_table
.
clear
();
num_of_lives
=
0
;
...
...
@@ -86,10 +75,6 @@ struct memory_coloring_impl
{
return
is_param
(
ins
)
&&
any_cast
<
builtin
::
param
>
(
ins
->
op
).
parameter
==
"output"
;
}
bool
is_scratch_param
(
const
instruction_ref
ins
)
{
return
is_param
(
ins
)
&&
any_cast
<
builtin
::
param
>
(
ins
->
op
).
parameter
==
"scratch"
;
}
bool
is_allocate
(
const
instruction_ref
ins
)
{
return
ins
->
op
.
name
()
==
"hip::allocate"
;
}
bool
is_outline
(
const
instruction_ref
ins
)
{
return
ins
->
op
.
name
()
==
"@outline"
;
}
bool
is_literal
(
const
instruction_ref
ins
)
{
return
ins
->
op
.
name
()
==
"@literal"
;
}
...
...
@@ -148,8 +133,8 @@ struct memory_coloring_impl
};
program
*
p_program
;
std
::
unordered_map
<
const
instruction
*
,
interval_ptr
>
instr2_live
;
//
Map live interval Id to
live interval.
std
::
unordered_map
<
int
,
interval
_ptr
>
live_intervals
;
//
universe of
live interval
s
.
std
::
vector
<
live_
interval
>
live_intervals
;
// Map live range value number to live range.
std
::
unordered_map
<
int
,
live_range
*>
live_ranges
;
// Map live range value number to a set of conflicting live ranges' value numbers.
...
...
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