-
Notifications
You must be signed in to change notification settings - Fork 31
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
Make outlined function arguments non-aliasing #1006
base: main
Are you sure you want to change the base?
Changes from all commits
c003230
0f7f8df
1ef7bf5
fa011a4
7f2c00f
e88cb10
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -290,7 +290,22 @@ def AMDAIELinalgFunctionOutlining : | |||||||
"Replace all outlined functions with a function that does nothing, " | ||||||||
"i.e. it just returns. Useful for measuring the performance of data " | ||||||||
"movement to/from the device -- by doing zero compute, all time is spent " | ||||||||
"moving data to/from the AIE cores."> | ||||||||
"moving data to/from the AIE cores.">, | ||||||||
Option<"noAliasMemrefArgs", "no-alias-memref-args", "bool", /*default=*/"true", | ||||||||
"A developer only option. When 'true' (the default), " | ||||||||
"the final memref argument of the outlined function " | ||||||||
"will have the 'llvm.noalias' attribute attached to " | ||||||||
"it. The motivation for having this attribute is that " | ||||||||
"sometimes the matmul code generated in llvm's opt is " | ||||||||
"much (2x) faster. The motivation for adding it manually " | ||||||||
"without any analysis is that llvm/peano cannot always " | ||||||||
"infer that this attribute can safely be attached, " | ||||||||
"because (I suppose) the analysis of all call sites, " | ||||||||
"i.e. checking that the final argument is not aliased " | ||||||||
"to any other arguments is too complicated/expensive. " | ||||||||
"The addition of this attribute in this pass is exposed " | ||||||||
"as an option, as there is no guarantee that it is valid " | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no guarantee that is valid, and you're saying it's a developer only option, but we're setting it to true by default? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah. If by "developer only option" we mean one that we don't guarantee correctness for when changed from default, then I suppose it's not a developer only option. What I meant was that it's an option that you shouldn't be playing with to eke out extra performance. Alternative approach (1): remove it as option, and do a shallow check that it's valid by checking if outlined payload is a matmul, or do some basic analysis of pointers. My concern is that this can balloon into complex code. Alternative approach (2): make the option 'false' by default. My concern here is that it should probably be true for every workload we're likely to see. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have been thinking about this and I think we can guarantee the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for thinking about this! I think for an analysis to be easier in pass N than pass M (where M<N) either (1) the analysis is done in an intervening pass P (M<P<=N) or (2) an assumption is baked into the IR in an intervening pass. Either way, I think it makes sense to have a pass to add the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you base the analysis on |
||||||||
"-- the final argument could in theory alias another argument. "> | ||||||||
Comment on lines
+307
to
+308
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
]; | ||||||||
} | ||||||||
|
||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Currently this is the default: | ||
// RUN: iree-opt --split-input-file --pass-pipeline="builtin.module(iree-amdaie-linalg-function-outlining{empty-functions=false no-alias-memref-args=true})" --verify-diagnostics --split-input-file %s | FileCheck %s --check-prefix=CHECK_NOTEMPTY_NOALIAS | ||
|
||
// CHECK_NOTEMPTY_NOALIAS: func.func private @ | ||
// CHECK_NOTEMPTY_NOALIAS-SAME: memref<4xbf16> {llvm.noalias}, | ||
// CHECK_NOTEMPTY_NOALIAS-SAME: memref<bf16> {llvm.noalias}) { | ||
// CHECK_NOTEMPTY_NOALIAS: linalg.generic | ||
// CHECK_NOTEMPTY_NOALIAS: return | ||
// CHECK_NOTEMPTY_NOALIAS: func.func @reduction | ||
|
||
// A run to check the option empty-functions=true: | ||
// RUN: iree-opt --split-input-file --pass-pipeline="builtin.module(iree-amdaie-linalg-function-outlining{empty-functions=true no-alias-memref-args=true})" --verify-diagnostics --split-input-file %s | FileCheck %s --check-prefix=CHECK_EMPTY_NOALIAS | ||
|
||
// CHECK_EMPTY_NOALIAS: func.func private @ | ||
// CHECK_EMPTY_NOALIAS-SAME: memref<4xbf16> {llvm.noalias}, | ||
// CHECK_EMPTY_NOALIAS-SAME: memref<bf16> {llvm.noalias}) { | ||
// CHECK_EMPTY_NOALIAS-NOT: linalg.generic | ||
// CHECK_EMPTY_NOALIAS: return | ||
// CHECK_EMPTY_NOALIAS: func.func @reduction | ||
|
||
// A run to check the option no-alias-memref-args=false: | ||
// RUN: iree-opt --split-input-file --pass-pipeline="builtin.module(iree-amdaie-linalg-function-outlining{empty-functions=false no-alias-memref-args=false})" --verify-diagnostics --split-input-file %s | FileCheck %s --check-prefix=CHECK_NOTEMPTY_ALIAS | ||
|
||
// CHECK_NOTEMPTY_ALIAS: func.func private @ | ||
// CHECK_NOTEMPTY_ALIAS-SAME: memref<4xbf16>, | ||
// CHECK_NOTEMPTY_ALIAS-SAME: memref<bf16>) { | ||
// CHECK_NOTEMPTY_ALIAS: linalg.generic | ||
// CHECK_NOTEMPTY_ALIAS: return | ||
// CHECK_NOTEMPTY_ALIAS: func.func @reduction | ||
|
||
func.func @reduction(%A: memref<4xbf16>, %B: memref<bf16>) { | ||
%c2 = arith.constant 2 : index | ||
%tile = amdaie.tile(%c2, %c2) | ||
%1 = amdaie.core(%tile, in : [], out : []) { | ||
linalg.generic { | ||
indexing_maps = [affine_map<(d0) -> (d0)>, affine_map<(d0) -> ()>], | ||
iterator_types = ["reduction"] | ||
} ins(%A: memref<4xbf16>) outs(%B : memref<bf16>) { | ||
^bb0(%in: bf16, %out: bf16): | ||
linalg.yield %in : bf16 | ||
} | ||
amdaie.end | ||
} | ||
return | ||
} |
This file was deleted.
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.