Permalink
Browse files

implementing random write

  • Loading branch information...
1 parent 801c613 commit 241d57b79a91b65310481875419c2e0ae046372f @hongsup hongsup committed Apr 10, 2012
View
@@ -104,6 +104,7 @@ SRCS2 =\
gps_syminfo.cc \
gm_gps_bb_find_reachable.cc\
gm_gps_java.cc gm_gps_lib.cc\
+ gm_gps_lib_random_write.cc\
# Object names: change .cc -> .o and add ./obj/ in front of it.
@@ -43,7 +43,7 @@ class gps_find_comm_vertex_bb: public gps_apply_bb_ast
if (gm_is_all_graph_iter_type(fe->get_iter_type())) return true;
- curr->set_has_sender(true);
+ //curr->set_has_sender(true);
gen->add_communication_unit_nested(fe); // adding inner loop
@@ -56,10 +56,10 @@ class gps_find_comm_vertex_bb: public gps_apply_bb_ast
}
else if (s->get_nodetype() == AST_ASSIGN)
{
- if (s->find_info_ptr(GPS_FLAG_SENT_SYMBOL_SB) != NULL)
+ if (s->find_info_ptr(GPS_FLAG_SENT_BLOCK_FOR_RANDOM_WRITE_ASSIGN) != NULL)
{
ast_assign* a = (ast_assign*) s;
- ast_sentblock* sb = (ast_sentblock*) (s->find_info_ptr(GPS_FLAG_SENT_SYMBOL_SB));
+ ast_sentblock* sb = (ast_sentblock*) (s->find_info_ptr(GPS_FLAG_SENT_BLOCK_FOR_RANDOM_WRITE_ASSIGN));
ast_field* f = a->get_lhs_field();
gm_symtab_entry* sym = f->get_first()->getSymInfo();
@@ -118,7 +118,7 @@ gps_bb* split_vertex_BB(gps_bb* BB, gm_gps_beinfo* gen)
//printf("splitting BB id = %d\n", BB->get_id());
assert(BB->is_vertex());
- assert(BB->has_sender());
+ //assert(BB->has_sender());
assert(BB->has_receiver());
assert(BB->get_num_entries() == 1);
assert(BB->get_num_exits() == 1);
@@ -24,6 +24,19 @@ void gm_gps_beinfo::add_communication_unit(gm_gps_comm_unit& C)
}
+gm_gps_communication_symbol_info* gm_gps_beinfo::find_communication_symbol_info(gm_gps_comm_unit& C, gm_symtab_entry* sym)
+{
+ assert(comm_symbol_info.find(C) != comm_symbol_info.end());
+ std::list<gm_gps_communication_symbol_info>& sym_info = comm_symbol_info[C];
+ std::list<gm_gps_communication_symbol_info>::iterator I;
+ for(I=sym_info.begin(); I!= sym_info.end();I++)
+ {
+ gm_gps_communication_symbol_info& S = *I;
+ if (S.symbol == sym) return &S; // found
+ }
+
+ return NULL;
+}
// Add a symbol to a communication loop
void gm_gps_beinfo::add_communication_symbol(gm_gps_comm_unit& C, gm_symtab_entry* sym)
@@ -144,7 +157,6 @@ gm_gps_congruent_msg_class*
new gm_gps_congruent_msg_class();
C->id = congruent_msg.size();
C->sz_info = sz;
- printf("adding bb %p to class %p\n", bb, C);
C->add_receiving_basic_block(bb);
congruent_msg.push_back(C);
@@ -327,7 +327,9 @@ class gps_check_random_write_t2 : public gm_apply
}
used.insert(e);
- s->add_info_ptr(GPS_FLAG_SENT_SYMBOL_SB, sb);
+ s->add_info_ptr(GPS_FLAG_SENT_BLOCK_FOR_RANDOM_WRITE_ASSIGN, sb);
+ sb->add_info_set_element(GPS_FLAG_RANDOM_WRITE_SYMBOLS_FOR_SB, e);
+
}
}
}
@@ -294,17 +294,17 @@ void gm_gps_gen::do_generate_vertex_state_body(gm_gps_basic_block *b)
std::list<gm_gps_comm_unit>& R = b->get_receivers();
std::list<gm_gps_comm_unit>::iterator I;
- //if (R.size() != 1) {
- gm_baseindent_reproduce(4);
- //}
for(I=R.begin(); I!=R.end(); I++)
{
gm_gps_comm_unit U = *I;
if (U.get_type() == GPS_COMM_NESTED) {
ast_foreach* fe = U.fe;
+ assert(fe!=NULL);
Body.pushln("/*------");
+ Body.pushln("(Nested Loop)");
Body.flush();
+ gm_baseindent_reproduce(4);
fe->reproduce(0);
gm_flush_reproduce();
Body.pushln("-----*/");
@@ -316,9 +316,36 @@ void gm_gps_gen::do_generate_vertex_state_body(gm_gps_basic_block *b)
generate_sent(fe->get_body());
}
- get_lib()->generate_message_receive_end( fe, Body, R.size()==1);
+ get_lib()->generate_message_receive_end(Body, R.size()==1);
} else {
- assert(false);
+ ast_sentblock* sb = U.sb;
+ assert(sb!=NULL);
+ Body.pushln("/*------");
+ Body.pushln("(Random Write)");
+ Body.pushln("{");
+ Body.flush();
+ gm_baseindent_reproduce(5);
+ std::list<ast_sent*>& sents = sb->get_sents();
+ std::list<ast_sent*>::iterator I;
+ for(I=sents.begin(); I!=sents.end();I++) {
+ ast_sent* s = *I;
+ if (s->find_info_ptr(GPS_FLAG_SENT_BLOCK_FOR_RANDOM_WRITE_ASSIGN) == sb)
+ s->reproduce(0);
+ }
+ gm_flush_reproduce();
+ Body.pushln("}");
+ Body.pushln("-----*/");
+ get_lib()->generate_message_receive_begin( sb, U.sym, Body, b, R.size()==1);
+
+ for(I=sents.begin(); I!=sents.end();I++) {
+ ast_sent* s = *I;
+ if (s->find_info_ptr(GPS_FLAG_SENT_BLOCK_FOR_RANDOM_WRITE_ASSIGN) == sb) {
+ // implement receiving sentence
+ generate_sent(s);
+ }
+ }
+
+ get_lib()->generate_message_receive_end(Body, R.size()==1);
}
}
set_receiver_generate(false);
@@ -35,6 +35,50 @@ const char* gm_gps_gen::get_type_string(ast_typedecl* T, bool is_master)
return "???";
}
+void gm_gps_gen::generate_sent_block(ast_sentblock* sb, bool need_brace)
+{
+ std::list<ast_sent*> &sents = sb->get_sents();
+
+ std::list<ast_sent*>::iterator i;
+ if (need_brace) _Body.pushln("{") ;
+ if (sb->has_info_set(GPS_FLAG_RANDOM_WRITE_SYMBOLS_FOR_SB))
+ {
+ std::set<void*> S = sb->get_info_set(GPS_FLAG_RANDOM_WRITE_SYMBOLS_FOR_SB);
+ std::set<void*>::iterator I;
+ for(I=S.begin(); I!=S.end(); I++)
+ {
+ gm_symtab_entry* sym = (gm_symtab_entry*) *I;
+ get_lib()->generate_message_create_for_random_write(
+ sb, sym, Body);
+ }
+ Body.NL();
+ }
+
+ for(i=sents.begin(); i!=sents.end(); i++)
+ {
+ ast_sent* s = *i;
+ generate_sent(s);
+ }
+
+ if (sb->has_info_set(GPS_FLAG_RANDOM_WRITE_SYMBOLS_FOR_SB))
+ {
+ Body.NL();
+
+ std::set<void*> S = sb->get_info_set(GPS_FLAG_RANDOM_WRITE_SYMBOLS_FOR_SB);
+ std::set<void*>::iterator I;
+ for(I=S.begin(); I!=S.end(); I++)
+ {
+ gm_symtab_entry* sym = (gm_symtab_entry*) *I;
+ get_lib()->generate_message_send_for_random_write(
+ sb, sym, Body);
+ }
+ }
+
+ if (need_brace) _Body.pushln("}") ;
+
+
+}
+
void gm_gps_gen::generate_expr_nil(ast_expr* e)
{
get_lib()->generate_expr_nil(e, Body);
@@ -85,7 +129,8 @@ void gm_gps_gen::generate_rhs_id(ast_id* i)
{
if (i->getSymInfo()->getType()->is_node_iterator())
{
- if (i->getSymInfo()->find_info_bool(GPS_FLAG_SENT_SYMBOL) && !this->is_receiver_generate()) {
+ if (i->getSymInfo()->find_info_bool(GPS_FLAG_COMM_SYMBOL) &&
+ !this->is_receiver_generate()) {
get_lib()->generate_node_iterator_rhs(i, Body);
}
else {
@@ -107,9 +152,21 @@ void gm_gps_gen::generate_sent_reduce_assign(ast_assign* a)
{
if (is_master_generate())
{
+ // [to be done]
assert(false);
}
- else if (a->is_target_scalar())
+
+ if (a->find_info_ptr(GPS_FLAG_SENT_BLOCK_FOR_RANDOM_WRITE_ASSIGN) != NULL)
+ {
+ if (!is_receiver_generate())
+ {
+ // generate random write messaging
+ get_lib()->generate_message_payload_packing_for_random_write(a, Body);
+ return ;
+ }
+ }
+
+ if (a->is_target_scalar())
{
// check target is global
{
@@ -228,16 +285,28 @@ void gm_gps_gen::generate_sent_assign(ast_assign *a)
// normal assign
if (is_master_generate()) {
this->gm_code_generator::generate_sent_assign(a);
+ return;
}
- else if (a->is_target_scalar())
+
+ // vertex or receiver generate
+ if (a->find_info_ptr(GPS_FLAG_SENT_BLOCK_FOR_RANDOM_WRITE_ASSIGN) != NULL)
+ {
+ if (!is_receiver_generate())
+ {
+ // generate random write messaging
+ get_lib()->generate_message_payload_packing_for_random_write(a, Body);
+ return ;
+ }
+ }
+
+ if (a->is_target_scalar())
{
ast_id* i = a->get_lhs_scala();
gps_syminfo* syminfo = (gps_syminfo*)
i->getSymInfo()->find_info(TAG_BB_USAGE);
// normal assign
- //if ((syminfo == NULL) || (!syminfo->is_used_in_multiple_BB()))
if (!syminfo->is_scoped_global())
{
this->gm_code_generator::generate_sent_assign(a);
@@ -246,18 +315,15 @@ void gm_gps_gen::generate_sent_assign(ast_assign *a)
else {
// write to global scalar
- // to be done
- printf("error: %s\n", i->get_genname());
+ // [TO BE DONE]
+ printf("need to implement: %s\n", i->get_genname());
assert(false);
}
}
else
{
ast_field* f = a->get_lhs_field();
- // temporary
- //assert(f->getSourceTypeSummary() == GMTYPE_NODEITER_ALL);
-
this->gm_code_generator::generate_sent_assign(a);
}
}
@@ -103,7 +103,6 @@ void gm_gpslib::generate_broadcast_variable_type(
//---------------------------------------------------
// Type: Long, Int, Double, Float, Bool
//---------------------------------------------------
- printf("type = %s\n", gm_get_type_string(type_id));
if (gm_is_node_compatible_type(type_id))
type_id = GMTYPE_NODE;
@@ -710,20 +709,26 @@ static bool is_symbol_defined_in_bb(gm_gps_basic_block* b, gm_symtab_entry *e)
else return true;
}
-void gm_gpslib::generate_message_receive_begin(ast_foreach* fe, gm_code_writer& Body, gm_gps_basic_block *b, bool is_only_comm)
+void gm_gpslib::generate_message_receive_begin(ast_foreach* fe, gm_code_writer& Body, gm_gps_basic_block* b, bool is_only_comm)
+{
+ gm_gps_beinfo * info = (gm_gps_beinfo *) FE.get_current_backend_info();
+ int comm_type = (fe == NULL) ? GPS_COMM_INIT : GPS_COMM_NESTED;
+ gm_gps_comm_unit U(comm_type, fe);
+ generate_message_receive_begin(U, Body, b, is_only_comm);
+}
+void gm_gpslib::generate_message_receive_begin(ast_sentblock* sb, gm_symtab_entry* drv, gm_code_writer& Body, gm_gps_basic_block* b, bool is_only_comm)
+{
+ gm_gps_beinfo * info = (gm_gps_beinfo *) FE.get_current_backend_info();
+ int comm_type = GPS_COMM_RANDOM_WRITE;
+ gm_gps_comm_unit U(comm_type, sb, drv);
+ generate_message_receive_begin(U, Body, b, is_only_comm);
+}
+
+void gm_gpslib::generate_message_receive_begin(gm_gps_comm_unit& U, gm_code_writer& Body, gm_gps_basic_block *b, bool is_only_comm)
{
gm_gps_beinfo * info =
(gm_gps_beinfo *) FE.get_current_backend_info();
- int comm_type;
- if (fe == NULL)
- comm_type = GPS_COMM_INIT;
- else
- comm_type = GPS_COMM_NESTED;
-
- gm_gps_comm_unit U(comm_type, fe);
-
-
std::list<gm_gps_communication_symbol_info>& LIST = info->get_all_communication_symbols(U);
//int comm_id = info->find_communication_size_info(fe).id;
int comm_id = (info->find_communication_size_info(U))->msg_class->id;
@@ -762,7 +767,7 @@ void gm_gpslib::generate_message_receive_begin(ast_foreach* fe, gm_code_writer&
}
}
-void gm_gpslib::generate_message_receive_end(ast_foreach* fe, gm_code_writer& Body, bool is_only_comm)
+void gm_gpslib::generate_message_receive_end(gm_code_writer& Body, bool is_only_comm)
{
if (!is_only_comm) {
Body.pushln("}");
@@ -841,7 +846,7 @@ void gm_gpslib::generate_prepare_bb(
generate_message_receive_begin(NULL, Body, bb, true);
sprintf(temp,"%s.%s[i] = %s;", STATE_SHORT_CUT, GPS_REV_NODE_ID, GPS_DUMMY_ID);
Body.pushln(temp);
- generate_message_receive_end(NULL, Body, true);
+ generate_message_receive_end(Body, true);
Body.pushln("i++;");
Body.pushln("}");
}
Oops, something went wrong.

0 comments on commit 241d57b

Please sign in to comment.