def compare_route(f, o_route, compressed_dict, o_code=None, start=0):
    if o_code is None:
        o_code = codify(o_route)
    keys = list(compressed_dict.keys())
    for i in range(start, len(keys)):
        c_code = keys[i]
        if covers(o_code, c_code):
            c_route = compressed_dict[c_code]
            f.write("\t\t{}\n".format(reports.format_route(c_route)))
            if o_route.defaultable != c_route.defaultable:
                raise PacmanRoutingException(
                    "Compressed route {} covers original route {} but has "
                    "a different defaultable value.".format(c_route, o_route))
            if o_route.processor_ids != c_route.processor_ids:
                raise PacmanRoutingException(
                    "Compressed route {} covers original route {} but has "
                    "a different processor_ids.".format(c_route, o_route))
            if o_route.link_ids != c_route.link_ids:
                raise PacmanRoutingException(
                    "Compressed route {} covers original route {} but has "
                    "a different link_ids.".format(c_route, o_route))
            remainders = calc_remainders(o_code, c_code)
            for remainder in remainders:
                compare_route(f, o_route, compressed_dict, o_code=remainder,
                              start=i + 1)
            return
        compare_route(f, o_route, compressed_dict, o_code=o_code, start=i+1)
        return
Exemplo n.º 2
0
def compare_route(f, o_route, compressed_dict, o_code=None, start=0):
    if o_code is None:
        o_code = codify(o_route)
    keys = list(compressed_dict.keys())
    for i in range(start, len(keys)):
        c_code = keys[i]
        if covers(o_code, c_code):
            c_route = compressed_dict[c_code]
            f.write("\t\t{}\n".format(reports.format_route(c_route)))
            if o_route.defaultable != c_route.defaultable:
                raise PacmanRoutingException(
                    "Compressed route {} covers original route {} but has "
                    "a different defaultable value.".format(c_route, o_route))
            if o_route.processor_ids != c_route.processor_ids:
                raise PacmanRoutingException(
                    "Compressed route {} covers original route {} but has "
                    "a different processor_ids.".format(c_route, o_route))
            if o_route.link_ids != c_route.link_ids:
                raise PacmanRoutingException(
                    "Compressed route {} covers original route {} but has "
                    "a different link_ids.".format(c_route, o_route))
            remainders = calc_remainders(o_code, c_code)
            for remainder in remainders:
                compare_route(f,
                              o_route,
                              compressed_dict,
                              o_code=remainder,
                              start=i + 1)
            return
        compare_route(f, o_route, compressed_dict, o_code=o_code, start=i + 1)
        return
def compare_route(o_route, compressed_dict, o_code=None, start=0, f=None):
    """
    :param ~spinn_machine.MulticastRoutingEntry o_route: the original route
    :param dict compressed_dict:
    :param str o_code:
    :param int start:
    :param ~io.FileIO f:
    :rtype: None
    """
    if o_code is None:
        o_code = codify(o_route)
    keys = list(compressed_dict.keys())
    for i in range(start, len(keys)):
        c_code = keys[i]
        if covers(o_code, c_code):
            c_route = compressed_dict[c_code]
            if f is not None:
                f.write("\t\t{}\n".format(reports.format_route(c_route)))
            if o_route.processor_ids != c_route.processor_ids:
                if set(o_route.processor_ids) != set(c_route.processor_ids):
                    raise PacmanRoutingException(
                        "Compressed route {} covers original route {} but has "
                        "a different processor_ids.".format(c_route, o_route))
            if o_route.link_ids != c_route.link_ids:
                if set(o_route.link_ids) != set(c_route.link_ids):
                    raise PacmanRoutingException(
                        "Compressed route {} covers original route {} but has "
                        "a different link_ids.".format(c_route, o_route))
            if not o_route.defaultable and c_route.defaultable:
                if o_route == c_route:
                    raise PacmanRoutingException(
                        "Compressed route {} while original route {} but has "
                        "a different defaultable value.".format(
                            c_route, o_route))
                else:
                    compare_route(o_route,
                                  compressed_dict,
                                  o_code=o_code,
                                  start=i + 1,
                                  f=f)
            else:
                remainders = calc_remainders(o_code, c_code)
                for remainder in remainders:
                    compare_route(o_route,
                                  compressed_dict,
                                  o_code=remainder,
                                  start=i + 1,
                                  f=f)
            return
    if not o_route.defaultable:
        # print("No route found {}".format(o_route))
        raise PacmanRoutingException("No route found {}".format(o_route))
Exemplo n.º 4
0
def generate_routing_compression_checker_report(report_folder, routing_tables,
                                                compressed_routing_tables):
    """ Make a full report of how the compressed covers all routes in the\
        and uncompressed routing table

    :param report_folder: the folder to store the resulting report
    :param routing_tables: the original routing tables
    :param compressed_routing_tables: the compressed routing tables
    :rtype: None
    """
    file_name = os.path.join(report_folder,
                             "routing_compression_checker_report.rpt")

    try:
        with open(file_name, "w") as f:
            progress = ProgressBar(
                routing_tables.routing_tables,
                "Generating routing compression checker report")

            f.write("If this table did not raise an exception compression "
                    "was fully checked. \n\n")
            f.write("The format is:\n"
                    "Chip x, y\n"
                    "\t Uncompressed Route\n"
                    "\t\tCompressed Route\n\n")

            for original in progress.over(routing_tables.routing_tables):
                x = original.x
                y = original.y
                f.write("Chip: X:{} Y:{} \n".format(x, y))

                compressed_table = compressed_routing_tables.\
                    get_routing_table_for_chip(x, y)
                compressed_dict = codify_table(compressed_table)
                for o_route in original.multicast_routing_entries:
                    f.write("\t{}\n".format(reports.format_route(o_route)))
                    compare_route(f, o_route, compressed_dict)
    except IOError:
        logger.exception(
            "Generate_router_comparison_reports: Can't open file"
            " {} for writing.", file_name)
def generate_routing_compression_checker_report(
        report_folder, routing_tables, compressed_routing_tables):
    """ Make a full report of how the compressed covers all routes in the\
        and uncompressed routing table

    :param report_folder: the folder to store the resulting report
    :param routing_tables: the original routing tables
    :param compressed_routing_tables: the compressed routing tables
    :rtype: None
    """
    file_name = os.path.join(
        report_folder, "routing_compression_checker_report.rpt")

    try:
        with open(file_name, "w") as f:
            progress = ProgressBar(
                routing_tables.routing_tables,
                "Generating routing compression checker report")

            f.write("If this table did not raise an exception compression "
                    "was fully checked. \n\n")
            f.write("The format is:\n"
                    "Chip x, y\n"
                    "\t Uncompressed Route\n"
                    "\t\tCompressed Route\n\n")

            for original in progress.over(routing_tables.routing_tables):
                x = original.x
                y = original.y
                f.write("Chip: X:{} Y:{} \n".format(x, y))

                compressed_table = compressed_routing_tables.\
                    get_routing_table_for_chip(x, y)
                compressed_dict = codify_table(compressed_table)
                for o_route in original.multicast_routing_entries:
                    f.write("\t{}\n".format(reports.format_route(o_route)))
                    compare_route(f, o_route, compressed_dict)
    except IOError:
        logger.exception("Generate_router_comparison_reports: Can't open file"
                         " {} for writing.", file_name)
Exemplo n.º 6
0
    def _create_table_report(self, router_table, sorted_bit_fields,
                             report_out):
        """ creates the report entry

        :param ~.AbsractMulticastRoutingTable router_table:
            the uncompressed router table to process
        :param list sorted_bit_fields: the bitfields overall
        :param ~io.TextIOBase report_out: the report writer
        """
        n_bit_fields_merged = 0
        n_packets_filtered = 0
        for key in self._best_bit_fields_by_processor.keys():
            best_bit_fields = self._best_bit_fields_by_processor[key]
            n_bit_fields_merged += len(best_bit_fields)
            for element in best_bit_fields:
                n_neurons = len(element.bit_field) * self._BITS_PER_WORD
                for neuron_id in range(0, n_neurons):
                    is_set = self._bit_for_neuron_id(element.bit_field,
                                                     neuron_id)
                    if is_set == 0:
                        n_packets_filtered += 1

        n_possible_bit_fields = len(sorted_bit_fields)

        percentage_done = 100
        if n_possible_bit_fields != 0:
            percentage_done = ((100.0 / float(n_possible_bit_fields)) *
                               float(n_bit_fields_merged))

        report_out.write(
            "Table{}:{} has integrated {} out of {} available chip level "
            "bitfields into the routing table. There by producing a "
            "compression of {}%.\n\n".format(router_table.x, router_table.y,
                                             n_bit_fields_merged,
                                             n_possible_bit_fields,
                                             percentage_done))

        report_out.write(
            "The uncompressed routing table had {} entries, the compressed "
            "one with {} integrated bitfields has {} entries. \n\n".format(
                router_table.number_of_entries,
                # Note: _best_routing_table is a list(), router_table is not
                len(self._best_routing_table),
                n_bit_fields_merged))

        report_out.write(
            "The integration of {} bitfields removes up to {} MC packets "
            "that otherwise would be being processed by the cores on the "
            "chip, just to be dropped as they do not target anything.".format(
                n_bit_fields_merged, n_packets_filtered))

        report_out.write("The bit_fields merged are as follows:\n\n")

        for key in self._best_bit_fields_by_processor.keys():
            for bf_by_processor in self._best_bit_fields_by_processor[key]:
                report_out.write("bitfield on core {} for key {} \n".format(
                    bf_by_processor.processor_id, key))

        report_out.write("\n\n\n")
        report_out.write("The final routing table entries are as follows:\n\n")

        report_out.write(
            "{: <5s} {: <10s} {: <10s} {: <10s} {: <7s} {}\n".format(
                "Index", "Key", "Mask", "Route", "Default", "[Cores][Links]"))
        report_out.write(
            "{:-<5s} {:-<10s} {:-<10s} {:-<10s} {:-<7s} {:-<14s}\n".format(
                "", "", "", "", "", ""))
        line_format = "{: >5d} {}\n"

        entry_count = 0
        n_defaultable = 0
        # Note: _best_routing_table is a list(), router_table is not
        for entry in self._best_routing_table:
            index = entry_count & self._LOWER_16_BITS
            entry_str = line_format.format(
                index, format_route(entry.to_MulticastRoutingEntry()))
            entry_count += 1
            if entry.defaultable:
                n_defaultable += 1
            report_out.write(entry_str)
        report_out.write("{} Defaultable entries\n".format(n_defaultable))