- 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
Draft
hunhoffe wants to merge12 commits intomainChoose a base branch fromdevice-slicer
base:main
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
Uh oh!
There was an error while loading.Please reload this page.
Draft
Changes fromall commits
Commits
Show all changes
12 commits Select commitHold shift + click to select a range
97abe9b initial device slicing code
hunhoffe566898e revert unnecessary changes
hunhoffe481cd66 remove cores per column placer option
hunhoffe70f7293 Merge branch 'main' into device-slicer
hunhoffeefaa905 add more placer tests; not working yet, I don't think
hunhoffe3ff3487 update a test
hunhoffe1ec2923 Merge branch 'main' into device-slicer
hunhoffe23341cb Update python/iron/device/device.py
hunhoffea6f860c Merge branch 'main' into device-slicer
hunhoffee34b276 Update python/iron/program.py
hunhoffe2d42d0e Merge branch 'main' into device-slicer
hunhoffedc54360 Merge branch 'main' into device-slicer
hunhoffeFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -9,32 +9,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, | ||
| @@ -44,55 +36,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. | ||
| @@ -101,9 +66,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]: | ||
| @@ -112,11 +77,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. | ||
| @@ -125,9 +86,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: | ||
| @@ -237,29 +198,114 @@ def resolve_tile( | ||
| 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_tiles in tiles: | ||
| for t in col_tiles: | ||
| 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}", | ||
| }, | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.