Commit 4f06697d authored by Paul's avatar Paul
Browse files

Use operand alias in memory coloring

parent d71254c5
...@@ -6,7 +6,6 @@ void memory_coloring_impl::run() ...@@ -6,7 +6,6 @@ void memory_coloring_impl::run()
{ {
MIGRAPH_DEBUG(dump("---Before memory coloring---")); MIGRAPH_DEBUG(dump("---Before memory coloring---"));
MIGRAPH_DEBUG(dump_program()); MIGRAPH_DEBUG(dump_program());
register_operand_alias();
build(); build();
if(num_of_lives != 0) if(num_of_lives != 0)
{ {
...@@ -130,7 +129,6 @@ void memory_coloring_impl::build() ...@@ -130,7 +129,6 @@ void memory_coloring_impl::build()
{ {
is_dead = true; is_dead = true;
} }
int tie_ndx = get_input_tie_ndx(iter);
int cnt = -1; int cnt = -1;
for(auto&& arg : iter->inputs()) for(auto&& arg : iter->inputs())
{ {
...@@ -145,15 +143,8 @@ void memory_coloring_impl::build() ...@@ -145,15 +143,8 @@ void memory_coloring_impl::build()
} }
continue; continue;
} }
const instruction* p_arg = &(*arg); const instruction* p_arg = &(*instruction::get_output_alias(arg));
if(cnt == tie_ndx && (def_interval != nullptr)) if(instr2_live.find(p_arg) == instr2_live.end())
{
// input memory is used as this instruction's output.
// def is considered as use. Coalesce the live intervals.
def_interval->add_use(cur_points);
instr2_live[p_arg] = def_interval;
}
else if(instr2_live.find(p_arg) == instr2_live.end())
{ {
// First time see a use, create a live interval. // First time see a use, create a live interval.
int id = num_of_lives++; int id = num_of_lives++;
...@@ -183,24 +174,6 @@ void memory_coloring_impl::build() ...@@ -183,24 +174,6 @@ void memory_coloring_impl::build()
} while(iter != begin); } while(iter != begin);
} }
void memory_coloring_impl::register_operand_alias()
{
operand_alias["hip::allocate"] = -1;
operand_alias["hip::load_literal"] = -1;
operand_alias["@outline"] = -1;
operand_alias["check_context"] = -1;
operand_alias["@literal"] = -1;
operand_alias["@param"] = -1;
operand_alias["nop"] = -1;
operand_alias["transpose"] = 0;
operand_alias["flatten"] = 0;
operand_alias["broadcast"] = 0;
operand_alias["identity"] = 0;
operand_alias["reshape"] = 0;
operand_alias["pass"] = 0;
operand_alias["scalar"] = 0;
}
void memory_coloring_impl::rewrite() void memory_coloring_impl::rewrite()
{ {
std::vector<std::size_t> dims; std::vector<std::size_t> dims;
......
...@@ -59,7 +59,6 @@ struct memory_coloring_impl ...@@ -59,7 +59,6 @@ struct memory_coloring_impl
num_of_lives = 0; num_of_lives = 0;
max_value_number = -1; max_value_number = -1;
required_bytes = 0; required_bytes = 0;
operand_alias.clear();
earliest_end_point = -1; earliest_end_point = -1;
latest_end_point = -1; latest_end_point = -1;
unify_literals = false; unify_literals = false;
...@@ -75,7 +74,6 @@ struct memory_coloring_impl ...@@ -75,7 +74,6 @@ struct memory_coloring_impl
} }
void build(); void build();
void run(); void run();
void register_operand_alias();
void rewrite(); void rewrite();
private: private:
...@@ -92,30 +90,6 @@ struct memory_coloring_impl ...@@ -92,30 +90,6 @@ struct memory_coloring_impl
return ins->name() == "check_context"; return ins->name() == "check_context";
} }
// get operand alias info. This is a temporary workaround.
int get_input_tie_ndx(const instruction_ref ins)
{
std::string name = ins->name();
if(operand_alias.find(name) != operand_alias.end())
return operand_alias[name];
if(is_allocate(ins))
{
// This happens to custom allocators.
operand_alias[name] = -1;
return -1;
}
int cnt = -1;
int last_allocate = -1;
for(auto&& arg : ins->inputs())
{
cnt++;
if(is_allocate(arg) || is_output_param(arg))
last_allocate = cnt;
}
assert(last_allocate != -1);
operand_alias[name] = last_allocate;
return last_allocate;
}
static bool is_disjoin(live_range& range1, live_range& range2) static bool is_disjoin(live_range& range1, live_range& range2)
{ {
if((range1.size == 0) || (range2.size == 0)) if((range1.size == 0) || (range2.size == 0))
...@@ -164,7 +138,6 @@ struct memory_coloring_impl ...@@ -164,7 +138,6 @@ struct memory_coloring_impl
std::unordered_map<int, std::set<int>> conflict_table; std::unordered_map<int, std::set<int>> conflict_table;
// Priority queue for coloring. // Priority queue for coloring.
std::priority_queue<interval_ptr, std::vector<interval_ptr>, ordering> alloc_queue; std::priority_queue<interval_ptr, std::vector<interval_ptr>, ordering> alloc_queue;
std::unordered_map<std::string, int> operand_alias;
int num_of_lives; int num_of_lives;
int max_value_number; int max_value_number;
......
...@@ -281,7 +281,7 @@ void program::compile(const target& t, tracer trace) ...@@ -281,7 +281,7 @@ void program::compile(const target& t, tracer trace)
{ {
assert(this->validate() == impl->instructions.end()); assert(this->validate() == impl->instructions.end());
this->impl->ctx = t.get_context(); this->impl->ctx = t.get_context();
if(not trace.enabled() or enabled(MIGRAPH_TRACE_COMPILE{})) if(enabled(MIGRAPH_TRACE_COMPILE{}))
trace = tracer{std::cout}; trace = tracer{std::cout};
trace(*this); trace(*this);
trace(); trace();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment