def __init__(self, nearest_neighbour_id, n_blocks, x=None, y=None): """ :param nearest_neighbour_id: The id of the packet, between 0 and 127 :type nearest_neighbour_id: int :param n_blocks: The number of blocks of data that will be sent,\ between 0 and 255 :type n_blocks: int :param x: The x-coordindate of the chip to load the data on to. If\ not specified, the data will be loaded on to all chips :type x: int :param y: The y-coordinate of the chip to load the data on to. If\ not specified, the data will be loaded on to all chips :type y: int """ key = ((_NNP_FLOOD_FILL_START << 24) | (nearest_neighbour_id << 16) | (n_blocks << 8)) data = 0xFFFF if x is not None and y is not None: m = ((y & 3) * 4) + (x & 3) data = (((x & 0xfc) << 24) + ((y & 0xfc) << 16) + (3 << 16) + (1 << m)) super(SCPFloodFillStartRequest, self).__init__( SDPHeader(flags=SDPFlag.REPLY_EXPECTED, destination_port=0, destination_cpu=0, destination_chip_x=0, destination_chip_y=0), SCPRequestHeader(command=SCPCommand.CMD_NNP), argument_1=key, argument_2=data, argument_3=_NNP_FORWARD_RETRY)
def __init__(self, x, y, p, packet_types): """ :param x: The x-coordinate of a chip, between 0 and 255 :type x: int :param y: The y-coordinate of a chip, between 0 and 255 :type y: int :param p: The processor running the dropped packet reinjector, between\ 0 and 17 :type p: int :param packet_types: The types of packet to reinject - if empty or\ None reinjection is disabled :type packet_types: None or list of \ `py:class:spinnman.messages.scp.scp_dpri_packet_type_flags.SCPDPRIPacketTypeFlags` """ flags = 0 if packet_types is not None: for packet_type in packet_types: flags |= packet_type.value AbstractSCPRequest.__init__( self, SDPHeader(flags=SDPFlag.REPLY_EXPECTED, destination_port=0, destination_cpu=p, destination_chip_x=x, destination_chip_y=y), SCPRequestHeader(command=SCPCommand.CMD_DPRI), argument_1=SCPDPRICommand.SET_PACKET_TYPES.value, argument_2=flags)
def __init__(self, app_id, x, y, processors): """ :param app_id: The id of the application to run, between 16 and 255 :type app_id: int :param x: The x-coordinate of the chip to run on, between 0 and 255 :type x: int :param y: The y-coordinate of the chip to run on, between 0 and 255 :type y: int :param processors: The processors on the chip where the executable\ should be started, between 1 and 17 """ processor_mask = 0 if processors is not None: for processor in processors: processor_mask |= (1 << processor) processor_mask |= (app_id << 24) super(SCPApplicationRunRequest, self).__init__(SDPHeader(flags=SDPFlag.REPLY_EXPECTED, destination_port=0, destination_cpu=0, destination_chip_x=x, destination_chip_y=y), SCPRequestHeader(command=SCPCommand.CMD_AR), argument_1=processor_mask)
def __init__(self, x, y, cpu, led_states): """ :param x: The x-coordinate of the chip, between 0 and 255 :type x: int :param y: The y-coordinate of the chip, between 0 and 255 :type y: int :param cpu: The CPU-number to use to set the LED. :type cpu: int :param led_states: A dictionary mapping LED index to state with 0 being off, 1 on and 2 inverted. :type led_states: dict """ encoded_led_states = 0 for led, state in led_states.items(): encoded_led_states |= {0: 2, 1: 3, 2: 1}[state] << (2 * led) super(SCPLEDRequest, self).__init__(SDPHeader(flags=SDPFlag.REPLY_EXPECTED, destination_port=0, destination_cpu=cpu, destination_chip_x=x, destination_chip_y=y), SCPRequestHeader(command=SCPCommand.CMD_LED), argument_1=encoded_led_states)
def __init__(self, x, y, host, port, tag, strip): """ :param x: The x-coordinate of a chip, between 0 and 255 :type x: int :param y: The y-coordinate of a chip, between 0 and 255 :type y: int :param host: The host address, as an array of 4 bytes :type host: bytearray :param port: The port, between 0 and 65535 :type port: int :param tag: The tag, between 0 and 7 :type tag: int :param strip: if the SDP header should be striped from the packet. :type strip: bool """ strip_value = 0 if strip: strip_value = 1 super(SCPIPTagSetRequest, self).__init__( SDPHeader( flags=SDPFlag.REPLY_EXPECTED, destination_port=0, destination_cpu=0, destination_chip_x=x, destination_chip_y=y), SCPRequestHeader(command=SCPCommand.CMD_IPTAG), argument_1=(strip_value << 28) | (_IPTAG_SET << 16) | tag, argument_2=port, argument_3=((host[3] << 24) | (host[2] << 16) | (host[1] << 8) | host[0]))
def __init__(self, x, y, base_address, data, cpu=0): """ :param x: The x-coordinate of the chip, between 0 and 255\ this is not checked due to speed restrictions :type x: int :param y: The y-coordinate of the chip, between 0 and 255\ this is not checked due to speed restrictions :type y: int :param base_address: The base_address to start writing to \ the base address is not checked to see if its not valid :type base_address: int :param data: between 1 and 256 bytes of data to write\ this is not checked due to speed restrictions :type data: bytearray or string """ size = len(data) super(SCPWriteMemoryRequest, self).__init__( SDPHeader(flags=SDPFlag.REPLY_EXPECTED, destination_port=0, destination_cpu=cpu, destination_chip_x=x, destination_chip_y=y), SCPRequestHeader(command=SCPCommand.CMD_WRITE), argument_1=base_address, argument_2=size, argument_3=constants.address_length_dtype[(base_address % 4), (size % 4)].value, data=None) self._data_to_write = data
def __init__(self, x, y, p, run_time, infinite_run, destination_port, expect_response=True): sdp_flags = SDPFlag.REPLY_NOT_EXPECTED arg3 = 0 if expect_response: sdp_flags = SDPFlag.REPLY_EXPECTED arg3 = 1 AbstractSCPRequest.__init__( self, SDPHeader(flags=sdp_flags, destination_port=destination_port, destination_cpu=p, destination_chip_x=x, destination_chip_y=y), SCPRequestHeader(command=( constants.SDP_RUNNING_MESSAGE_CODES.SDP_NEW_RUNTIME_ID_CODE)), argument_1=run_time, argument_2=infinite_run, argument_3=arg3)
def __init__(self, x, y, base_address, size, cpu=0): """ :param x: The x-coordinate of the chip to read from, between 0 and 255 :type x: int :param y: The y-coordinate of the chip to read from, between 0 and 255 :type y: int :param base_address: The positive base address to start the read from :type base_address: int :param size: The number of bytes to read, between 1 and 256 :type size: int :raise spinnman.exceptions.SpinnmanInvalidParameterException: * If the chip coordinates are out of range * If the base address is not a positive number * If the size is out of range """ super(SCPReadMemoryRequest, self).__init__( SDPHeader(flags=SDPFlag.REPLY_EXPECTED, destination_port=0, destination_cpu=cpu, destination_chip_x=x, destination_chip_y=y), SCPRequestHeader(command=SCPCommand.CMD_READ), argument_1=base_address, argument_2=size, argument_3=constants.address_length_dtype[(base_address % 4, size % 4)].value)
def __init__(self, nearest_neighbour_id, block_no, base_address, data, offset=0, length=None): """ :param nearest_neighbour_id: The id of the packet, between 0 and 127 :type nearest_neighbour_id: int :param block_no: Which block this block is, between 0 and 255 :type block_no: int :param base_address: The base address where the data is to be loaded :type base_address: int :param data: The data to load, between 4 and 256 bytes and the size\ must be divisible by 4 :type data: bytearray """ self._size = length self._offset = offset self._data_to_write = data if length is None: self._size = len(data) argument_1 = _NNP_FORWARD_RETRY | nearest_neighbour_id argument_2 = (block_no << 16) | (((self._size / 4) - 1) << 8) super(SCPFloodFillDataRequest, self).__init__( SDPHeader(flags=SDPFlag.REPLY_EXPECTED, destination_port=0, destination_cpu=0, destination_chip_x=0, destination_chip_y=0), SCPRequestHeader(command=SCPCommand.CMD_FFD), argument_1=argument_1, argument_2=argument_2, argument_3=base_address, data=None)
def __init__(self, boards, scp_request_header, argument_1=None, argument_2=None, argument_3=None, data=None): """ :param boards: The board or boards to be addressed by this request :type boards: int or iterable of int :param scp_request_header: The SCP request header :param argument_1: The optional first argument :param argument_2: The optional second argument :param argument_3: The optional third argument :param data: The optional data to be sent """ sdp_header = SDPHeader( flags=SDPFlag.REPLY_EXPECTED, destination_port=0, destination_cpu=AbstractSCPBMPRequest.get_first_board(boards), destination_chip_x=0, destination_chip_y=0) AbstractSCPRequest.__init__(self, sdp_header, scp_request_header, argument_1, argument_2, argument_3, data)
def __init__(self, x, y, app_id, n_entries): """ :param x: The x-coordinate of the chip to allocate on, between 0 and\ 255 :type x: int :param y: The y-coordinate of the chip to allocate on, between 0 and\ 255 :type y: int :param app_id: The id of the application, between 0 and 255 :type app_id: int :param n_entries: The number of entries to allocate :type n_entries: int """ super(SCPRouterAllocRequest, self).__init__( SDPHeader(flags=SDPFlag.REPLY_EXPECTED, destination_port=0, destination_cpu=0, destination_chip_x=x, destination_chip_y=y), SCPRequestHeader(command=SCPCommand.CMD_ALLOC), argument_1=( (app_id << 8) | SCPAllocFreeType.ALLOC_ROUTING.value), # @UndefinedVariable argument_2=n_entries)
def __init__(self, x, y, link, base_address, data, cpu=0): """ :param x: The x-coordinate of the chip whose neighbour will be written\ to, between 0 and 255 :type x: int :param y: The y-coordinate of the chip whose neighbour will be written\ to, between 0 and 255 :type y: int :param cpu: The CPU core to use, normally 0 (or if a BMP, the board \ slot number) :type cpu: int :param link: The link number to write to between 0 and 5 (or if a BMP,\ the FPGA between 0 and 2) :type link: int :param base_address: The base_address to start writing to :type base_address: int :param data: Up to 256 bytes of data to write :type data: bytearray """ super(SCPWriteLinkRequest, self).__init__( SDPHeader( flags=SDPFlag.REPLY_EXPECTED, destination_port=0, destination_cpu=cpu, destination_chip_x=x, destination_chip_y=y), SCPRequestHeader(command=SCPCommand.CMD_LINK_WRITE), argument_1=base_address, argument_2=len(data), argument_3=link, data=None) self._data_to_write = data
def __init__(self, nearest_neighbour_id, app_id=0, processors=None): """ :param nearest_neighbour_id: The id of the packet, between 0 and 127 :type nearest_neighbour_id: int :param app_id: The application id to start using the data, between 16\ and 255. If not specified, no application is started :type app_id: int :param processors: A list of processors on which to start the\ application, each between 1 and 17. If not specified,\ no application is started. :type processors: iterable of int """ processor_mask = 0 if processors is not None: for processor in processors: processor_mask |= (1 << processor) key = (_NNP_FLOOD_FILL_END << 24) | nearest_neighbour_id data = (app_id << 24) | processor_mask super(SCPFloodFillEndRequest, self).__init__(SDPHeader(flags=SDPFlag.REPLY_EXPECTED, destination_port=0, destination_cpu=0, destination_chip_x=0, destination_chip_y=0), SCPRequestHeader(command=SCPCommand.CMD_NNP), argument_1=key, argument_2=data, argument_3=_NNP_FORWARD_RETRY)
def __init__(self, x, y, p, timeout_mantissa, timeout_exponent): """ :param x: The x-coordinate of a chip, between 0 and 255 :type x: int :param y: The y-coordinate of a chip, between 0 and 255 :type y: int :param p: The processor running the dropped packet reinjector, between\ 0 and 17 :type p: int :param timeout_mantissa: The mantissa of the timeout value, \ between 0 and 15 :type timeout_mantissa: int :param timeout_exponent: The exponent of the timeout value, \ between 0 and 15 """ AbstractSCPRequest.__init__( self, SDPHeader(flags=SDPFlag.REPLY_EXPECTED, destination_port=0, destination_cpu=p, destination_chip_x=x, destination_chip_y=y), SCPRequestHeader(command=SCPCommand.CMD_DPRI), argument_1=SCPDPRICommand.SET_ROUTER_TIMEOUT.value, argument_2=(timeout_mantissa & 0xF) | ((timeout_exponent & 0xF) << 4))
def __init__(self, app_id, signal): """ :param app_id: The id of the application, between 0 and 255 :type app_id: int :param signal: The signal to send :type signal: :py:class:`spinnman.messages.scp.scp_signal.SCPSignal` :raise spinnman.exceptions.SpinnmanInvalidParameterException: If\ app_id is out of range """ if app_id < 0 or app_id > 255: raise SpinnmanInvalidParameterException( "app_id", str(app_id), "Must be between 0 and 255") super(SCPSendSignalRequest, self).__init__(SDPHeader(flags=SDPFlag.REPLY_EXPECTED, destination_port=0, destination_cpu=0, destination_chip_x=0, destination_chip_y=0), SCPRequestHeader(command=SCPCommand.CMD_SIG), argument_1=signal.signal_type.value, argument_2=_get_data(app_id, signal), argument_3=_ALL_CORE_MASK)
def __init__(self, x, y, app_id, base_address=None): """ :param x: The x-coordinate of the chip to allocate on, between 0 and\ 255 :type x: int :param y: The y-coordinate of the chip to allocate on, between 0 and\ 255 :type y: int :param app_id: The id of the application, between 0 and 255 :type app_id: int :param base_address: The start address in SDRAM to which the block\ needs to be deallocated, or none if deallocating via app_id :type base_address: int or None """ if base_address is not None: AbstractSCPRequest.__init__( self, SDPHeader(flags=SDPFlag.REPLY_NOT_EXPECTED, destination_port=0, destination_cpu=0, destination_chip_x=x, destination_chip_y=y), SCPRequestHeader(command=SCPCommand.CMD_ALLOC), argument_1=(app_id << 8 | SCPAllocFreeType.FREE_SDRAM_BY_POINTER.value ), # @UndefinedVariable argument_2=base_address) else: AbstractSCPRequest.__init__( self, SDPHeader(flags=SDPFlag.REPLY_EXPECTED, destination_port=0, destination_cpu=0, destination_chip_x=x, destination_chip_y=y), SCPRequestHeader(command=SCPCommand.CMD_ALLOC), argument_1=(app_id << 8 | SCPAllocFreeType.FREE_ROUTING_BY_APP_ID.value )) # @UndefinedVariable
def read_bytestring(self, data, offset): """ Reads a packet from a bytestring of data :param data: The data to be read :type data: bytestring :param offset: The offset in the data from which the response should\ be read :type offset: int """ self._sdp_header = SDPHeader.from_bytestring(data, offset) self._scp_response_header = SCPResponseHeader.from_bytestring( data, _SCP_HEADER_OFFSET + offset) self.read_data_bytestring(data, _SCP_DATA_OFFSET + offset)
def __get_sdp_data(message, x, y, p): # Create an SDP message - no reply so source is unimportant # SDP port can be anything except 0 as the target doesn't care sdp_message = SDPMessage(SDPHeader(flags=SDPFlag.REPLY_NOT_EXPECTED, tag=0, destination_port=1, destination_cpu=p, destination_chip_x=x, destination_chip_y=y, source_port=0, source_cpu=0, source_chip_x=0, source_chip_y=0), data=message.bytestring) return _TWO_SKIP.pack() + sdp_message.bytestring
def __init__(self, x, y): """ :param x: The x-coordinate of a chip, between 0 and 255 :type x: int :param y: The y-coordinate of a chip, between 0 and 255 :type y: int """ super(SCPTagInfoRequest, self).__init__( SDPHeader( flags=SDPFlag.REPLY_EXPECTED, destination_port=0, destination_cpu=0, destination_chip_x=x, destination_chip_y=y), SCPRequestHeader(command=SCPCommand.CMD_IPTAG), argument_1=(_IPTAG_INFO << 16), argument_2=_IPTAG_MAX)
def __init__(self, x, y, n_entries, table_address, base_address, app_id): """ :param x: The x-coordinate of the chip, between 0 and 255, \ this is not checked due to speed restrictions :type x: int :param y: The y-coordinate of the chip, between 0 and 255\ this is not checked due to speed restrictions :type y: int :param n_entries: The number of entries in the table, more than 0 :type n_entries: int :param table_address: The allocated table address :type table_address: int :param base_address: The base_address containing the entries :type base_address: int :param app_id: The id of the application with which to associate the\ routes. If not specified, defaults to 0. :type app_id: int :raise spinnman.exceptions.SpinnmanInvalidParameterException:\ * If x is out of range * If y is out of range * If n_entries is 0 or less * If table_address is not positive * If base_address is not positive """ if n_entries < 1: raise SpinnmanInvalidParameterException("n_entries", str(n_entries), "Must be more than 0") if base_address < 0: raise SpinnmanInvalidParameterException( "base_address", str(base_address), "Must be a positive integer") if table_address < 0: raise SpinnmanInvalidParameterException( "table_address", str(table_address), "Must be a positive integer") super(SCPRouterInitRequest, self).__init__( SDPHeader(flags=SDPFlag.REPLY_EXPECTED, destination_port=0, destination_cpu=0, destination_chip_x=x, destination_chip_y=y), SCPRequestHeader(command=SCPCommand.CMD_RTR), argument_1=((n_entries << 16) | (app_id << 8) | 2), argument_2=table_address, argument_3=base_address)
def __init__(self, x, y, tag): """ :param x: The x-coordinate of a chip, between 0 and 255 :type x: int :param y: The y-coordinate of a chip, between 0 and 255 :type y: int :param tag: The tag, between 0 and 7 :type tag: int """ super(SCPIPTagClearRequest, self).__init__( SDPHeader( flags=SDPFlag.REPLY_EXPECTED, destination_port=0, destination_cpu=0, destination_chip_x=x, destination_chip_y=y), SCPRequestHeader(command=SCPCommand.CMD_IPTAG), argument_1=(_IPTAG_CLEAR << 16) | tag)
def _send_request(self, vertex, message): """ Sends a request :param vertex: The vertex to send to :param message: The message to send """ placement = self._placements.get_placement_of_subvertex(vertex) sdp_header = SDPHeader(destination_chip_x=placement.x, destination_chip_y=placement.y, destination_cpu=placement.p, flags=SDPFlag.REPLY_NOT_EXPECTED, destination_port=spinn_front_end_constants. SDP_PORTS.INPUT_BUFFERING_SDP_PORT.value) sdp_message = SDPMessage(sdp_header, message.bytestring) self._transceiver.send_sdp_message(sdp_message)
def __init__(self, transceiver, placement): """ Create a new SpecSender :param transceiver: The transceiver used to communicate with the board. :type transceiver: Transceiver :param placement: The destination of the data specification. :type placement: Placement :return: """ self.transceiver = transceiver self.placement = placement self.header = SDPHeader(flags=SDPFlag.REPLY_NOT_EXPECTED, destination_cpu=placement.p, destination_chip_x=placement.x, destination_chip_y=placement.y, destination_port=1) self.msg_data = bytearray()
def __init__(self, app_id): """ :param app_id: The id of the application, between 0 and 255 :type app_id: int :param signal: The signal to send :type signal: :py:class:`spinnman.messages.scp.scp_signal.SCPSignal` """ super(SCPAppStopRequest, self).__init__( SDPHeader(flags=SDPFlag.REPLY_EXPECTED, destination_port=0, destination_cpu=0, destination_chip_x=0, destination_chip_y=0), SCPRequestHeader(command=SCPCommand.CMD_NNP), argument_1=(0x3f << 16), argument_2=(5 << 28) | _get_data(app_id, SCPSignal.STOP), argument_3=(1 << 31) + (0x3f << 8))
def __init__(self, app_id, state): """ :param app_id: The id of the application, between 0 and 255 :type app_id: int :param state: The state to count :type state: :py:class:`spinnman.model.cpu_state.CPUState` """ super(SCPCountStateRequest, self).__init__(SDPHeader(flags=SDPFlag.REPLY_EXPECTED, destination_port=0, destination_cpu=0, destination_chip_x=0, destination_chip_y=0), SCPRequestHeader(command=SCPCommand.CMD_SIG), argument_1=_COUNT_SIGNAL_TYPE, argument_2=_get_data(app_id, state), argument_3=_ALL_CORE_MASK)
def __init__(self, x, y, p): """ :param x: The x-coordinate of a chip, between 0 and 255 :type x: int :param y: The y-coordinate of a chip, between 0 and 255 :type y: int :param p: The processor running the dropped packet reinjector, between\ 0 and 17 :type p: int """ AbstractSCPRequest.__init__( self, SDPHeader(flags=SDPFlag.REPLY_EXPECTED, destination_port=0, destination_cpu=p, destination_chip_x=x, destination_chip_y=y), SCPRequestHeader(command=SCPCommand.CMD_DPRI), argument_1=SCPDPRICommand.RESET_COUNTERS.value)
def __init__(self, x, y, tag_timeout): """ :param x: The x-coordinate of the chip to run on, between 0 and 255 :type x: int :param y: The y-coordinate of the chip to run on, between 0 and 255 :type y: int :param tag_timeout: The timeout value, via the IPTAG_TIME_OUT_WAIT_TIMES\ enum located in spinnman.constants """ super(SCPIPTagTTORequest, self).__init__(SDPHeader(flags=SDPFlag.REPLY_EXPECTED, destination_port=0, destination_cpu=0, destination_chip_x=x, destination_chip_y=y), SCPRequestHeader(command=SCPCommand.CMD_IPTAG), argument_1=_IPTAG_TTO, argument_2=tag_timeout)
def __init__(self, x, y, p): """ :param x: The x-coordinate of the chip to read from, between 0 and 255 :type x: int :param y: The y-coordinate of the chip to read from, between 0 and 255 :type y: int :param p: The id of the processor to read the version from,\ between 0 and 31 :type p: int :raise spinnman.exceptions.SpinnmanInvalidParameterException: * If the chip coordinates are out of range * If the processor is out of range """ super(SCPVersionRequest, self).__init__( SDPHeader( flags=SDPFlag.REPLY_EXPECTED, destination_port=0, destination_cpu=p, destination_chip_x=x, destination_chip_y=y), SCPRequestHeader(command=SCPCommand.CMD_VER))
def __init__(self, x, y): """ :param x: The x-coordinate of the chip, between 0 and 255 \ this is not checked due to speed restrictions :type x: int :param y: The y-coordinate of the chip, between 0 and 255 \ this is not checked due to speed restrictions :type y: int :raise spinnman.exceptions.SpinnmanInvalidParameterException:\ * If x is out of range * If y is out of range """ super(SCPRouterClearRequest, self).__init__( SDPHeader(flags=SDPFlag.REPLY_EXPECTED, destination_port=0, destination_cpu=0, destination_chip_x=x, destination_chip_y=y), SCPRequestHeader(command=SCPCommand.CMD_RTR))
def __call__(self, txrx, app_id, all_core_subsets): # check that the right number of processors are in sync processors_completed = txrx.get_core_state_count( app_id, CPUState.FINISHED) total_processors = len(all_core_subsets) left_to_do_cores = total_processors - processors_completed progress_bar = ProgressBar( left_to_do_cores, "Forcing error cores to generate provenance data") # check that all cores are in the state CPU_STATE_12 which shows that # the core has received the message and done provenance updating while processors_completed != total_processors: unsuccessful_cores = helpful_functions.get_cores_not_in_state( all_core_subsets, CPUState.FINISHED, txrx) for (x, y, p) in unsuccessful_cores: data = struct.pack( "<I", constants.SDP_RUNNING_MESSAGE_CODES. SDP_UPDATE_PROVENCE_REGION_AND_EXIT.value) txrx.send_sdp_message( SDPMessage(SDPHeader( flags=SDPFlag.REPLY_NOT_EXPECTED, destination_cpu=p, destination_chip_x=x, destination_port=(constants.SDP_PORTS. RUNNING_COMMAND_SDP_PORT.value), destination_chip_y=y), data=data)) processors_completed = txrx.get_core_state_count( app_id, CPUState.FINISHED) left_over_now = total_processors - processors_completed to_update = left_to_do_cores - left_over_now if to_update != 0: progress_bar.update(to_update) progress_bar.end()
def from_bytestring(data, offset): sdp_header = SDPHeader.from_bytestring(data, offset) return SDPMessage(sdp_header, data, offset + 8)