feat: add fused_MHA_systolic example - #581
Open
RuizeYu05 wants to merge 6 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new example implementation and testbench for a fused MHA systolic-array dataflow design (with int8 quantization and online softmax) in Allo.
Changes:
- Introduces
get_systolic_top(...)dataflow region implementing the fused MHA systolic kernel. - Adds a numerical-correctness testbench comparing simulator output against a NumPy golden reference and optionally running Vitis HLS synthesis.
- Adds example package scaffolding for
examples/fused_MHA_systolic.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| examples/fused_MHA_systolic/fused_MHA_systolic.py | New fused MHA systolic dataflow kernel generator (get_systolic_top). |
| examples/fused_MHA_systolic/test_systolic.py | New testbench for simulator correctness + optional HLS synthesis. |
| examples/fused_MHA_systolic/init.py | Package init with license header. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
This request's central contribution is a fused MHA systolic array. Our design is a pure dataflow description in Allo dataflow programming. We re-architect the algorithm-to-hardware mapping so that the entire FlashAttention loop fits a strictly unidirectional, feedback-free dataflow with one tc block per PE column. We additionally apply SageAttention( https://arxiv.org/abs/2410.02367), a quantization method that preserves precision under 8-bit quantization, to save resources.
Problems
Using online softmax we can fuse the self-attention calculation into one single pass. Is it possible to implement it in a pure dataflow architecture? Cascading two systolic arrays does not seem to be the optimal implementation.
Proposed Solutions
The kernel routes three concurrent streams through a block_T * block_T PE array. The query$Q$ and the FlashAttention state $(m, d, \mathbf{O})$ enter from the left boundary and propagate strictly rightward in lockstep, with each PE forwarding both to its right neighbour after one use. The key and value blocks $K$ and $V$ enter from the top and propagate downward, where column $j$ is statically bound to tc block j-1: column1 owns the first block_T keys, column2 the next block_T, and so on. Each compute PE iterates over its assigned $tc$ block, computing $\mathbf{q}\cdot\mathbf{k}$ , applying the online softmax update against the incoming state, and accumulating $V$ into $\mathbf{O}$ before passing the updated state right and $K{,}V$ down. State traverses the array exactly once, so the channel graph is acyclic and no feedback FIFOs are required.
Examples
This is an example
Checklist
Please make sure to review and check all of these items: