Skip to content

Commit 4f12a35

Browse files
committed
Update to support 6 output keys and masks
1 parent 0547356 commit 4f12a35

File tree

3 files changed

+46
-26
lines changed

3 files changed

+46
-26
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ simple_example.png
2424
*.data
2525
*.data2
2626
*.csv
27+
/.mypy_cache/

spynnaker/pyNN/external_devices_models/spif_devices.py

+18-6
Original file line numberDiff line numberDiff line change
@@ -315,28 +315,40 @@ class SpiNNFPGARegister(IntEnum):
315315
#: peripheral to SpiNNaker
316316
START = 17
317317

318-
def cmd(self, payload=None):
318+
#: The base of the keys that can be sent out of SpiNNaker (up to 6)
319+
XP_KEY_BASE = 32
320+
321+
#: The base of the masks that can be sent out of SpiNNake (up to 6)
322+
XP_MASK_BASE = 48
323+
324+
def cmd(self, payload=None, index=0):
319325
"""
320326
Make a command to send to the FPGA to set a register value.
321327
322328
:param payload:
323329
The payload to use in the command, or `None` for no payload
324330
:type payload: int or None
331+
:param int index:
332+
The index of the register to send to when there are multiple
333+
registers starting from a base
325334
:rtype: ~spinn_front_end_common.utility_models.MultiCastCommand
326335
"""
327336
return MultiCastCommand(
328-
_LC_KEY + self.value, payload, time=None, repeat=_REPEATS,
337+
_LC_KEY + self.value + index, payload, time=None, repeat=_REPEATS,
329338
delay_between_repeats=_DELAY_BETWEEN_REPEATS)
330339

331-
def delayed_command(self, get_payload):
340+
def delayed_command(self, get_payload, index=0):
332341
"""
333342
Make a command to send to the FPGA to set a register value,
334343
where the value itself is currently unknown.
335344
336-
:param callable()->int get_payload:
337-
A function to call to get the payload later
345+
:param callable(int)->int get_payload:
346+
A function to call to get the payload later, passing in the index
347+
:param int index:
348+
The index of the register to send to when there are multiple
349+
registers starting from a base
338350
:rtype: ~spinn_front_end_common.utility_models.MultiCastCommand
339351
"""
340352
return _DelayedMultiCastCommand(
341-
_LC_KEY + self.value, get_payload, repeat=_REPEATS,
353+
_LC_KEY + self.value + index, get_payload(index), repeat=_REPEATS,
342354
delay_between_repeats=_DELAY_BETWEEN_REPEATS)

spynnaker/pyNN/external_devices_models/spif_output_device.py

+27-20
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
from .spif_devices import (
2626
SPIF_FPGA_ID, SPIF_OUTPUT_FPGA_LINK, SpiNNFPGARegister)
2727

28+
# The maximum number of partitions that can be supported.
29+
N_OUTGOING = 6
30+
2831

2932
class SPIFOutputDevice(
3033
ApplicationFPGAVertex, PopulationApplicationVertex,
@@ -33,7 +36,7 @@ class SPIFOutputDevice(
3336
Output (only) to a SPIF device.
3437
"""
3538

36-
__slots__ = ["__incoming_partition", "__create_database"]
39+
__slots__ = ["__incoming_partitions", "__create_database"]
3740

3841
def __init__(self, board_address=None, chip_coords=None, label=None,
3942
create_database=True, database_notify_host=None,
@@ -44,7 +47,7 @@ def __init__(self, board_address=None, chip_coords=None, label=None,
4447
SPIF_FPGA_ID, SPIF_OUTPUT_FPGA_LINK, board_address,
4548
chip_coords),
4649
label=label)
47-
self.__incoming_partition = None
50+
self.__incoming_partitions = list()
4851
# Force creation of the database, to be used in the read side of things
4952
if create_database:
5053
set_config("Database", "create_database", "True")
@@ -58,44 +61,48 @@ def add_incoming_edge(self, edge, partition):
5861
# Ignore non-spike partitions
5962
if partition.identifier != SPIKE_PARTITION_ID:
6063
return
61-
if self.__incoming_partition is not None:
64+
if len(self.__incoming_partitions) >= N_OUTGOING:
6265
raise ValueError(
63-
"Only one outgoing connection is supported per spif device"
64-
f" (existing partition: {self.__incoming_partition}")
65-
self.__incoming_partition = partition
66+
f"Only {N_OUTGOING} outgoing connections are supported per"
67+
" spif device (existing partitions:"
68+
f" {self.__incoming_partitions}")
69+
self.__incoming_partitions.append(partition)
6670
if self.__create_database:
6771
SpynnakerDataView.add_live_output_vertex(
68-
self.__incoming_partition.pre_vertex,
69-
self.__incoming_partition.identifier)
72+
partition.pre_vertex, partition.identifier)
7073

71-
def _get_set_key_payload(self):
74+
def _get_set_key_payload(self, index):
7275
"""
7376
Get the payload for the command to set the router key.
77+
78+
:param int index: The index of key to get
7479
"""
7580
r_infos = SpynnakerDataView.get_routing_infos()
7681
return r_infos.get_first_key_from_pre_vertex(
77-
self.__incoming_partition.pre_vertex,
78-
self.__incoming_partition.identifier)
82+
self.__incoming_partitions[index].pre_vertex,
83+
self.__incoming_partitions[index].identifier)
7984

80-
def _get_set_mask_payload(self):
85+
def _get_set_mask_payload(self, index):
8186
"""
8287
Get the payload for the command to set the router mask.
88+
89+
:param int index: The index of the mask to get
8390
"""
8491
r_infos = SpynnakerDataView.get_routing_infos()
8592
return r_infos.get_routing_info_from_pre_vertex(
86-
self.__incoming_partition.pre_vertex,
87-
self.__incoming_partition.identifier).mask
93+
self.__incoming_partitions[index].pre_vertex,
94+
self.__incoming_partitions[index].identifier).mask
8895

8996
@property
9097
def start_resume_commands(self):
9198
# The commands here are delayed, as at the time of providing them,
9299
# we don't know the key or mask of the incoming link...
93-
return [
94-
SpiNNFPGARegister.P_KEY.delayed_command(
95-
self._get_set_key_payload),
96-
SpiNNFPGARegister.P_MASK.delayed_command(
97-
self._get_set_mask_payload)
98-
]
100+
commands = list()
101+
for i in range(len(self.__incoming_partitions)):
102+
commands.append(SpiNNFPGARegister.XP_KEY_BASE.delayed_command(
103+
self._get_set_key_payload, i))
104+
commands.append(SpiNNFPGARegister.XP_MASK_BASE.delayed_command(
105+
self._get_set_mask_payload, i))
99106

100107
@property
101108
def pause_stop_commands(self):

0 commit comments

Comments
 (0)