-
Notifications
You must be signed in to change notification settings - Fork 15
Lower Affine Dialect to Nerua Dialect #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
base: main
Are you sure you want to change the base?
Changes from 6 commits
fe46cdb
93955fa
7e16547
ae6134a
8c3c6e5
0c24064
2f34550
5bc4884
c0a861c
083aea8
e917f0a
768b208
6594f4a
9d4ee25
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 |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| add_subdirectory(NeuraDialect) | ||
| add_subdirectory(Conversion) | ||
| add_subdirectory(Conversion) | ||
| # add_subdirectory(Compiler) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| set(LLVM_TARGET_DEFINITIONS CompilerPasses.td) | ||
| mlir_tablegen(CompilerPasses.h.inc --gen-pass-decls) | ||
| add_public_tablegen_target(MLIRCompilerPassesIncGen) | ||
ShangkunLi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| // ConversionPasses.h - Header file for conversion passes | ||
|
|
||
| #ifndef CONVERSION_PASSES_H | ||
| #define CONVERSION_PASSES_H | ||
|
|
||
| #include "NeuraDialect/NeuraDialect.h" | ||
| #include "NeuraDialect/NeuraOps.h" | ||
| #include "mlir/Pass/Pass.h" | ||
| #include "mlir/Pass/PassManager.h" | ||
| #include "mlir/Pass/PassRegistry.h" | ||
| #include <memory> | ||
|
|
||
| namespace mlir { | ||
|
|
||
| // Passes defined in GraphPasses.td. | ||
| #define GEN_PASS_DECL | ||
| #include "Conversion/ConversionPasses.h.inc" | ||
|
|
||
| // Conversion passes. | ||
| std::unique_ptr<mlir::Pass> createLowerArithToNeuraPass(); | ||
| std::unique_ptr<mlir::Pass> createLowerLlvmToNeuraPass(); | ||
| std::unique_ptr<mlir::Pass> createLowerAffineToNeuraPass(); | ||
|
|
||
| #define GEN_PASS_REGISTRATION | ||
| #include "Conversion/ConversionPasses.h.inc" | ||
|
|
||
| } // namespace mlir | ||
|
|
||
| #endif // CONVERSION_PASSES_H |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| // CompilerPasses.td - Passes for neura compiler | ||
|
|
||
| #ifndef COMPILER_PASSES_TD | ||
| #define COMPILER_PASSES_TD | ||
|
|
||
| include "mlir/Pass/PassBase.td" | ||
|
|
||
| //=========================================================// | ||
| // Passes for the CGRA Mapping | ||
| //=========================================================// | ||
| def GenerateDFG: Pass<"generate-dfg", "ModuleOp">{ | ||
| let summary = "Generates a Data Flow Graph (DFG) for the Neura dialect"; | ||
| let description = [{This pass generates a DFG from the Neura dialect operations.}]; | ||
| let constructor = "neura::createGenerateDFGPass()"; | ||
| } | ||
|
|
||
| #endif // COMPILER_PASSES_TD |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| // NeuraOps.td - Custom operation definitions. | ||
|
|
||
| include "NeuraDialect/NeuraDialect.td" | ||
| include "mlir/IR/CommonTypeConstraints.td" | ||
|
||
|
|
||
| // ---------------------------------------------------- | ||
| // Defines basic scalar operations. | ||
|
|
@@ -11,15 +12,15 @@ def Neura_ConstantOp : Op<NeuraDialect, "constant"> { | |
| OptionalAttr<BoolAttr>:$predicate // Add optional predicate attribute | ||
| ); | ||
| let results = (outs AnyType:$result); | ||
| // let assemblyFormat = "attr-dict `:` type($result)"; | ||
| let assemblyFormat = "attr-dict `:` type($result)"; | ||
| } | ||
|
|
||
| // Defines an addition operation. | ||
| def Neura_AddOp : Op<NeuraDialect, "add"> { | ||
| let summary = "Integer addition operation"; | ||
| let opName = "add"; | ||
| let arguments = (ins AnyInteger:$lhs, AnyInteger:$rhs, Optional<AnyType>:$predicate); | ||
| let results = (outs AnyInteger:$result); | ||
| let arguments = (ins SignlessIntegerLike:$lhs, SignlessIntegerLike:$rhs, Optional<AnyType>:$predicate); | ||
ShangkunLi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| let results = (outs SignlessIntegerLike:$result); | ||
| // let assemblyFormat = "$lhs `,` $rhs `,` $predicate attr-dict `:` type($result)"; | ||
| let traits = [SameOperandsAndResultElementType]; | ||
| } | ||
|
|
@@ -101,6 +102,34 @@ def Neura_StoreOp : Op<NeuraDialect, "store"> { | |
| // let assemblyFormat = "$value `,` $addr `,` $predicate attr-dict"; | ||
| } | ||
|
|
||
| // Defines a load operation with integrated address calculation. | ||
| def Neura_LoadIndexedOp: Op<NeuraDialect, "load_indexed", [AttrSizedOperandSegments]>{ | ||
| let summary = "Load with integrated address calculation for multi-dimensional arrays"; | ||
| let description = [{ | ||
| Calculates the address using the base address and indices. | ||
| Load the value at the calculated address. | ||
| Example: | ||
| %value = neura.load_indexed %base [%arg1, %arg2] : f32 | ||
tancheng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }]; | ||
| let arguments = (ins Arg<AnyMemRef, "the load operation">:$base, Variadic<Index>:$indices, Optional<AnyType>:$predicate); | ||
| let results = (outs AnyType:$result); | ||
tancheng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| let assemblyFormat = "type($base) $base `[` $indices `]` ($predicate^ `:` type($predicate))? attr-dict `:` type($result)"; | ||
| } | ||
|
|
||
| //Defines a store operation with integrated address calculation. | ||
| def Neura_StoreIndexedOp: Op<NeuraDialect, "store_indexed", [AttrSizedOperandSegments]> { | ||
| let summary = "Store with integrated address calculation for multi-dimensional arrays"; | ||
| let description = [{ | ||
| Calculates the address using the base address and indices. | ||
| Store the value at the calculated address. | ||
| Example: | ||
| neura.store_indexed %value, %base [%arg1, %arg2] : f32 | ||
| }]; | ||
| let arguments = (ins AnyType:$value, Arg<AnyMemRef, "the store operation">:$base, Variadic<Index>:$indices, Optional<AnyType>:$predicate); | ||
| let results = (outs); | ||
| let assemblyFormat = "$value `to` type($base) $base `[` $indices `]` ($predicate^ `:` type($predicate))? attr-dict `:` type($value)"; | ||
| } | ||
|
|
||
| // Defines a pointer computation operation. | ||
| def Neura_GEP : Op<NeuraDialect, "gep"> { | ||
| let summary = "Pointer computation using offset indices"; | ||
|
|
@@ -253,3 +282,50 @@ def Neura_ReserveOp : Op<NeuraDialect, "reserve"> { | |
| let results = (outs AnyType:$result); | ||
| let assemblyFormat = "attr-dict `:` type($result)"; | ||
| } | ||
|
|
||
| // ---------------------------------------------------- | ||
| // Defines loop related operations. | ||
|
|
||
| // Loop iteration operation for index increament and compare | ||
| def Neura_LoopIterOp : Op<NeuraDialect, "loop_iter", [AttrSizedOperandSegments]> { | ||
| let summary = "CGRA-optimized loop iteration operation"; | ||
| let description = [{ | ||
| Takes the current loop index, a step value, and an upper bound as the inputs. | ||
| Outputs the next loop index and a boolean condition indicating whether the loop should continue. | ||
|
|
||
| Example: | ||
| %next_index, %continue = neura.loop_control current_index: 0, step: 1, bound: 10 : i32 i1}]; | ||
|
|
||
| let arguments = (ins Index: $current_index, | ||
| Index:$step, | ||
| Index:$bound, | ||
| Optional<AnyType>:$loop_type, // 0: <, 1: <=, 2: >, 3: >= | ||
| Optional<AnyType>:$predicate); | ||
| let results = (outs Index:$next_index, I1:$continue_condition); | ||
| let assemblyFormat = "`current_index` `:` $current_index `,` `step` `:` $step `,` `bound` `:` $bound `:` type($bound) ($loop_type^ `:` type($loop_type))? ($predicate^ `:` type($predicate))? attr-dict `:` type($next_index) type($continue_condition)"; | ||
| } | ||
|
|
||
| // Loop control operation that integrates loop iteration and control flow. | ||
| def Neura_LoopControlOp: Op<NeuraDialect, "loop_control", [Terminator]>{ | ||
| let summary = "Intergrated loop control operation for simple loops"; | ||
| let description = [{ | ||
| This operation is an integrated loop control operation that combines the loop iteration and control flow. | ||
| It has three main actions: | ||
| 1. Calculates the next iteration's index: `next_index = current_index + step` | ||
| 2. Checks if the loop should continue based on the current index and bound. | ||
| 3. If the loop should continue, it branches to the loop body, and yields related values. | ||
| 4. Otherwise, it exits the loop. | ||
| }]; | ||
| let arguments = (ins Index:$current_index, // Current loop index | ||
| Index:$step, | ||
| Index:$bound, | ||
| DefaultValuedAttr<StrAttr, "\"lt\"">:$loop_type, // Loop type: "lt", "le", "gt", "ge", "eq", "ne" | ||
| Variadic<AnyType>:$passthrough_args // Additional arguments to pass through to the successors | ||
| ); | ||
| let results = (outs); | ||
| let successors = (successor | ||
| AnySuccessor:$body, // loop body successors | ||
| AnySuccessor:$exit // exit successors | ||
| ); | ||
| let assemblyFormat = "`current_index` `:` $current_index `,` `step` `:` $step `,` `bound` `:` $bound `,` `loop_type` `:` $loop_type (`passthrough` `(` $passthrough_args^ `:` type($passthrough_args) `)`)? `then` $body `else` $exit attr-dict"; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| add_subdirectory(NeuraDialect) | ||
| add_subdirectory(Conversion) | ||
| add_subdirectory(Conversion) | ||
| # add_subdirectory(Compiler) | ||
ShangkunLi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Uh oh!
There was an error while loading. Please reload this page.