- Notifications
You must be signed in to change notification settings - Fork161
[WIP] Stateful Destructive Device Slicing#2726
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Changes from1 commit
97abe9b566898e481cd6670f7293efaa9053ff34871ec292323341cba6f860ce34b2762d42d0edc54360File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -11,32 +11,24 @@ | ||
| from ... import ir # type: ignore | ||
| from ...dialects._aie_enum_gen import WireBundle # type: ignore | ||
| from ...dialects.aie import AIEDevice, tile, get_target_model # type: ignore | ||
| from ..resolvable import Resolvable | ||
| from .tile import Tile | ||
| import re | ||
| class DeviceLike(Resolvable): | ||
| class __DeviceTile(Tile, Resolvable): | ||
| """ | ||
| Interior class for tiles objects owned by a particular device. | ||
| This is needed to ensure we don't generate more than one MLIR operation corresponding | ||
| to the same logical tile within a device. | ||
| """ | ||
| def __init__(self, col: int, row: int) -> None: | ||
| Tile.__init__(self, col, row) | ||
| Resolvable.__init__(self) | ||
| def resolve( | ||
| self, | ||
| @@ -46,55 +38,28 @@ def resolve( | ||
| ) -> None: | ||
| if self._op == None: | ||
| self._op = tile( | ||
| self.col, | ||
| self.row, | ||
| loc=loc, | ||
| ip=ip, | ||
| allocation_scheme=allocation_scheme, | ||
| ) | ||
| def __init__( | ||
| self, device: AIEDevice, tiles: list[list[Tile]] | None = None | ||
| ) -> None: | ||
| self._device = device | ||
| self._tm = get_target_model(device) | ||
| if tiles is None: | ||
| self._tiles: list[list[DeviceLike.__DeviceTile]] = [] | ||
| for c in range(self._tm.columns()): | ||
| self._tiles.append([]) | ||
| for r in range(self._tm.rows()): | ||
| self._tiles[c].append(DeviceLike.__DeviceTile(c, r)) | ||
| else: | ||
| self._tiles = tiles | ||
| self.ncols = len(self._tiles) | ||
| self.nrows = len(self._tiles[0]) if self.ncols else 0 | ||
| def get_shim_tiles(self) -> list[Tile]: | ||
| """Returns a list of all shim tiles on the device. | ||
| @@ -103,9 +68,9 @@ def get_shim_tiles(self) -> list[Tile]: | ||
| list[Tile]: A list of shim tiles. | ||
| """ | ||
| return [ | ||
| t | ||
| for t in self.tile_iterator() | ||
| if self._tm.is_shim_noc_or_pl_tile(t.col, t.row) | ||
| ] | ||
| def get_mem_tiles(self) -> list[Tile]: | ||
| @@ -114,11 +79,7 @@ def get_mem_tiles(self) -> list[Tile]: | ||
| Returns: | ||
| list[Tile]: A list of mem tiles. | ||
| """ | ||
| return [t for t in self.tile_iterator() if self._tm.is_mem_tile(t.col, t.row)] | ||
| def get_compute_tiles(self) -> list[Tile]: | ||
| """Returns a list of all compute tiles on the device. | ||
| @@ -127,9 +88,9 @@ def get_compute_tiles(self) -> list[Tile]: | ||
| list[Tile]: A list of compute tiles. | ||
| """ | ||
| return [ | ||
| Tile(t.col, t.row) | ||
hunhoffe marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| for t in self.tile_iterator() | ||
| if self._tm.is_core_tile(t.col, t.row) | ||
| ] | ||
| def get_num_source_switchbox_connections(self, t: Tile) -> int: | ||
| @@ -197,37 +158,129 @@ def is_legal_mem_affinity(self, src_tile: Tile, dst_tile: Tile) -> bool: | ||
| int: Number of connections (channels) available on the tile | ||
| """ | ||
| return self._tm.is_legal_mem_affinity( | ||
| src_tile.col, src_tile.row, dst_tile.col, dst_tile.row | ||
| ) | ||
| def resolve( | ||
| self, | ||
| loc: ir.Location | None = None, | ||
| ip: ir.InsertionPoint | None = None, | ||
| ) -> None: | ||
| return self._device | ||
| def resolve_tile( | ||
| self, | ||
| tile: Tile, | ||
| loc: ir.Location | None = None, | ||
| ip: ir.InsertionPoint | None = None, | ||
| ): | ||
| self._tiles[tile.col][tile.row].resolve( | ||
| loc, ip, getattr(tile, "allocation_scheme", None) | ||
| ) | ||
| tile.op = self._tiles[tile.col][tile.row].op | ||
| def tile_iterator(self) -> Generator[Tile, None, None]: | ||
| """ | ||
| Iterates over the available device tiles deterministically | ||
| """ | ||
| for c in range(self._tm.columns()): | ||
| for r in range(self._tm.rows()): | ||
| yield self._tiles[c][r] | ||
| class DeviceView(DeviceLike): | ||
| def __init__(self, device: "Device", tiles: list[Tile]): | ||
| super().__init__(device=device._device, tiles=tiles) | ||
| self._device_instance = device | ||
| self._coords = set() | ||
| for col in tiles: | ||
| for t in col: | ||
hunhoffe marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| self._coords.add((t.col, t.row)) | ||
| def tile_iterator(self) -> Generator[Tile, None, None]: | ||
| # Keep ordering consistent from the device we sliced from. | ||
| for c in range(len(self._tiles)): | ||
| for r in range(len(self._tiles[0])): | ||
| yield self._tiles[c][r] | ||
| class Device(DeviceLike): | ||
| """ | ||
| A base class for representations of a device of a specific type. | ||
| """ | ||
| def __init__(self, device: AIEDevice) -> None: | ||
| """Initialize a representation of a device. | ||
| Args: | ||
| device (AIEDevice): aie device | ||
| """ | ||
| super().__init__(device=device) | ||
| self._claimed_tiles = set() | ||
| def __getitem__(self, key): | ||
| if isinstance(key, tuple): | ||
| if len(key) > 2: | ||
| raise IndexError("Only 2D slicing is supported for devices.") | ||
| if len(key) == 2: | ||
| col_slice, row_slice = key | ||
| else: | ||
| col_slice, row_slice = key[0], slice(None, None, None) | ||
| elif isinstance(key, (int, slice)): | ||
| col_slice, row_slice = key, slice(None, None, None) | ||
| else: | ||
| raise IndexError( | ||
| "Device indices must be integers, slices, or a 2-tuple of those." | ||
| ) | ||
| if isinstance(col_slice, int) and isinstance(row_slice, int): | ||
| if col_slice >= self._tm.columns() or row_slice >= self._tm.rows(): | ||
| raise IndexError("Tile index out of range.") | ||
| # Handle slices and integers for cols | ||
| if isinstance(col_slice, int): | ||
| cols = [col_slice] | ||
| else: | ||
| cols = range(self._tm.columns())[col_slice] | ||
| # Handle slices and integers for rows | ||
| if isinstance(row_slice, int): | ||
| rows = [row_slice] | ||
| else: | ||
| rows = range(self._tm.rows())[row_slice] | ||
| if not cols or not rows: | ||
| return DeviceView(self, []) | ||
| tiles_to_claim = [] | ||
| coords_to_claim = set() | ||
| for c in cols: | ||
| tiles_to_claim.append([]) | ||
| for r in rows: | ||
| if (c, r) in self._claimed_tiles: | ||
| raise ValueError(f"Tile ({c}, {r}) has already been claimed.") | ||
| coords_to_claim.add((c, r)) | ||
| tiles_to_claim[-1].append(self._tiles[c][r]) | ||
| self._claimed_tiles.update(coords_to_claim) | ||
| return DeviceView(self, tiles_to_claim) | ||
| def tile_iterator(self) -> Generator[Tile, None, None]: | ||
| for t in super().tile_iterator(): | ||
| if (t.col, t.row) not in self._claimed_tiles: | ||
| yield self._tiles[t.col][t.row] | ||
| def create_class(class_name, device): | ||
| def _device__init__(self) -> None: | ||
| super(globals()[class_name], self).__init__(device=device) | ||
| globals()[class_name] = type( | ||
| class_name, | ||
| (Device,), | ||
| { | ||
| "__init__": _device__init__, | ||
| "__doc__": f"A representation of a device that resolves to {device}", | ||
| }, | ||
| ) | ||
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.