-
Notifications
You must be signed in to change notification settings - Fork 14
Optimize spatial-temporal heuristic and reduce II for multiple kernels #222
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
Conversation
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.
Pull request overview
This PR optimizes the spatial-temporal mapping heuristic for CGRA (Coarse-Grained Reconfigurable Architecture) compilation, achieving significant Initiation Interval (II) reductions across multiple benchmarks. The optimization introduces degree-based operation scheduling, adaptive link congestion penalties, and deterministic tie-breaking to improve mapping quality and test stability.
Key changes:
- Implements degree-based priority scheduling to map high-connectivity operations first
- Adds adaptive quadratic penalty for link congestion to avoid routing bottlenecks
- Introduces stable tie-breaking logic for consistent mapping results across executions
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
lib/NeuraDialect/Mapping/mapping_util.cpp |
Core algorithm changes: degree-based sorting in flatten_level_buckets() and adaptive congestion penalty in calculateAward() |
MAPPING_OPTIMIZATION_SUMMARY.md |
New documentation summarizing performance improvements and algorithm changes |
test/neura/fusion/test.mlir |
Updated II expectation from 13→12 (note: description claims 11) |
test/controflow_fuse/simple_loop_reduction/simple_loop_reduction.mlir |
Updated II expectation from 4→3 |
test/controflow_fuse/perfect_nested/perfect_nested.mlir |
Updated II expectation from 10→8 (note: description claims different baseline) |
test/code_gen/test_code_generate.mlir |
Updated II expectation from 5→4 with detailed mapping output changes |
test/c2llvm2mlir/nested_loop/test.mlir |
Updated II expectation from 13→11 |
| Multiple test files | Updated mapping expectations reflecting new operation placement strategies |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Pull request overview
Copilot reviewed 15 out of 15 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
9ae899b to
b1b1297
Compare
8fa2071 to
8ea76f4
Compare
|
The previous commits used non-deterministic representations for some IIs, for the mapping was not stable, and some of the IIs stated in the description are due to coincidence. I'm sorry for the confusion. The Solution: Changed std::sort() to std::stable_sort(). However, the mapping became even messier :( I will try to figure out the problem tmr :( |
This commit introduces significant performance improvements to the spatial-temporal mapping algorithm by implementing degree-based operation scheduling and link congestion awareness. Key improvements: - Implemented degree-based priority scheduling in flatten_level_buckets() - Operations are now sorted by connectivity (fan-in + fan-out) within each ALAP level - High-degree operations get mapped first, securing optimal placements - Added stable tie-breaking to ensure deterministic results - Added balanced link congestion penalty in calculateAward() - Quadratic penalty based on incoming/outgoing link occupancy - Guides mapper away from congested areas without over-constraining - Improved sorting stability with time-step tie-breaking - Minimizes non-deterministic mapping variations in tests Performance results: - fusion/test.mlir: II reduced from 13 to 11 (-15.4%) - nested_loop/test.mlir: II reduced from 13 to 11 (-15.4%) - code_gen/test_code_generate.mlir: II reduced from 5 to 4 (-20%) - All other tests maintain or improve their II Test updates: - Updated test expectations for improved II values - nested_loop/test.mlir: updated CHECK-LLVM2NEURA-MAP to expect II=11 - fusion/test.mlir: updated CHECK-MAPPING to expect II=11 Files modified: - lib/NeuraDialect/Mapping/mapping_util.cpp - test/c2llvm2mlir/nested_loop/test.mlir - test/neura/fusion/test.mlir - MAPPING_OPTIMIZATION_SUMMARY.md (new documentation)
Further improved the link congestion penalty by: 1. Increased penalty coefficient from 10 to 50 2. Added fan-in-based scaling: penalty *= (1 + num_producers) - Operations with more data dependencies are more sensitive to congestion - This prevents high-fanin ops from being placed in bottleneck areas Performance improvements: - fusion/test.mlir: II reduced from 13 to 11 (-15.4%) - nested_loop/test.mlir: II reduced from 13 to 11 (-15.4%) - code_gen/test_code_generate.mlir: II reduced from 5 to 4 (-20%) Test status: - 71/83 tests passing (85.54%) - Remaining failures are due to detailed mapping layout changes (PE positions, register allocations) which are expected when scheduling order changes - Core II improvements are verified and consistent
… penalty Implements core mapping optimizations to reduce Initiation Interval (II): 1. Degree-based priority scheduling: Maps high-connectivity nodes first. 2. Adaptive Congestion Penalty: - High fan-in ops (>=3 producers): Strong penalty (coeff 60) to avoid congestion. - Low fan-in ops: Weak penalty (coeff 15) to allow dense packing. Performance improvements: - fusion/test.mlir (fuse-pattern): II 13 -> 12 (-7.7%) - fusion/test.mlir (iter-merge): II 12 -> 12 (No regression) - nested_loop/test.mlir: II 13 -> 11 (-15.4%) - code_gen/test_code_generate.mlir: II 5 -> 4 (-20%) Tests updated: - Updated expectations for fusion, nested_loop, code_gen, and branch_for. - Remaining test failures are due to benign mapping layout changes.
Addresses PR #222 / Issue #221 feedback from tancheng. Problem: Within same ALAP level, high-degree non-critical ops were mapped before low-degree critical ops, causing routing congestion and suboptimal II. Solution: Modified flatten_level_buckets() to use criticality as PRIMARY sorting criterion within each ALAP level: Priority 1: Criticality (critical ops first) Priority 2: Degree (higher degree first within category) Priority 3: Original index (stability) Conservative implementation: Only reorders within levels, preserves ALAP level boundaries and overall scheduling. Results: - bicg: II 11 → 10 (-1 cycle) - test_code_generate: II 5 → 4 (-1 cycle) - Other tests: stable (no regressions) Modified files: - include/NeuraDialect/Mapping/mapping_util.h - lib/NeuraDialect/Mapping/mapping_util.cpp - lib/NeuraDialect/Transforms/MapToAcceleratorPass.cpp - test/e2e/bicg/bicg_kernel.mlir (updated FileCheck)
- Update 5 failing tests to match new mapping results from critical path optimization - test_code_generate.mlir: II improved from 5→4, full MAPPING (72 lines) + YAML + ASM - bicg_kernel.mlir: II improved from 13→10, full MAPPING (217 lines) + YAML/ASM (40 lines) - histogram_kernel.mlir: Full MAPPING (46 lines) with regex for module attributes + YAML/ASM (40 lines) - relu_kernel.mlir: Full MAPPING (59 lines) + complete YAML (527 lines) + ASM (104 lines) - branch_for.mlir: Simple MAPPING check + YAML/ASM (40 lines) - All tests now pass: 80/83 (96.39%), 3 expectedly failed - No II performance regressions confirmed
37e7fe6 to
d12394d
Compare
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.
Pull request overview
Copilot reviewed 17 out of 17 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
progress up to now in terms of
|
- Implement Critical Path First heuristic in MapToAcceleratorPass - Sort by Critical > Materialized > Degree > Topological dfg_id - Amplify proximity and time bonuses for critical ops - Update all failing tests with new deterministic mapping output - Improve test stability by fixing non-deterministic tie-breakers
ca37249 to
72257d9
Compare
…r k*; rename congestion penalty constants
72257d9 to
82f0cdb
Compare
…nused next_time variable
Description
This PR addresses issue #221. It improves the spatial-temporal mapping quality by implementing degree-based operation scheduling and an adaptive link congestion penalty. These changes allow the mapper to find more efficient placements for critical nodes and reduce the overall
compiled_iifor several complex kernels.Key Algorithmic Improvements:
Degree-Based Priority Scheduling:
Operations within each ALAP (As-Late-As-Possible) level are now sorted by their connectivity (total degree: fan-in + fan-out). High-degree operations are prioritized for placement, ensuring that nodes with the most routing constraints secure optimal physical resources early in the mapping process.
Adaptive Link Congestion Penalty:
A quadratic penalty term based on link occupancy has been integrated into the
calculateAwardcost function. This guides the mapper to automatically avoid congested areas of the CGRA fabric, preventing routing bottlenecks that previously led to higher II.Deterministic Tie-Breaking:
Stable tie-breaking logic using time-steps and degrees has been introduced. This ensures that the mapping results are consistent across different machines and parallel test executions, eliminating "flaky" test failures.
Results:
simple_loop_reduction.mlirtest_code_generate.mlirperfect_nested.mlirnested_loop/test.mlirfusion/test.mlir