xbtorch.deployment.mapping

Crossbar mapping utilities for weight placement.

This module provides helper functions for mapping software weight matrices onto physical crossbar subarrays in simulation. Proper mapping ensures that each weight matrix fits within the hardware dimensions and does not overlap with previously placed matrices.

Functions

  • check_overlap() : Check whether two mapped submatrices overlap.

  • map_random() : Randomly assign non-overlapping positions for weight matrices on the simulated chip.

Notes

Mapping is a critical part of hardware-aware simulation, as overlapping placements would result in invalid or conflicting conductance states.

Functions

check_overlap(start1, shape1, start2, shape2)

Check if two submatrices overlap in the crossbar array.

map_random(accelerator, layer_shape[, beta, ...])

Randomly map a weight matrix to non-overlapping locations on a crossbar array.

xbtorch.deployment.mapping.check_overlap(start1, shape1, start2, shape2)[source]

Check if two submatrices overlap in the crossbar array.

Parameters:
  • start1 (tuple[int, int]) – Starting index (row, col) of the first submatrix.

  • shape1 (tuple[int, int]) – Shape (rows, cols) of the first submatrix.

  • start2 (tuple[int, int]) – Starting index (row, col) of the second submatrix.

  • shape2 (tuple[int, int]) – Shape (rows, cols) of the second submatrix.

Returns:

True if the submatrices overlap, False otherwise.

Return type:

bool

Examples

>>> check_overlap((0, 0), (2, 2), (1, 1), (2, 2))
True
>>> check_overlap((0, 0), (2, 2), (3, 3), (2, 2))
False
xbtorch.deployment.mapping.map_random(accelerator, layer_shape, beta=1, current_mappings=[])[source]

Randomly map a weight matrix to non-overlapping locations on a crossbar array.

Each weight matrix is mapped onto the simulated accelerator’s chip at random valid positions. Multiple redundant mappings can be requested (via beta) for ensemble or fault-tolerant encoding.

Parameters:
  • accelerator (GenericAccelerator) – The accelerator instance containing chip dimensions (rows, columns).

  • layer_shape (tuple[int, int]) – Shape (rows, cols) of the layer to map.

  • beta (int, optional) – Number of redundant mappings to generate (default: 1).

  • current_mappings (list[tuple[tuple[int, int], tuple[int, int]]], optional) – Existing mappings to ensure no overlaps are introduced. Each entry is ((start_row, start_col), (rows, cols)).

Returns:

List of starting indices (row, col) for each mapping.

Return type:

list[tuple[int, int]]

Raises:

ValueError – If the layer does not fit in the array dimensions or if no valid non-overlapping placement is found after the maximum number of attempts.

Notes

  • The number of attempts is capped by _MAX_ATTEMPTS (default: 1000).

  • Ensures that newly placed layers do not overlap with existing mapped regions.