spinn_front_end_common.interface.ds package

Module contents

class spinn_front_end_common.interface.ds.DataSpecificationBase(x: int, y: int, p: int, ds_db: DsSqlliteDatabase, report_writer: TextIO | None = None)

Bases: object

Base class for all vertex data specification creation

Parameters:

report_writer (TextIOBase or None) – Determines if a text version of the specification is to be written and, if so, where. No report is written if this is None.

comment(comment: str)[source]

Write a comment to the text version of the specification.

Note

This is ignored by the binary file.

Parameters:

comment (str) – The comment to write

end_specification() None[source]

Insert a command to indicate that the specification has finished and finish writing.

abstract reference_memory_region(region: int, ref: int, label: str | None = None)[source]

Insert command to reference another memory region.

Parameters:
  • region (int) – The number of the region to reserve, from 0 to 15

  • ref (int) – The identifier of the region to reference

  • label (str or None) – An optional label for the region

Raises:
  • RegionInUseException – If the region was already reserved

  • ParameterOutOfBoundsException – If the region requested was out of the allowed range, or the size was too big to fit in SDRAM

abstract reserve_memory_region(region: int, size: int, label: str | None = None, reference: int | None = None)[source]

Insert command to reserve a memory region.

Parameters:
  • region (int) – The number of the region to reserve, from 0 to 32

  • size (int) – The size to reserve for the region, in bytes

  • label (str or None) – An optional label for the region

  • reference (int or None) – A globally unique reference for this region

Raises:
  • RegionInUseException – If the region was already reserved

  • ParameterOutOfBoundsException – If the region requested was out of the allowed range, or the size was too big to fit in SDRAM

switch_write_focus(region: int)[source]

Insert command to switch the region being written to.

Parameters:

region (int) – The ID of the region to switch to, between 0 and 15

Raises:
  • ParameterOutOfBoundsException – If the region identifier is not valid

  • DataSpecException – If the region has not been allocated

write_array(array_values: Sequence[int] | Sequence[float] | ndarray, data_type=DataType.UINT32)[source]

Insert command to write an array, causing the write pointer to move on by (data type size * the array size), in bytes.

Parameters:
write_value(data: int | float, data_type=DataType.UINT32)[source]

Insert command to write a value (once) to the current write pointer, causing the write pointer to move on by the number of bytes required to represent the data type. The data is passed as a parameter to this function

Note

This method used to have two extra parameters repeats and repeats_is_register. They have been removed here. If you need them, use write_repeated_value()

Parameters:
  • data (int or float) – the data to write as a float.

  • data_type (DataType) – the type to convert data to

Raises:
  • ParameterOutOfBoundsException

    • If data_type is an integer type, and data has a fractional part

    • If data would overflow the data type

  • UnknownTypeException – If the data type is not known

  • ValueError – If the data size is invalid

  • NoRegionSelectedException – If no region has been selected

class spinn_front_end_common.interface.ds.DataSpecificationGenerator(x: int, y: int, p: int, vertex: AbstractGeneratesDataSpecification | AbstractRewritesDataSpecification, ds_db: DsSqlliteDatabase, report_writer=None)

Bases: DataSpecificationBase

Used to generate the data specification data in the database

Parameters:
  • x (int) –

  • y (int) –

  • p (int) –

  • vertex (AbstractRewritesDataSpecification) – The vertex being written.

  • report_writer (TextIOBase or None) – Determines if a text version of the specification is to be written and, if so, where. No report is written if this is None.

Raises:
  • DsDatabaseException – If this core is not known and no vertex supplied (during reload)

  • AttributeError – If the vertex is not an AbstractHasAssociatedBinary

  • KeyError – If there is no Chip as x, y

  • IntegrityError – If this combination of x, y, p has already been used Even if with the same vertex

reference_memory_region(region: int, ref: int, label: str | None = None)[source]

Insert command to reference another memory region.

Parameters:
  • region (int) – The number of the region to reserve, from 0 to 15

  • ref (int) – The identifier of the region to reference

  • label (str or None) – An optional label for the region

Raises:
  • RegionInUseException – If the region was already reserved

  • ParameterOutOfBoundsException – If the region requested was out of the allowed range, or the size was too big to fit in SDRAM

reserve_memory_region(region: int, size: int, label: str | None = None, reference: int | None = None)[source]

Insert command to reserve a memory region.

Parameters:
  • region (int) – The number of the region to reserve, from 0 to 32

  • size (int) – The size to reserve for the region, in bytes

  • label (str or None) – An optional label for the region

  • reference (int or None) – A globally unique reference for this region

Raises:
  • RegionInUseException – If the region was already reserved

  • ParameterOutOfBoundsException – If the region requested was out of the allowed range, or the size was too big to fit in SDRAM

class spinn_front_end_common.interface.ds.DataSpecificationReloader(x: int, y: int, p: int, ds_db: DsSqlliteDatabase, report_writer: TextIO | None = None)

Bases: DataSpecificationBase

Used to reload the data specification data

Parameters:

report_writer (TextIOBase or None) – Determines if a text version of the specification is to be written and, if so, where. No report is written if this is None.

reference_memory_region(region: int, ref: int, label: str | None = None)[source]

Insert command to reference another memory region.

Parameters:
  • region (int) – The number of the region to reserve, from 0 to 15

  • ref (int) – The identifier of the region to reference

  • label (str or None) – An optional label for the region

Raises:
  • RegionInUseException – If the region was already reserved

  • ParameterOutOfBoundsException – If the region requested was out of the allowed range, or the size was too big to fit in SDRAM

reserve_memory_region(region: int, size: int, label: str | None = None, reference: int | None = None)[source]

Insert command to reserve a memory region.

Parameters:
  • region (int) – The number of the region to reserve, from 0 to 32

  • size (int) – The size to reserve for the region, in bytes

  • label (str or None) – An optional label for the region

  • reference (int or None) – A globally unique reference for this region

Raises:
  • RegionInUseException – If the region was already reserved

  • ParameterOutOfBoundsException – If the region requested was out of the allowed range, or the size was too big to fit in SDRAM

class spinn_front_end_common.interface.ds.DataType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Enum

Supported data types. Internally, these are actually tuples.

  1. an identifier for the enum class;

  2. the size in bytes of the type;

  3. the minimum possible value for the type;

  4. the maximum possible value for the type;

  5. the scale of the input value to convert it in integer;

  6. the pattern to use following the struct package encodings to convert the data in binary format;

  7. is whether to apply the scaling when converting to SpiNNaker’s binary format.

  8. the corresponding numpy type (or None to inhibit direct conversion via numpy, scaled conversion still supported);

  9. the text description of the type.

Note

Some types (notably 64-bit fixed-point and floating-point types) are not recommended for use on SpiNNaker due to complications with represent them and lack of hardware/library support.

FLOAT_32: DataType = 14
FLOAT_64: DataType = 15
INT16: DataType = 5
INT32: DataType = 6
INT64: DataType = 7
INT8: DataType = 4
S015: DataType = 21
S031: DataType = 22
S063: DataType = 23
S07: DataType = 20
S1615: DataType = 12
S3231: DataType = 13
S87: DataType = 11
U016: DataType = 17
U032: DataType = 18
U064: DataType = 19
U08: DataType = 16
U1616: DataType = 9
U3232: DataType = 10
U88: DataType = 8
UINT16: DataType = 1
UINT32: DataType = 2
UINT64: DataType = 3
UINT8: DataType = 0
as_bytes(value: int | float) bytes[source]

Encode the Python value as bytes with NO padding.

Parameters:

value (float or int) –

Return type:

bytes

check_value(value: int | float)[source]

Check the value against the allowed min and max

Raises:

ValueError – If the value is outside of min to max

decode_array(values: ndarray[Any, dtype[_ScalarType_co]] | bytes) ndarray[Any, dtype[_ScalarType_co]][source]

Decodes a byte array into iterable of this type.

Parameters:

values – the bytes to decode into this given data type

Return type:

numpy array

decode_numpy_array(array: ndarray[Any, dtype[uint32]]) ndarray[Any, dtype[_ScalarType_co]][source]

Decode the numpy array of SpiNNaker values according to this type.

Parameters:

array (ndarray(uint32)) –

Return type:

ndarray(uint32 or float64)

encode_as_int(value: int | float) int[source]

Returns the value as an integer, according to this type.

Parameters:

value (float or int) –

Return type:

int

encode_as_numpy_int(value: int | float) uint32[source]

Returns the value as a numpy integer, according to this type.

Note

Only works with integer and fixed point data types.

Parameters:

value (float or int) –

Return type:

uint32

encode_as_numpy_int_array(array: ndarray[Any, dtype[_ScalarType_co]]) ndarray[Any, dtype[_ScalarType_co]][source]

Returns the numpy array as an integer numpy array, according to this type.

Parameters:

array (ndarray) –

Return type:

ndarray

property max: Decimal

The maximum possible value for the type.

Return type:

Decimal

property min: Decimal

The minimum possible value for the type.

Return type:

Decimal

property numpy_typename: type

The corresponding numpy type, if one exists.

property scale: Decimal

The scale of the input value to convert it in integer.

Return type:

Decimal

property size: int

The size in bytes of the type.

Return type:

int

property struct_encoding: str

The encoding string used for struct. Scaling may also be required.

Return type:

str

class spinn_front_end_common.interface.ds.DsSqlliteDatabase(database_file: str | None = None)

Bases: SQLiteDB

A database for holding data specification details.

Parameters:

init_file (bool) – Whether to initialise the DB from our DDL file. If not specified, this is guessed from whether we can read the file.

get_core_infos(is_system: bool) List[Tuple[int, int, int, int, int]][source]

Gets a list of id, x, y, p, ethernet_x, ethernet_y for all cores according to is_system

Parameters:

is_system (bool) – if True returns system cores otherwise application cores

Returns:

(x, y, p, ethernet_x, ethernet_y) for each system or app core

Return type:

list(int, int, int, int, int, int)

get_double_region() Iterable[Tuple[int, int, int, int]][source]
Finds and yields any region that was used in both region definition

and a reference

If all is well this method yields nothing!

Note

Do not use the database for anything else while iterating.

Returns:

x, y, p, region

Return type:

iterable(tuple(int, int, int, int))

get_ds_cores() Iterable[Tuple[int, int, int]][source]

Yields the x, y, p for the cores with possible Data Specifications

Includes cores where DataSpecs started even if no regions reserved

Yields nothing if there are no unknown cores

Note

Do not use the database for anything else while iterating.

Returns:

Yields the (x, y, p)

Return type:

iterable(tuple(int,int,int))

get_info_for_cores() Iterable[Tuple[Tuple[int, int, int], int, int, int]][source]

Yields the (x, y, p) and write info for each core

The sizes INCLUDE pointer table size

Yields nothing if no cores known

Note

A DB transaction may be held while this iterator is processing. Reentrant use of this class is not supported.

Returns:

Yields the (x, y, p), start_address, memory_used and memory_written

Return type:

iterable(tuple(tuple(int, int, int), int, int, int))

get_memory_to_malloc(x: int, y: int, p: int) int[source]

Gets the expected number of bytes to be written

Parameters:
  • x (int) – core X coordinate

  • y (int) – core Y coordinate

  • p (int) – core processor ID

Returns:

expected memory_written in bytes

Return type:

int

get_memory_to_write(x: int, y: int, p: int) int[source]

Gets the expected number of bytes to be written

Parameters:
  • x (int) – core X coordinate

  • y (int) – core Y coordinate

  • p (int) – core processor ID

Returns:

expected memory_written in bytes

Return type:

int

get_n_ds_cores() int[source]

Returns the number for cores there is a data specification saved for.

Includes cores where DataSpecs started even if no regions reserved

Return type:

int

Raises:

DsDatabaseException

get_reference_pointers(x: int, y: int, p: int) Iterable[Tuple[int, int]][source]

Yields the reference regions and where they point for this core

This may yield nothing if there are no reference pointers or if the core is not known

Note

Do not use the database for anything else while iterating.

Parameters:
  • x (int) – X coordinate of the core

  • y (int) – Y coordinate of the core

  • p (int) – Processor ID of the core

Returns:

Yields the referencing vertex region number and the pointer

Return type:

iterable(tuple(int,int))

get_region_pointer(x: int, y: int, p: int, region_num: int) int | None[source]

Gets the pointer for this region as set during the original load

returns None if the region is known but for some reason the pointer was not set

Parameters:
  • x (int) – X coordinate of the core

  • y (int) – Y coordinate of the core

  • p (int) – Processor ID of the core

  • region_num (int) – The Data Specification region number

Returns:

The pointer set during the original load

Return type:

int or None

Raises:

DsDatabaseException – if the region is not known

get_region_pointers_and_content(x: int, y: int, p: int) Iterable[Tuple[int, int, bytes | None]][source]

Yields the number, pointers and content for each reserved region

This includes regions with no content set where content will be None

Will yield nothing if there are no regions reserved or if the core if not known

Parameters:
  • x (int) – X coordinate of the core

  • y (int) – Y coordinate of the core

  • p (int) – Processor ID of the core

Returns:

number, pointer and (content or None)

Return type:

iterable(tuple(int, int, bytearray or None))

get_region_size(x: int, y: int, p: int, region_num: int) int[source]

Gets the size for a region with this x, y, p and region

Parameters:
  • x (int) – X coordinate of the core

  • y (int) – Y coordinate of the core

  • p (int) – Processor ID of the core

  • region_num (int) – The region number

Returns:

The size of the region, in bytes

Return type:

int

get_region_sizes(x: int, y: int, p: int) Dict[int, int][source]

Gets a dict of the regions and sizes reserved

The returned dict will be empty if there are no regions reserved or if the core is not known.

Parameters:
  • x (int) – X coordinate of the core

  • y (int) – Y coordinate of the core

  • p (int) – Processor ID of the core

Returns:

dict of region_num to size but only for regions with a size

Return type:

dict(int, int)

get_start_address(x: int, y: int, p: int) int[source]

Gets the start_address for this core

Parameters:
  • x (int) – X coordinate of the core

  • y (int) – Y coordinate of the core

  • p (int) – Processor ID of the core

Returns:

The base address for the whole core

Return type:

int

get_total_regions_size(x: int, y: int, p: int) int[source]

Gets the total size of the regions of this core

Does not include the size of the pointer table

Returns 0 even if the core is not known

Parameters:
  • x (int) – X coordinate of the core

  • y (int) – Y coordinate of the core

  • p (int) – Processor ID of the core

Returns:

The size of the regions or 0 if there are no regions for this core

Return type:

int

get_unlinked_references() Iterable[Tuple[int, int, int, int, int, str]][source]

Finds and yields info on unreferenced links

If all is well this method yields nothing!

Note

Do not use the database for anything else while iterating.

Returns:

x, y, p, region, reference, label for all unlinked references

Return type:

iterable(tuple(int, int, int, int, int, str))

set_app_id() None[source]

Sets the app id

set_core(x: int, y: int, p: int, vertex: AbstractHasAssociatedBinary)[source]

Creates a database record for the core with this x,y,z

Parameters:
  • x (int) – X coordinate of the core

  • y (int) – Y coordinate of the core

  • p (int) – Processor ID of the core

  • vertex (AbstractHasAssociatedBinary) – Vertex to check if it is a system vertex. if missing this method will not create a new record

Return type:

int

Raises:
  • AttributeError – If the vertex is not an AbstractHasAssociatedBinary

  • KeyError – If there is no Chip as x, y

  • IntegrityError – If this combination of x, y, p has already been used Even if with the same vertex

set_memory_region(x: int, y: int, p: int, region_num: int, size: int, reference: int | None, label: str | None)[source]

Writes the information to reserve a memory region into the database

Typically called after a DS.reserve_memory_region call

Parameters:
  • x (int) – X coordinate of the core

  • y (int) – Y coordinate of the core

  • p (int) – Processor ID of the core t

  • region_num (int) – The number of the region to reserve

  • size (int) – The size to reserve for the region, in bytes

  • label (str or None) – An optional label for the region

  • reference (int or None) – A globally unique reference for this region

Returns:

set_reference(x: int, y: int, p: int, region_num: int, reference: int, ref_label: str | None)[source]

Writes a outgoing region_reference into the database

Parameters:
  • x (int) – X coordinate of the core

  • y (int) – Y coordinate of the core

  • p (int) – Processor ID of the core

  • region_num (int) – The region number

  • reference (int) – The number of the reference on this core

  • ref_label (str or None) – label for the referencing region

set_region_content(x: int, y: int, p: int, region_num: int, content: bytes, content_debug: str | None)[source]

Sets the content for this region

Parameters:
  • x (int) – X coordinate of the core

  • y (int) – Y coordinate of the core

  • p (int) – Processor ID of the core

  • region_num (int) – The region number

  • content (bytes) – content to write

  • content_debug (str or None) – debug text

Raises:

DsDatabaseException – If the region already has content

set_region_pointer(x: int, y: int, p: int, region_num: int, pointer: int)[source]

Sets the pointer to the start of the address for this x, y, p region.

Parameters:
  • x (int) –

  • y (int) –

  • p (int) –

  • region_num (int) –

  • pointer (int) – start address

set_start_address(x: int, y: int, p: int, start_address: int)[source]

Sets the base address for a core and calculates pointers

Parameters:
  • x (int) – X coordinate of the core

  • y (int) – Y coordinate of the core

  • p (int) – Processor ID of the core

  • start_address (int) – The base address for the whole core

Raises:

DsDatabaseException – if the region is not known

write_session_credentials_to_db() None[source]

Write Spalloc session credentials to the database, if in use.