Example #1
0
def write_phase1_gather_preinit(builder, tr, inscription):
    t = parser.parse_typename(inscription.type, inscription.source)
    typename = t[1][0] # This should not failed, because check already verify this
    builder.line("const size_t $size = sizeof({0});", typename)
    builder.line("Tokens_{0.id} *$rbinding = static_cast<Tokens_{0.id}*>($bindings[$root]);", tr)
    builder.line("$rbinding->token_collective = new ca::Token<{0.type} >;", inscription)
    builder.line("$rbinding->token_collective->value.resize($thread->get_process_count());")
Example #2
0
def write_gather_nonroot(builder, tr, inscription):
    t = parser.parse_typename(inscription.type, inscription.source)
    typename = t[1][0] # This should not failed, because check already verify this
    builder.if_begin("ca::is_trivially_packable<{0} >()", typename)
    # Trivially packable
    builder.line("$thread->collective_gather_nonroot({0.id}, $root, &{1.expr}, sizeof({2}));",
                 tr, inscription, typename)
    builder.else_if("ca::fixed_size<{0} >() != 0", typename)
    # Fixed size
    write_pack_fixed_size(builder, typename, inscription.expr)
    builder.line("$thread->collective_gather_nonroot({0.id}, $root, $packer.get_buffer(), $size);",
                 tr, inscription, typename)
    builder.line("$packer.free();")
    builder.write_else()
    # Generic case
    builder.line("ca::Packer $packer;")
    builder.line("$packer << {0};", inscription.expr)
    builder.line("int $size = $packer.get_size();")
    builder.line("$thread->collective_gather_nonroot"
                 "({0.id}, $root, &$size, sizeof(int));", tr)
    #builder.line("fprintf(stderr, \"%i %i\\n\", $thread->get_process_id(), size)");
    builder.line("$thread->collective_gatherv_nonroot"
                 "({0.id}, $root, $packer.get_buffer(), $packer.get_size());",
                 tr, inscription, typename)
    builder.line("$packer.free();")
    builder.block_end()
Example #3
0
def write_allgather(builder, tr, inscription):
    t = parser.parse_typename(inscription.type, inscription.source)
    typename = t[1][0] # This should not failed, because check already verify this
    builder.line("ca::Token<std::vector<{0} > > *$token = new ca::Token<std::vector<{0} > >;",
                 typename)

    builder.if_begin("ca::is_trivially_packable<{0} >()", typename)
    # Trivially packable
    builder.line("const size_t $size = sizeof({0});", typename)
    builder.line("$token->value.resize($thread->get_process_count());")
    builder.line("$thread->collective_allgather({0.id}, &{1.expr}, $size, &$token->value[0]);",
                 tr, inscription)
    builder.else_if("ca::fixed_size<{0} >() != 0", typename)
    # Fixed size
    write_pack_fixed_size(builder, typename, inscription.expr)
    builder.line("void *$mem = malloc($size * $thread->get_process_count());")
    builder.line("$thread->collective_allgather({0.id}, $packer.get_buffer(), $size, $mem);",
                 tr, inscription)
    builder.line("$packer.free();")
    builder.line("ca::Unpacker $unpacker($mem, $size * $thread->get_process_count());")
    builder.line("ca::unpack_with_step($unpacker,"
                 "$token->value, $size, $thread->get_process_count());")

    builder.line("free($mem);")
    builder.write_else()
    # Generic case
    builder.line("int $process_count = $thread->get_process_count();")
    builder.line("int *$sizes = static_cast<int*>(alloca(sizeof(int) * $process_count));")
    builder.line("int *$displs = static_cast<int*>(alloca(sizeof(int) * (1 + $process_count)));")
    builder.line("int $size = 0;")
    builder.line("$thread->collective_allgather({0.id}, &$size, sizeof(int), $sizes);", tr)
    builder.line("$displs[0] = 0;")
    # Last displs[process_count] == sum of all sizes
    builder.for_begin("int $i = 0; $i < ca::process_count; $i++")
    builder.line("$displs[$i + 1] = $displs[$i] + $sizes[$i];")
    builder.block_end()
    builder.line("void *$mem = malloc($displs[$process_count]);")
    builder.line("$thread->collective_allgatherv({0.id}, &$size, 0, $mem, $sizes, $displs);", tr)
    builder.line("ca::Unpacker $unpacker($mem, $displs[$process_count]);")
    builder.line("int $process_id = $thread->get_process_id();")
    builder.line("ca::unpack_with_displs($unpacker, $token->value, $process_id, $displs);")
    builder.line("$token->value.push_back({0});", inscription.expr);
    builder.line("ca::unpack_with_displs"
                 "($unpacker, $token->value, $process_count - $process_id - 1,"
                             "$displs + $process_id + 1);")
    builder.line("free($mem);")
    builder.block_end()

    buildnet.write_place_add(builder,
                    inscription.edge.place,
                    builder.expand("$n->"),
                    builder.expand("$token"),
                    bulk=False,
                    token=True)
    buildnet.write_activation(builder,
                              builder.expand("$n"),
                              inscription.edge.place.get_transitions_out())
Example #4
0
 def parse_typename(self, string, source):
     return parser.parse_typename(string, source)
Example #5
0
 def parse_typename(self, string, source):
     return parser.parse_typename(string, source)