Comments (4)
Yeah so this is the code before the pass:
module {
func.func @kernel(%arg0: memref<20xi32>) -> i32 attributes {itypes = "s", otypes = "s", top} {
%c0_i32 = arith.constant 0 : i32
%alloc = memref.alloc() {name = "sum"} : memref<1xi32>
affine.store %c0_i32, %alloc[0] {to = "sum"} : memref<1xi32>
affine.for %arg1 = 0 to 20 {
%1 = affine.load %arg0[%arg1] {from = "A"} : memref<20xi32>
%2 = affine.load %alloc[0] {from = "sum"} : memref<1xi32>
%3 = arith.addi %2, %1 : i32
affine.store %3, %alloc[0] {to = "sum"} : memref<1xi32>
} {loop_name = "i", op_name = "S_i_0", reduction}
%0 = affine.load %alloc[0] {from = "sum"} : memref<1xi32>
return %0 : i32
}
}
and this is the code after the pass:
module {
func.func @kernel(%arg0: memref<20xi32>) -> i32 attributes {itypes = "s", otypes = "s", top} {
%c0_i32 = arith.constant 0 : i32
%alloc = memref.alloc() {name = "sum"} : memref<1xi32>
affine.store %c0_i32, %alloc[0] {to = "sum"} : memref<1xi32>
%0 = affine.load %alloc[0] {from = "sum"} : memref<1xi32>
%1 = affine.for %arg1 = 0 to 20 iter_args(%arg2 = %0) -> (i32) {
%3 = affine.load %arg0[%arg1] {from = "A"} : memref<20xi32>
%4 = arith.addi %arg2, %3 : i32
affine.yield %4 : i32
}
affine.store %1, %alloc[0] : memref<1xi32>
%2 = affine.load %alloc[0] {from = "sum"} : memref<1xi32>
return %2 : i32
}
}
you can see the load and store on sum have been removed and replaced with iter_args and an affine.yield. The sum memref should then be able to be removed entirely using store-load forwarding.
from allo.
I agree that generating iteration variables may be helpful for some compiler passes. However, it is somehow not an easy job to determine whether a variable is a reduction variable from the frontend, so we currently do not support this feature. The allo.reduction
function is just an annotation, and it does not generate the loop with iteration variables.
I haven't figured out a good way to resolve this issue. Probably some sophisticated frontend analysis pass may help generate this kind of reduction loops.
from allo.
I think I found a solution to this problem: https://github.com/cornell-zhang/amc-dialect/pull/64
from allo.
This looks cool! Could you provide an example of the original MLIR code and the code after this pass? @andrewb1999
from allo.
Related Issues (20)
- [BUG]FFN memory usage not optmized due to difficulty of fusing linalg ops
- [BUG] Relu allocates extra memory for storing broadcasted zero tensor
- [BUG] Builder doesn't build scf for loop when both loop bounds are expressions
- [BUG] FIFO read in loop attempts to access repeated data HOT 1
- [BUG] Tuple not supported in dataflow analysis
- [BUG] For loop does not run when given int param from function HOT 1
- [BUG] Excessive Copy Loops HOT 5
- [BUG] Installation Issue HOT 1
- The compiler couldn't identify the loop listed before HOT 4
- [Feature] Use wraparound math for intermediate vals when desired
- [Feature] Rewind memory access loops HOT 1
- [Feature] Comment block support HOT 4
- [Feature] Allow list of AlloType as dtype for Structure
- [BUG] KeyError: 'attempt to access a non-existent attribute'
- [BUG] `arith.fptoui` issue with negative loop bound
- [BUG] Vitis HLS backend results not written back to argument
- [BUG] Cannot find target loop at schedule composition
- [BUG] HLS code of softmax will generate a variable named "exp"
- [Feature] Test HW on board using allo to generate the input
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from allo.