mapping#

This module contains methods to map a given network to the chip.

class sinabs.backend.dynapcnn.mapping.FlowGraphEdge(s: int, t: int, cap: int, flow: int = 0, rev: ForwardRef('FlowGraphEdge') | None = None)[source]#
Parameters:
  • s (int)

  • t (int)

  • cap (int)

  • flow (int)

  • rev (FlowGraphEdge | None)

class sinabs.backend.dynapcnn.mapping.LayerConstraints(kernel_memory: int, neuron_memory: int, bias_memory: int)[source]#
Parameters:
  • kernel_memory (int)

  • neuron_memory (int)

  • bias_memory (int)

sinabs.backend.dynapcnn.mapping.edmonds(graph: List[List[FlowGraphEdge]], source: int, sink: int, verbose: bool = False) List[List[FlowGraphEdge]][source]#

Use Edmonds’ Algorithm to compute flow of flow graph

Makes a copy of the graph. The original graph is not changed in place.

Parameters:
  • List[List[FlowGraphEdge]]) (graph) – Flow graph representation. Each list entry corresponds to a node and consists of a list holding the outgoing edges from this node.

  • source (int) – Index of source node within graph.

  • sind (int) – Index of sink node within graph.

  • verbose (bool) – Print detailed flow information if True.

  • graph (List[List[FlowGraphEdge]])

  • sink (int)

Returns:

New flow graph with calculated flow. Type is List[List[FlowGraphEdge]].

Return type:

List[List[FlowGraphEdge]]

sinabs.backend.dynapcnn.mapping.find_chip_layers(layer: DynapcnnLayer, constraints: List[LayerConstraints]) List[int][source]#

Find all layers where a given layer configuration fits.

Parameters:
Returns:

A list of indices of layers where the given layer fits.

Return type:

List[int]

sinabs.backend.dynapcnn.mapping.get_valid_mapping(layers: Dict[int, DynapcnnLayer], constraints: List[LayerConstraints]) Dict[int, int][source]#

Given a model, find a valid layer ordering for its placement within the constraints provided.

Parameters:
  • layers (Dict[int, DynapcnnLayer]) – Dict with layer indices as keys and DynapcnnLayer instances as values.

  • constraints (List[LayerConstraints]) – A list of all the layer’s constraints.

Returns:

Dict mapping from layer index (key) to assigned core ID (value).

Return type:

Dict[int, int]

sinabs.backend.dynapcnn.mapping.make_flow_graph(layer_mapping: List[List[int]], num_layers: int = 9) List[List[FlowGraphEdge]][source]#

Make a bipartite flow graph (flow network) given all possible chip layers for each DynapCNNLayer layer. The goal is to formulate the mapping from DynapCNNLayer instance to chip layer as a bipartite matching problem. Note that the flows are not computed yet. The flow for the graph generated here needs to be populated by calling the method edmonds.

Parameters:
  • layer_mapping (List[List[int]]) – List of a list of matching chip core indices for each DynapCNNLayer instance. Eg. [[1,3], [4, 6, 1]] for a two layer model, where each integer is a core index.

  • num_layers (int) – Number of layers on the chip.

Returns:

Flow graph representation. Each list entry corresponds to a node and consists of a list holding the outgoing edges from this node. The returned object is of type List[List[FlowGraphEdge]].

Return type:

List[List[FlowGraphEdge]]

sinabs.backend.dynapcnn.mapping.recover_mapping(graph: List[List[FlowGraphEdge]], num_layers: int) List[int][source]#

Based on the flow graph retrieve a layer-to-core mapping

Parameters:
  • List[List[FlowGraphEdge]]) (graph) – Flow graph representation with flow calculated. Each list entry corresponds to a node and consists of a list holding the outgoing edges from this node.

  • num_layers (int) – Number of software layers.

  • graph (List[List[FlowGraphEdge]])

Returns:

Assigned core IDs for each layer in order. Type is List[int].

Return type:

List[int]