Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
run: |
git clone https://github.com/llvm/llvm-project.git
cd llvm-project
git checkout cd70802
git checkout 6146a88
mkdir build && cd build
cmake -G Ninja ../llvm \
-DLLVM_ENABLE_PROJECTS="mlir" \
Expand Down
1 change: 1 addition & 0 deletions include/Conversion/ConversionPasses.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace mlir {
// 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"
Expand Down
8 changes: 7 additions & 1 deletion include/Conversion/ConversionPasses.td
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ include "mlir/Pass/PassBase.td"
//=========================================================//
// Conversion passes
//=========================================================//
def LowerArithToNeura : Pass<"lower-arith-to-neura", "FuncOp">{
def LowerArithToNeura : Pass<"lower-arith-to-neura", "ModuleOp">{
let summary = "Lower arith to Neura dialect";
let description = [{Lower arith dialect operations to Neura dialect operations.}];
let constructor = "mlir::createLowerArithToNeuraPass()";
Expand All @@ -20,4 +20,10 @@ def LowerLlvmToNeura : Pass<"lower-llvm-to-neura", "ModuleOp">{
let constructor = "mlir::createLowerLlvmToNeuraPass()";
}

def LowerAffineToNeura : Pass<"lower-affine-to-neura", "ModuleOp">{
let summary = "Lower affine to Neura dialect";
let description = [{Lower affine dialect operations to Neura dialect operations.}];
let constructor = "mlir::createLowerAffineToNeuraPass()";
}

#endif // CONVERSION_PASSES_TD
12 changes: 6 additions & 6 deletions include/NeuraDialect/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Set TableGen include paths
set(MLIR_TABLEGEN_INCLUDES
${PROJECT_SOURCE_DIR}/include
${PROJECT_SOURCE_DIR}/include/NeuraDialect
${CMAKE_CURRENT_BINARY_DIR}/include/NeuraDialect
${MLIR_MAIN_INCLUDE_DIR}
${MLIR_INCLUDE_DIR})
# set(MLIR_TABLEGEN_INCLUDES
# ${PROJECT_SOURCE_DIR}/include
# ${PROJECT_SOURCE_DIR}/include/NeuraDialect
# ${CMAKE_CURRENT_BINARY_DIR}/include/NeuraDialect
# ${MLIR_MAIN_INCLUDE_DIR}
# ${MLIR_INCLUDE_DIR})
Comment on lines +2 to +7
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove?


add_mlir_dialect(Neura neura)

Expand Down
76 changes: 76 additions & 0 deletions include/NeuraDialect/NeuraOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,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
}];
let arguments = (ins Arg<AnyMemRef, "the load operation">:$base, Variadic<Index>:$indices, Optional<AnyType>:$predicate);
let results = (outs AnyType:$result);
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";
Expand Down Expand Up @@ -253,3 +281,51 @@ 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
// TODO: Add support for more complex loop structures using LoopInterOp
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>:$body_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 `then` $body(`(`$body_args^ `:` type($body_args)`)`)? `else` $exit attr-dict";
}
6 changes: 6 additions & 0 deletions include/NeuraDialect/NeuraPasses.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,22 @@
namespace mlir {
namespace neura {

void registerNeuraLegalizePassPipeline();

// Passes defined in GraphPasses.td
#define GEN_PASS_DECL
#include "NeuraDialect/NeuraPasses.h.inc"
// Passes used for neura optimization and transformation
std::unique_ptr<mlir::Pass> createInsertDataMovPass();
std::unique_ptr<mlir::Pass> createInsertCtrlMovPass();
std::unique_ptr<mlir::Pass> createFusePatternsPass();
std::unique_ptr<mlir::Pass> createAssignAcceleratorPass();
std::unique_ptr<mlir::Pass> createTransformCtrlToDataFlowPass();
std::unique_ptr<mlir::Pass> createLeveragePredicatedValuePass();

// Passes used for neura compiler
// std::unique_ptr<mlir::Pass> createGenerateDFGPass();

#define GEN_PASS_REGISTRATION
#include "NeuraDialect/NeuraPasses.h.inc"

Expand Down
11 changes: 5 additions & 6 deletions include/NeuraDialect/NeuraPasses.td
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,16 @@ def InsertCtrlMov : Pass<"insert-ctrl-mov", "ModuleOp"> {

def TransformCtrlToDataFlow : Pass<"transform-ctrl-to-data-flow", "ModuleOp"> {
let summary = "Inserts ctrl move operations in the Neura dialect";
let description =
[{Transform ctrl to predicate-based data flow.}];
let description = [{Transform ctrl to predicate - based data flow.}];
let constructor = "neura::createTransformCtrlToDataFlowPass()";
}

def LeveragePredicatedValue : Pass<"leverage-predicated-value", "ModuleOp"> {
let summary = "Convert values to predicated values in Neura dialect";
let description = [{
This pass converts regular values to predicated values in Neura dialect operations.
Each value is wrapped in a predicated value type with a default true predicate.
}];
let description = [{This pass converts regular values to predicated values in
Neura dialect operations
.Each value is wrapped in a predicated value type
with a default true predicate.}];
let constructor = "neura::createLeveragePredicatedValuePass()";
}

Expand Down
3 changes: 2 additions & 1 deletion lib/CMakeLists.txt
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)
Loading