def get_edge_constraints(self):
     # This allocator requires each edge to have keys of the form
     # |8 bits >= 0 and <= 7|8 bits >= 0 and <= 7|5 bits >= 0 and <= 17|
     # |11 remaining bits|
     # This is because this table was designed for a 48-chip board
     fields = [
         Field(0, 7, 0xFF000000),
         Field(0, 7, 0x00FF0000),
         Field(0, 17, 0x0000F800)]
     constraints = [
         FixedMaskConstraint(0xFFFFF800),
         FixedKeyFieldConstraint(fields)]
     return constraints
Example #2
0
def convert_mask_into_fields(entity):
    """

    :param entity:
    """
    results = list()
    expanded_mask = utility_calls.expand_to_bit_array(entity)

    # set up for first location
    detected_change_position = NUM_BITS_IN_ROUTING
    detected_last_state = expanded_mask[NUM_BITS_IN_ROUTING]

    # iterate up the key looking for fields
    for position in range(NUM_BITS_IN_ROUTING - 1,
                          START_OF_ROUTING_KEY_POSITION - 2, -1):
        # check for last bit iteration
        if position == -1:

            # if last bit has changed, create new field
            if detected_change_position != position:

                # create field with correct routing tag
                if detected_last_state == ROUTING_MASK_BIT:
                    tag = SUPPORTED_TAGS.ROUTING
                else:
                    tag = SUPPORTED_TAGS.APPLICATION
                results.append(
                    Field(NUM_BITS_IN_ROUTING - detected_change_position,
                          NUM_BITS_IN_ROUTING, entity, tag.name))
        else:

            # check for bit iteration
            if expanded_mask[position] != detected_last_state:

                # if changed state, a field needs to be created. check for
                # which type of field to support
                if detected_last_state == ROUTING_MASK_BIT:
                    tag = SUPPORTED_TAGS.ROUTING
                else:
                    tag = SUPPORTED_TAGS.APPLICATION
                results.append(
                    Field(NUM_BITS_IN_ROUTING - detected_change_position,
                          NUM_BITS_IN_ROUTING - (position + 1), entity,
                          tag.name))

                # update positions
                detected_last_state = expanded_mask[position]
                detected_change_position = position
    return results
Example #3
0
    def __init__(self, fixed_mask, fields, free_space_list):
        """
        :param int fixed_mask:
        :param fields:
        :type fields: list(Field) or None
        :param list(ElementFreeSpace) free_space_list:
        """

        self._fixed_mask = fixed_mask
        self._is_next_key = True
        self._free_space_list = free_space_list
        self._free_space_pos = 0
        self._next_key_read = False
        self._field_ones = dict()
        self._field_value = dict()

        expanded_mask = expand_to_bit_array(fixed_mask)
        zeros = numpy.where(expanded_mask == 0)[0]
        self._n_mask_keys = 2 ** len(zeros)

        # If there are no fields, add the mask as a field
        the_fields = fields
        if fields is None or not fields:
            n_ones = 32 - len(zeros)
            field_max = (2 ** n_ones) - 1
            the_fields = [Field(0, field_max, fixed_mask)]

        # Check that the fields don't cross each other
        for idx, field in enumerate(the_fields):
            for other_field in the_fields[idx+1:]:
                if field != other_field and field.mask & other_field.mask != 0:
                    raise PacmanRouteInfoAllocationException(
                        "Field masks {} and {} overlap".format(
                            field.mask, other_field.mask))

        # Sort the fields by highest bit range first
        self._fields = sorted(the_fields, key=lambda field: field.value,
                              reverse=True)

        self._update_next_valid_fields()
        self._increment_space_until_valid_key()
Example #4
0
 def test_fixed_key_field_constraint(self):
     c1 = FixedKeyFieldConstraint([Field(1, 2, 3, name="foo")])
     c1a = FixedKeyFieldConstraint([Field(1, 2, 3, name="foo")])
     c2 = FixedKeyFieldConstraint([Field(1, 2, 7)])
     c3 = FixedKeyFieldConstraint(
         [Field(1, 2, 3), Field(1, 2, 96),
          Field(1, 2, 12)])
     self.assertEqual(c1, c1a)
     self.assertNotEqual(c1, c2)
     self.assertNotEqual(c1, c3)
     self.assertNotEqual(c3, c1)
     r = ("FixedKeyFieldConstraint(fields=["
          "Field(lo=1, hi=2, value=3, tag=3, name=foo)])")
     self.assertEqual(str(c1), r)
     self.assertEqual([f.value for f in c3.fields], [96, 12, 3])
     d = {}
     d[c1] = 1
     d[c1a] = 2
     d[c2] = 3
     d[c3] = 4
     self.assertEqual(len(d), 3)
     self.assertEqual(d[c1], 2)