-
Notifications
You must be signed in to change notification settings - Fork 15
Allocate cgra to task #307
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
guosran
wants to merge
7
commits into
main
Choose a base branch
from
feature/allocate-cgra-to-task
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.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e04726c
Refactor: replace MapTaskOnCgra with AllocateCgraToTask pass supporti…
guosran 48f77a9
Updated test
guosran 3b22adf
Apply LLVM style: add braces for single-statement if/return blocks
guosran 2368a2b
Restore documentation comments and resolve user review annotations
guosran 338643f
Rename DFS variables for clarity; update Zeonica_Testbench submodule …
guosran ad979ff
Revert Zeonica_Testbench submodule to same commit as main (62389ec)
guosran 4ca8630
Move CGRA allocation utilities to a dedicated Allocation directory
guosran File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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 |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| //===- allocation_utils.h - Shared CGRA allocation utilities --------------===// | ||
| // | ||
| // Shared utility types and functions used by AllocateCgraToTaskPass and | ||
| // ResourceAwareTaskOptimizationPass for CGRA grid placement feasibility | ||
| // checks and task-to-CGRA mapping. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef TASKFLOW_ALLOCATION_UTILS_H | ||
| #define TASKFLOW_ALLOCATION_UTILS_H | ||
|
|
||
| #include "mlir/Dialect/Func/IR/FuncOps.h" | ||
| #include "llvm/ADT/SmallVector.h" | ||
|
|
||
| namespace mlir { | ||
| namespace taskflow { | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // Grid constants | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| constexpr int kCgraGridRows = 4; | ||
| constexpr int kCgraGridCols = 4; | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // CgraShape | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| // Represents a CGRA allocation shape on the grid. | ||
| // | ||
| // For rectangular shapes: rows × cols == cgra_count, and `cgra_positions` | ||
| // is empty (all cells in the bounding box are used). | ||
| // | ||
| // For non-rectangular shapes (L, T): `cgra_positions` stores the explicit | ||
| // (col, row) coordinates of the occupied CGRAs. `rows`/`cols` give the | ||
| // bounding box so that tile-level x_tiles/y_tiles can be computed. | ||
| struct CgraShape { | ||
| int rows; // Bounding-box CGRA rows. | ||
| int cols; // Bounding-box CGRA columns. | ||
| bool is_rectangular; // True if all cells in the bbox are used. | ||
| // Explicit CGRA positions for non-rectangular shapes. | ||
| // Each pair is (col, row) in CGRA coordinates. Empty for rectangles. | ||
| llvm::SmallVector<std::pair<int, int>> cgra_positions; | ||
|
|
||
| // Returns the bounding-box area (rows * cols). For rectangular shapes this | ||
| // equals cgra_count; for non-rectangular shapes it is larger than cgra_count | ||
| // (some cells in the bbox are unoccupied). Used only for shape sorting | ||
| // (prefer smaller bounding boxes), not for counting occupied CGRAs. | ||
| int area() const { return rows * cols; } | ||
|
|
||
| // Returns a human-readable description for log messages only (not IR). | ||
| std::string describe(int cgra_count) const; | ||
|
|
||
| // Returns the shape string written into the IR tile_shape attribute. | ||
| // For rectangular shapes: "NxM" (e.g. "2x2"). | ||
| // For non-rectangular shapes: "NxM[(c0,r0)(c1,r1)...]" listing only the | ||
| // occupied CGRA positions so that downstream passes can reconstruct the | ||
| // exact valid tile set for multi-CGRA mapping. | ||
| std::string irAttr() const; | ||
| }; | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // Shape Enumeration Utilities | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| // Generates all placement-candidate shapes for `cgra_count` CGRAs, including | ||
| // rotations. Rectangular shapes include both orientations (rows×cols and | ||
| // cols×rows, deduplicated for squares). Non-rectangular shapes include all | ||
| // four 90° rotations. | ||
| // | ||
| // Ordering (tried first to last): | ||
| // 1. Rectangular shapes, sorted by squareness (e.g. 2×2 before 1×4), | ||
| // with smaller bounding-box area as tiebreaker. | ||
| // 2. Non-rectangular shapes (L, T, etc.) in all unique rotations. | ||
| llvm::SmallVector<CgraShape> getAllPlacementShapes(int cgra_count); | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // Global Placement Feasibility | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| // Simulates greedy placement of all tasks' shapes on the kCgraGridRows × | ||
| // kCgraGridCols grid to verify that they physically fit without overlap. | ||
| // | ||
| // For each task, all valid shapes (including rotations) are tried. Rectangular | ||
| // shapes prefer square-like orientations (e.g. 2×2 over 1×4). Non-rectangular | ||
| // shapes are tried in all four 90° rotations. | ||
| // | ||
| // `task_cgra_counts` contains the cgra_count for every task in the graph | ||
| // (including the speculatively modified one). | ||
| // | ||
| // Returns true if all tasks can be placed without overlap. | ||
| bool canAllTasksFitOnGrid(llvm::ArrayRef<int> task_cgra_counts); | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // Direct Pass Invocation | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| // Runs the CGRA task placement logic directly on a function, producing | ||
| // `task_mapping_info` attributes with global grid placement that respects | ||
| // multi-CGRA shapes. | ||
| // | ||
| // grid_rows/grid_cols default to 4x4 (kCgraGridRows/kCgraGridCols). | ||
| // | ||
| // Defined in lib/TaskflowDialect/Util/AllocateCgraTaskMapper.cpp. | ||
| void runAllocateCgraToTask(mlir::func::FuncOp func, | ||
| int grid_rows = kCgraGridRows, | ||
| int grid_cols = kCgraGridCols); | ||
|
|
||
| } // namespace taskflow | ||
| } // namespace mlir | ||
|
|
||
| #endif // TASKFLOW_CGRA_PLACEMENT_UTILS_H |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| add_mlir_library(MLIRTaskflowAllocation | ||
| allocation_utils.cpp | ||
| allocation_utils_mapper.cpp | ||
|
|
||
| DEPENDS | ||
| MLIRTaskflowTransformsIncGen | ||
|
|
||
| LINK_LIBS PUBLIC | ||
| MLIRIR | ||
| MLIRPass | ||
| MLIRSupport | ||
| MLIRFuncDialect | ||
| MLIRTaskflow | ||
| LLVMSupport | ||
| ) |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do fusion candidates mean?