Пример #1
0
 def test_board_constraint(self):
     c1 = BoardConstraint("1.2.3.4")
     self.assertEqual(c1.board_address, "1.2.3.4")
     self.assertEqual(c1, BoardConstraint("1.2.3.4"))
     self.assertEqual(str(c1), 'BoardConstraint(board_address="1.2.3.4")')
     c2 = BoardConstraint("4.3.2.1")
     self.assertNotEqual(c1, c2)
     self.assertNotEqual(c1, "1.2.3.4")
     d = {}
     d[c1] = 1
     d[c2] = 2
     self.assertEqual(len(d), 2)
Пример #2
0
def constraint_from_json(json_dict, graph=None):
    if json_dict["class"] == "BoardConstraint":
        return BoardConstraint(json_dict["board_address"])
    if json_dict["class"] == "ChipAndCoreConstraint":
        if "p" in json_dict:
            p = json_dict["p"]
        else:
            p = None
        return ChipAndCoreConstraint(json_dict["x"], json_dict["y"], p)
    if json_dict["class"] == "ContiguousKeyRangeContraint":
        return ContiguousKeyRangeContraint()
    if json_dict["class"] == "FixedKeyAndMaskConstraint":
        if "key_list_function" in json_dict:
            raise NotImplementedError("key_list_function {}".format(
                json_dict["key_list_function"]))
        return FixedKeyAndMaskConstraint(
            key_masks_from_json(json_dict["keys_and_masks"]))
    if json_dict["class"] == "FixedMaskConstraint":
        return FixedMaskConstraint(json_dict["mask"])
    if json_dict["class"] == "FixedVertexAtomsConstraint":
        return FixedVertexAtomsConstraint(json_dict["size"])
    if json_dict["class"] == "MaxVertexAtomsConstraint":
        return MaxVertexAtomsConstraint(json_dict["size"])
    if json_dict["class"] == "RadialPlacementFromChipConstraint":
        return RadialPlacementFromChipConstraint(json_dict["x"],
                                                 json_dict["y"])
    if json_dict["class"] == "SameChipAsConstraint":
        return SameChipAsConstraint(vertex_lookup(json_dict["vertex"], graph))
    if json_dict["class"] == "SameAtomsAsVertexConstraint":
        return SameAtomsAsVertexConstraint(
            vertex_lookup(json_dict["vertex"], graph))
    raise NotImplementedError("constraint {}".format(json_dict["class"]))
Пример #3
0
 def test_vertex2(self):
     """Like test_vertex, but with constraints."""
     c1 = ContiguousKeyRangeContraint()
     c2 = BoardConstraint("1.2.3.4")
     s1 = SimpleMachineVertex(ResourceContainer(
         iptags=[IPtagResource("127.0.0.1", port=None, strip_sdp=True)]),
                              label="Vertex",
                              constraints=[c1, c2])
     self.vertex_there_and_back(s1)
    def _install_send_buffer(self, n_keys, send_buffer_times, target_address):
        if (len(send_buffer_times) and
                hasattr(send_buffer_times[0], "__len__")):
            # Working with a list of lists so check length
            if len(send_buffer_times) != n_keys:
                raise ConfigurationException(
                    "The array or arrays of times {} does not have the "
                    "expected length of {}".format(send_buffer_times, n_keys))

        self._send_buffer = BufferedSendingRegion(self._send_buffer_max_space)
        self._send_buffer_times = send_buffer_times

        (ip_address, port, tag, board_address) = target_address
        self._iptags = [IPtagResource(
            ip_address=ip_address, port=port, strip_sdp=True, tag=tag,
            traffic_identifier=TRAFFIC_IDENTIFIER)]
        if board_address is not None:
            self.add_constraint(BoardConstraint(board_address))
        self._send_buffers = {
            self._REGIONS.SEND_BUFFER.value:
            self._send_buffer
        }
Пример #5
0
 def test_board_constraint(self):
     c1 = BoardConstraint("1.2.3.4")
     self.constraint_there_and_back(c1)
Пример #6
0
    def __init__(
        self,
        n_keys,
        label=None,
        constraints=None,
        max_atoms_per_core=sys.maxsize,

        # General parameters
        board_address=None,

        # Live input parameters
        receive_port=None,
        receive_sdp_port=(constants.SDP_PORTS.INPUT_BUFFERING_SDP_PORT.value),
        receive_tag=None,
        receive_rate=10,

        # Key parameters
        virtual_key=None,
        prefix=None,
        prefix_type=None,
        check_keys=False,

        # Send buffer parameters
        send_buffer_times=None,
        send_buffer_partition_id=None,
        send_buffer_max_space=(constants.MAX_SIZE_OF_BUFFERED_REGION_ON_CHIP),
        send_buffer_space_before_notify=640,

        # Buffer parameters
        buffer_notification_ip_address=None,
        buffer_notification_port=None,
        buffer_notification_tag=None,

        # Extra flag for input without a reserved port
        reserve_reverse_ip_tag=False):
        """
        :param n_keys: The number of keys to be sent via this multicast source
        :param label: The label of this vertex
        :param constraints: Any initial constraints to this vertex
        :param board_address: The IP address of the board on which to place\
            this vertex if receiving data, either buffered or live (by\
            default, any board is chosen)
        :param receive_port: The port on the board that will listen for\
            incoming event packets (default is to disable this feature; set a\
            value to enable it)
        :param receive_sdp_port: The SDP port to listen on for incoming event\
            packets (defaults to 1)
        :param receive_tag: The IP tag to use for receiving live events\
            (uses any by default)
        :param receive_rate: The estimated rate of packets that will be sent\
            by this source
        :param virtual_key: The base multicast key to send received events\
            with (assigned automatically by default)
        :param prefix: The prefix to "or" with generated multicast keys\
            (default is no prefix)
        :param prefix_type: Whether the prefix should apply to the upper or\
            lower half of the multicast keys (default is upper half)
        :param check_keys: True if the keys of received events should be\
            verified before sending (default False)
        :param send_buffer_times: An array of arrays of times at which keys\
            should be sent (one array for each key, default disabled)
        :param send_buffer_partition_id: The ID of the partition containing\
            the edges down which the events are to be sent
        :param send_buffer_max_space: The maximum amount of space to use of\
            the SDRAM on the machine (default is 1MB)
        :param send_buffer_space_before_notify: The amount of space free in\
            the sending buffer before the machine will ask the host for more\
            data (default setting is optimised for most cases)
        :param buffer_notification_ip_address: The IP address of the host\
            that will send new buffers (must be specified if a send buffer is\
            specified or if recording will be used)
        :param buffer_notification_port: The port that the host that will\
            send new buffers is listening on (must be specified if a send\
            buffer is specified, or if recording will be used)
        :param buffer_notification_tag: The IP tag to use to notify the\
            host about space in the buffer (default is to use any tag)
        """
        # pylint: disable=too-many-arguments, too-many-locals
        super(ReverseIpTagMultiCastSource,
              self).__init__(label, constraints, max_atoms_per_core)

        # basic items
        self._n_atoms = n_keys

        # Store the parameters for EIEIO
        self._board_address = board_address
        self._receive_port = receive_port
        self._receive_sdp_port = receive_sdp_port
        self._receive_tag = receive_tag
        self._receive_rate = receive_rate
        self._virtual_key = virtual_key
        self._prefix = prefix
        self._prefix_type = prefix_type
        self._check_keys = check_keys

        self._reverse_iptags = None
        if receive_port is not None or reserve_reverse_ip_tag:
            self._reverse_iptags = [
                ReverseIPtagResource(port=receive_port,
                                     sdp_port=receive_sdp_port,
                                     tag=receive_tag)
            ]
            if board_address is not None:
                self.add_constraint(BoardConstraint(board_address))

        # Store the send buffering details
        self._send_buffer_times = send_buffer_times
        self._send_buffer_partition_id = send_buffer_partition_id
        self._send_buffer_max_space = send_buffer_max_space
        self._send_buffer_space_before_notify = send_buffer_space_before_notify

        # Store the buffering details
        self._buffer_notification_ip_address = buffer_notification_ip_address
        self._buffer_notification_port = buffer_notification_port
        self._buffer_notification_tag = buffer_notification_tag
        self._reserve_reverse_ip_tag = reserve_reverse_ip_tag

        self._iptags = None
        if send_buffer_times is not None:
            self._iptags = [
                IPtagResource(buffer_notification_ip_address,
                              buffer_notification_port, True,
                              buffer_notification_tag)
            ]
            if board_address is not None:
                self.add_constraint(BoardConstraint(board_address))

        # Store recording parameters
        self._record_buffer_size = 0
        self._record_buffer_size_before_receive = 0
        self._record_time_between_requests = 0

        # Keep the vertices for resuming runs
        self._machine_vertices = list()
    def __init__(
        self,
        n_keys,
        label,
        constraints=None,

        # General input and output parameters
        board_address=None,

        # Live input parameters
        receive_port=None,
        receive_sdp_port=(constants.SDP_PORTS.INPUT_BUFFERING_SDP_PORT.value),
        receive_tag=None,
        receive_rate=10,

        # Key parameters
        virtual_key=None,
        prefix=None,
        prefix_type=None,
        check_keys=False,

        # Send buffer parameters
        send_buffer_times=None,
        send_buffer_partition_id=None,
        send_buffer_max_space=(constants.MAX_SIZE_OF_BUFFERED_REGION_ON_CHIP),
        send_buffer_space_before_notify=640,

        # Buffer notification details
        buffer_notification_ip_address=None,
        buffer_notification_port=None,
        buffer_notification_tag=None,

        # Extra flag for receiving packets without a port
        reserve_reverse_ip_tag=False):
        """

        :param n_keys: The number of keys to be sent via this multicast source
        :param label: The label of this vertex
        :param constraints: Any initial constraints to this vertex
        :param board_address: The IP address of the board on which to place\
                this vertex if receiving data, either buffered or live (by\
                default, any board is chosen)
        :param receive_port: The port on the board that will listen for\
                incoming event packets (default is to disable this feature;\
                set a value to enable it)
        :param receive_sdp_port: The SDP port to listen on for incoming event\
                packets (defaults to 1)
        :param receive_tag: The IP tag to use for receiving live events\
                (uses any by default)
        :param virtual_key: The base multicast key to send received events\
                with (assigned automatically by default)
        :param prefix: The prefix to "or" with generated multicast keys\
                (default is no prefix)
        :param prefix_type: Whether the prefix should apply to the upper or\
                lower half of the multicast keys (default is upper half)
        :param check_keys: True if the keys of received events should be\
                verified before sending (default False)
        :param send_buffer_times: An array of arrays of times at which keys\
                should be sent (one array for each key, default disabled)
        :param send_buffer_max_space: The maximum amount of space to use of\
                the SDRAM on the machine (default is 1MB)
        :param send_buffer_space_before_notify: The amount of space free in\
                the sending buffer before the machine will ask the host for\
                more data (default setting is optimised for most cases)
        :param buffer_notification_ip_address: The IP address of the host\
                that will send new buffers (must be specified if a send buffer\
                is specified)
        :param buffer_notification_port: The port that the host that will\
                send new buffers is listening on (must be specified if a\
                send buffer is specified)
        :param buffer_notification_tag: The IP tag to use to notify the\
                host about space in the buffer (default is to use any tag)
        """
        MachineVertex.__init__(self, label, constraints)
        AbstractReceiveBuffersToHost.__init__(self)

        AbstractProvidesOutgoingPartitionConstraints.__init__(self)

        self._iptags = None
        self._reverse_iptags = None

        # Set up for receiving live packets
        if receive_port is not None or reserve_reverse_ip_tag:
            self._reverse_iptags = [
                ReverseIPtagResource(port=receive_port,
                                     sdp_port=receive_sdp_port,
                                     tag=receive_tag)
            ]
            if board_address is not None:
                self.add_constraint(BoardConstraint(board_address))
        self._receive_rate = receive_rate
        self._receive_sdp_port = receive_sdp_port

        # Work out if buffers are being sent
        self._send_buffer = None
        self._send_buffer_partition_id = send_buffer_partition_id
        if send_buffer_times is None:
            self._send_buffer_times = None
            self._send_buffer_max_space = send_buffer_max_space
            self._send_buffers = None
        else:
            self._send_buffer_max_space = send_buffer_max_space
            self._send_buffer = BufferedSendingRegion(send_buffer_max_space)
            self._send_buffer_times = send_buffer_times

            self._iptags = [
                IPtagResource(ip_address=buffer_notification_ip_address,
                              port=buffer_notification_port,
                              strip_sdp=True,
                              tag=buffer_notification_tag,
                              traffic_identifier=TRAFFIC_IDENTIFIER)
            ]
            if board_address is not None:
                self.add_constraint(BoardConstraint(board_address))
            self._send_buffers = {
                self._REGIONS.SEND_BUFFER.value: self._send_buffer
            }

        # buffered out parameters
        self._send_buffer_space_before_notify = send_buffer_space_before_notify
        if self._send_buffer_space_before_notify > send_buffer_max_space:
            self._send_buffer_space_before_notify = send_buffer_max_space

        # Set up for recording (if requested)
        self._record_buffer_size = 0
        self._buffer_size_before_receive = 0
        self._time_between_triggers = 0
        self._maximum_recording_buffer = 0

        # Set up for buffering
        self._buffer_notification_ip_address = buffer_notification_ip_address
        self._buffer_notification_port = buffer_notification_port
        self._buffer_notification_tag = buffer_notification_tag

        # set flag for checking if in injection mode
        self._in_injection_mode = receive_port is not None

        # Sort out the keys to be used
        self._n_keys = n_keys
        self._virtual_key = virtual_key
        self._mask = None
        self._prefix = prefix
        self._prefix_type = prefix_type
        self._check_keys = check_keys

        # Work out the prefix details
        if self._prefix is not None:
            if self._prefix_type is None:
                self._prefix_type = EIEIOPrefix.UPPER_HALF_WORD
            if self._prefix_type == EIEIOPrefix.UPPER_HALF_WORD:
                self._prefix = prefix << 16

        # If the user has specified a virtual key
        if self._virtual_key is not None:

            # check that virtual key is valid
            if self._virtual_key < 0:
                raise ConfigurationException("Virtual keys must be positive")

            # Get a mask and maximum number of keys for the number of keys
            # requested
            self._mask, max_key = self._calculate_mask(n_keys)

            # Check that the number of keys and the virtual key don't interfere
            if n_keys > max_key:
                raise ConfigurationException(
                    "The mask calculated from the number of keys will "
                    "not work with the virtual key specified")

            if self._prefix is not None:

                # Check that the prefix doesn't change the virtual key in the
                # masked area
                masked_key = (self._virtual_key | self._prefix) & self._mask
                if self._virtual_key != masked_key:
                    raise ConfigurationException(
                        "The number of keys, virtual key and key prefix"
                        " settings don't work together")
            else:

                # If no prefix was generated, generate one
                self._prefix_type = EIEIOPrefix.UPPER_HALF_WORD
                self._prefix = self._virtual_key
    def __init__(
            self, n_keys, label, constraints=None,

            # General input and output parameters
            board_address=None,

            # Live input parameters
            receive_port=None,
            receive_sdp_port=(
                constants.SDP_PORTS.INPUT_BUFFERING_SDP_PORT.value),
            receive_tag=None,
            receive_rate=10,

            # Key parameters
            virtual_key=None, prefix=None,
            prefix_type=None, check_keys=False,

            # Send buffer parameters
            send_buffer_times=None,
            send_buffer_partition_id=None,
            send_buffer_max_space=(
                constants.MAX_SIZE_OF_BUFFERED_REGION_ON_CHIP),
            send_buffer_space_before_notify=640,

            # Buffer notification details
            buffer_notification_ip_address=None,
            buffer_notification_port=None,
            buffer_notification_tag=None,

            # Extra flag for receiving packets without a port
            reserve_reverse_ip_tag=False):
        """
        :param n_keys: The number of keys to be sent via this multicast source
        :param label: The label of this vertex
        :param constraints: Any initial constraints to this vertex
        :param board_address: The IP address of the board on which to place\
            this vertex if receiving data, either buffered or live (by\
            default, any board is chosen)
        :param receive_port: The port on the board that will listen for\
            incoming event packets (default is to disable this feature; set a\
            value to enable it, or set the reserve_reverse_ip_tag parameter\
            to True if a random port is to be used)
        :param receive_sdp_port: The SDP port to listen on for incoming event\
            packets (defaults to 1)
        :param receive_tag: The IP tag to use for receiving live events\
            (uses any by default)
        :param virtual_key: The base multicast key to send received events\
            with (assigned automatically by default)
        :param prefix: The prefix to "or" with generated multicast keys\
            (default is no prefix)
        :param prefix_type: Whether the prefix should apply to the upper or\
            lower half of the multicast keys (default is upper half)
        :param check_keys: True if the keys of received events should be\
            verified before sending (default False)
        :param send_buffer_times: An array of arrays of times at which keys\
            should be sent (one array for each key, default disabled)
        :param send_buffer_max_space: The maximum amount of space to use of\
            the SDRAM on the machine (default is 1MB)
        :param send_buffer_space_before_notify: The amount of space free in\
            the sending buffer before the machine will ask the host for more\
            data (default setting is optimised for most cases)
        :param buffer_notification_ip_address: The IP address of the host that\
            will send new buffers (must be specified if a send buffer is\
            specified)
        :param buffer_notification_port: The port that the host that will\
            send new buffers is listening on (must be specified if a send\
            buffer is specified)
        :param buffer_notification_tag: The IP tag to use to notify the\
            host about space in the buffer (default is to use any tag)
        :param reserve_reverse_ip_tag: True if the source should set up a tag\
            through which it can receive packets; if port is set to None this\
            can be used to enable the reception of packets on a randomly\
            assigned port, which can be read from the database
        """
        # pylint: disable=too-many-arguments, too-many-locals
        super(ReverseIPTagMulticastSourceMachineVertex, self).__init__(
            label, constraints)

        self._iptags = None
        self._reverse_iptags = None

        # Set up for receiving live packets
        if receive_port is not None or reserve_reverse_ip_tag:
            self._reverse_iptags = [ReverseIPtagResource(
                port=receive_port, sdp_port=receive_sdp_port,
                tag=receive_tag)]
            if board_address is not None:
                self.add_constraint(BoardConstraint(board_address))
        self._receive_rate = receive_rate
        self._receive_sdp_port = receive_sdp_port

        # Work out if buffers are being sent
        self._send_buffer = None
        self._send_buffer_partition_id = send_buffer_partition_id
        self._send_buffer_max_space = send_buffer_max_space
        if send_buffer_times is None:
            self._send_buffer_times = None
            self._send_buffers = None
        else:
            self._install_send_buffer(n_keys, send_buffer_times, (
                buffer_notification_ip_address, buffer_notification_port,
                buffer_notification_tag, board_address))

        # buffered out parameters
        self._send_buffer_space_before_notify = max((
            send_buffer_space_before_notify, send_buffer_max_space))

        # Set up for recording (if requested)
        self._record_buffer_size = 0
        self._buffer_size_before_receive = 0
        self._time_between_triggers = 0
        self._maximum_recording_buffer = 0

        # Set up for buffering
        self._buffer_notification_ip_address = buffer_notification_ip_address
        self._buffer_notification_port = buffer_notification_port
        self._buffer_notification_tag = buffer_notification_tag

        # set flag for checking if in injection mode
        self._in_injection_mode = \
            receive_port is not None or reserve_reverse_ip_tag

        # Sort out the keys to be used
        self._n_keys = n_keys
        self._virtual_key = virtual_key
        self._mask = None
        self._prefix = prefix
        self._prefix_type = prefix_type
        self._check_keys = check_keys

        # Work out the prefix details
        if self._prefix is not None:
            if self._prefix_type is None:
                self._prefix_type = EIEIOPrefix.UPPER_HALF_WORD
            if self._prefix_type == EIEIOPrefix.UPPER_HALF_WORD:
                self._prefix = prefix << 16

        # If the user has specified a virtual key
        if self._virtual_key is not None:
            self._install_virtual_key(n_keys)
    def __init__(
        self,
        label,
        vertex_slice=None,
        app_vertex=None,
        n_keys=None,
        constraints=None,

        # General input and output parameters
        board_address=None,

        # Live input parameters
        receive_port=None,
        receive_sdp_port=SDP_PORTS.INPUT_BUFFERING_SDP_PORT.value,
        receive_tag=None,
        receive_rate=10,

        # Key parameters
        virtual_key=None,
        prefix=None,
        prefix_type=None,
        check_keys=False,

        # Send buffer parameters
        send_buffer_times=None,
        send_buffer_partition_id=None,

        # Extra flag for receiving packets without a port
        reserve_reverse_ip_tag=False,

        # Flag to indicate that data will be received to inject
        enable_injection=False):
        # pylint: disable=too-many-arguments, too-many-locals
        if vertex_slice is None:
            if n_keys is not None:
                vertex_slice = Slice(0, n_keys - 1)
            else:
                raise KeyError("Either provide a vertex_slice or n_keys")

        super(ReverseIPTagMulticastSourceMachineVertex,
              self).__init__(label, constraints, app_vertex, vertex_slice)

        self._reverse_iptags = None
        self._n_keys = vertex_slice.n_atoms

        # Set up for receiving live packets
        if receive_port is not None or reserve_reverse_ip_tag:
            self._reverse_iptags = [
                ReverseIPtagResource(port=receive_port,
                                     sdp_port=receive_sdp_port,
                                     tag=receive_tag)
            ]
            if board_address is not None:
                self.add_constraint(BoardConstraint(board_address))
        self._receive_rate = receive_rate
        self._receive_sdp_port = receive_sdp_port

        # Work out if buffers are being sent
        self._send_buffer = None
        self._send_buffer_partition_id = send_buffer_partition_id
        self._send_buffer_size = 0
        n_buffer_times = 0
        if send_buffer_times is not None:
            for i in send_buffer_times:
                if hasattr(i, "__len__"):
                    n_buffer_times += len(i)
                else:
                    # assuming this must be a single integer
                    n_buffer_times += 1
            if n_buffer_times == 0:
                logger.warning(
                    "Combination of send_buffer_times {} and slice {} results "
                    "in a core with a ReverseIPTagMulticastSourceMachineVertex"
                    " which does not spike", send_buffer_times, vertex_slice)
        if n_buffer_times == 0:
            self._send_buffer_times = None
            self._send_buffers = None
        else:
            self._install_send_buffer(send_buffer_times)

        # Set up for recording (if requested)
        self._is_recording = False

        # set flag for checking if in injection mode
        self._in_injection_mode = (receive_port is not None
                                   or reserve_reverse_ip_tag
                                   or enable_injection)

        # Sort out the keys to be used
        self._virtual_key = virtual_key
        self._mask = None
        self._prefix = prefix
        self._prefix_type = prefix_type
        self._check_keys = check_keys

        # Work out the prefix details
        if self._prefix is not None:
            if self._prefix_type is None:
                self._prefix_type = EIEIOPrefix.UPPER_HALF_WORD
            if self._prefix_type == EIEIOPrefix.UPPER_HALF_WORD:
                self._prefix = prefix << 16

        # If the user has specified a virtual key
        if self._virtual_key is not None:
            self._install_virtual_key(vertex_slice.n_atoms)

        self._n_vertices += 1