Skip to content
Open
Show file tree
Hide file tree
Changes from 6 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
3 changes: 2 additions & 1 deletion include/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)
3 changes: 3 additions & 0 deletions include/Compiler/CMakeLists.txt
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)
29 changes: 29 additions & 0 deletions include/Compiler/CompilerPasses.h
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
17 changes: 17 additions & 0 deletions include/Compiler/CompilerPasses.td
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
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
6 changes: 6 additions & 0 deletions include/Conversion/ConversionPasses.td
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,10 @@ def LowerLlvmToNeura : Pass<"lower-llvm-to-neura", "ModuleOp">{
let constructor = "mlir::createLowerLlvmToNeuraPass()";
}

def LowerAffineToNeura : Pass<"lower-affine-to-neura", "FuncOp">{
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
82 changes: 79 additions & 3 deletions include/NeuraDialect/NeuraOps.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"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What is this used for?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Used for AnySignlessIntegerOrIndex, which was used before.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So you mean now we can remove this header?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Removed in latest commit


// ----------------------------------------------------
// Defines basic scalar operations.
Expand All @@ -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);
let results = (outs SignlessIntegerLike:$result);
// let assemblyFormat = "$lhs `,` $rhs `,` $predicate attr-dict `:` type($result)";
let traits = [SameOperandsAndResultElementType];
}
Expand Down Expand Up @@ -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
}];
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 +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";
}
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 {



// 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
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