-
Notifications
You must be signed in to change notification settings - Fork 23
Performance Bounding Dialect #1580
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
Draft
javathunderman
wants to merge
7
commits into
main
Choose a base branch
from
perfify
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.
+220
−0
Draft
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c13950c
start perfify dialect impl
javathunderman e1fe7fe
Add assume op, TODO: fix roundtrip parsing test
javathunderman fe5bd7e
tweak w/ clang-format
javathunderman 0fb50e6
Merge branch 'main' into perfify
javathunderman 7257b68
Fix AssumeOp parsing, adjust parsing test file
javathunderman 9d20414
attempt to resolve formatting issue
javathunderman 03417ae
format RegistryUtils?
javathunderman 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
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,14 @@ | ||
| #include "Dialect.h" | ||
|
|
||
| #include "mlir/IR/Builders.h" | ||
| #include "llvm/ADT/TypeSwitch.h" | ||
|
|
||
| #include "src/enzyme_ad/jax/Dialect/Perfify/PerfifyDialect.cpp.inc" | ||
|
|
||
| // Initialize the dialect | ||
| void mlir::enzyme::perfify::PerfifyDialect::initialize() { | ||
| addOperations< | ||
| #define GET_OP_LIST | ||
| #include "src/enzyme_ad/jax/Dialect/Perfify/PerfifyOps.cpp.inc" | ||
| >(); | ||
| } |
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,19 @@ | ||
| #ifndef ENZYME_AD_JAX_DIALECT_PERFIFY_DIALECT_H | ||
| #define ENZYME_AD_JAX_DIALECT_PERFIFY_DIALECT_H | ||
|
|
||
| #include "mlir/Bytecode/BytecodeOpInterface.h" | ||
| #include "mlir/IR/Attributes.h" | ||
| #include "mlir/IR/Dialect.h" | ||
| #include "mlir/IR/DialectImplementation.h" | ||
| #include "mlir/IR/OpDefinition.h" | ||
| #include "mlir/IR/Region.h" | ||
| #include "mlir/IR/Types.h" | ||
|
|
||
| // Include the dialect | ||
| #include "src/enzyme_ad/jax/Dialect/Perfify/PerfifyDialect.h.inc" | ||
|
|
||
| // Operations | ||
| #define GET_OP_CLASSES | ||
| #include "src/enzyme_ad/jax/Dialect/Perfify/PerfifyOps.h.inc" | ||
|
|
||
| #endif // ENZYME_AD_JAX_DIALECT_PERFIFY_DIALECT_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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| #ifndef ENZYME_AD_JAX_DIALECT_PERFIFY_DIALECT_TD | ||
| #define ENZYME_AD_JAX_DIALECT_PERFIFY_DIALECT_TD | ||
|
|
||
| include "mlir/IR/DialectBase.td" | ||
| include "mlir/IR/AttrTypeBase.td" | ||
| include "mlir/IR/Traits.td" | ||
| include "mlir/IR/OpBase.td" | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // Perfify dialect definition. | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| def PerfifyDialect : Dialect { | ||
| let name = "perfify"; | ||
| let summary = "A dialect for specifying and proving runtime bounds"; | ||
| let description = [{ | ||
| Lets users specify a bound on the number of steps/latency (per a predefined cost model) that a function or other operation should take. | ||
| Leverages SAT solvers to automatically prove this, or interactive theorem provers to allow for complete proofs. | ||
| }]; | ||
| let cppNamespace = "::mlir::enzyme::perfify"; | ||
| } | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // Base Perfify operation definition. | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| class PerfifyOp<string mnemonic, list<Trait> traits = []> | ||
| : Op<PerfifyDialect, mnemonic, traits>; | ||
|
|
||
| class PerfifyType<string name> : TypeDef<PerfifyDialect, name>; // may need to be modified | ||
|
|
||
| #endif // ENZYME_AD_JAX_DIALECT_PERFIFY_DIALECT_TD |
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 @@ | ||
| #include "mlir/IR/Builders.h" | ||
| #include "llvm/ADT/TypeSwitch.h" | ||
|
|
||
| #include "Dialect.h" | ||
| #include "mlir/IR/IRMapping.h" | ||
| #include "mlir/Interfaces/FunctionImplementation.h" | ||
| #include "mlir/Interfaces/FunctionInterfaces.h" | ||
|
|
||
| using namespace mlir; | ||
| using namespace mlir::enzyme::perfify; | ||
|
|
||
| namespace mlir::enzyme::perfify {} // namespace mlir::enzyme::perfify | ||
|
|
||
| #define GET_OP_CLASSES | ||
| #include "src/enzyme_ad/jax/Dialect/Perfify/PerfifyOps.cpp.inc" | ||
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,48 @@ | ||
| #ifndef ENZYME_AD_JAX_DIALECT_PERFIFY_OPS_TD | ||
| #define ENZYME_AD_JAX_DIALECT_PERFIFY_OPS_TD | ||
|
|
||
| include "mlir/IR/BuiltinAttributes.td" | ||
| include "mlir/IR/OpBase.td" | ||
| include "Dialect.td" | ||
|
|
||
| // Perfify.cost op | ||
| def CostOp : PerfifyOp<"cost", []> { | ||
| // summary | ||
| // description | ||
| // arguments | ||
| let arguments = (ins StrAttr:$target_op, | ||
| APIntAttr:$cycle_cost); | ||
| let assemblyFormat = "$target_op $cycle_cost attr-dict"; | ||
|
|
||
| } | ||
|
|
||
| def ArgOp : PerfifyOp<"arg", []> { | ||
| let arguments = (ins I64Attr:$val); | ||
| let assemblyFormat = "$val attr-dict"; | ||
| let results = (outs I64); | ||
| } | ||
|
|
||
| def AssumeOp : PerfifyOp<"assume", []> { | ||
| let arguments = (ins BoolAttr:$precondition); | ||
| let assemblyFormat = "$precondition attr-dict"; | ||
| } | ||
|
|
||
| def ConditionsOp : PerfifyOp<"conditions", []> { | ||
| let arguments = (ins FlatSymbolRefAttr:$func_handle, | ||
| BoolAttr:$verify_huh); | ||
| let regions = (region AnyRegion:$precondition, AnyRegion:$postcondition); | ||
|
|
||
| let assemblyFormat = [{ | ||
| $func_handle $verify_huh attr-dict `pre` | ||
| $precondition | ||
| `post` | ||
| $postcondition | ||
| }]; | ||
| } | ||
|
|
||
| def AssumptionsOp : PerfifyOp<"assumptions", []> { | ||
| let regions = (region AnyRegion:$body); | ||
| let assemblyFormat = [{$body attr-dict}]; | ||
| } | ||
|
|
||
| #endif // ENZYME_AD_JAX_DIALECT_PERFIFY_OPS_TD |
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,22 @@ | ||
| module { | ||
| perfify.assumptions { // operation in the dialect | ||
| perfify.cost "arith.mul" 3 // op | ||
| perfify.cost "func.return" 0 | ||
| perfify.cost "scf.yield" 0 | ||
| func.func @foo() -> () { return } | ||
|
|
||
| perfify.conditions @foo true pre { | ||
| %b0 = perfify.arg 0 // op | ||
| %c0 = arith.constant 0 | ||
| %cmp = arith.cmpi eq, %c0, %b0 : i64 | ||
| perfify.assume %cmp | ||
| } post { | ||
| // %cost = perfify.fn_cost : perfify.cost | ||
| // %c9 = perfify.constant_cost 9 : perfify.cost // then our cost is 9 | ||
|
|
||
| // %cmp = arith.cmpi eq, %cost, %c9 | ||
| // perfify.assume %cmp | ||
| } | ||
|
|
||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.