Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
3b19db4
Add histogram testbench files
n0thingNoob Oct 17, 2025
6da8b5c
Fix conversion for llvm.fdiv and llvm.fptosi, add e2e/histogram kerne…
n0thingNoob Oct 18, 2025
40aa68f
Delete test/testbench/histogram/histogram.cpp
n0thingNoob Oct 18, 2025
4b9f1c6
Delete test/testbench/histogram/histogram_kernel_neura.mlir
n0thingNoob Oct 18, 2025
3cd3901
Update test/e2e/histogram/histogram_kernel.mlir
n0thingNoob Oct 18, 2025
cdb66da
Delete test/testbench/histogram/histogram_kernel.cpp
n0thingNoob Oct 18, 2025
d694f69
Delete test/testbench/histogram/histogram_kernel.ll
n0thingNoob Oct 18, 2025
1b854f3
Delete test/testbench/histogram/histogram_kernel.mlir
n0thingNoob Oct 18, 2025
4fb939a
Clean up .gitmodules by removing duplicates
n0thingNoob Oct 18, 2025
71c28c3
add fir and modify LlvmToNeuraPass.cpp for llvm.fmuladd conversion
n0thingNoob Oct 18, 2025
180c3ef
Add FIR kernel support and llvm.fmuladd conversion
n0thingNoob Oct 18, 2025
f70a11e
Merge remote-tracking branch 'origin/testbench'
n0thingNoob Oct 18, 2025
411b066
Clean up repository: remove temporary and generated files
n0thingNoob Oct 19, 2025
9a846b1
Fix Neura_OrOp type definition to support neura.data types
n0thingNoob Oct 19, 2025
e73bf40
Remove FFT and fusion test files
n0thingNoob Oct 19, 2025
10dfd4b
remove histogram.cpp
n0thingNoob Oct 19, 2025
e59f4de
remove ll file
n0thingNoob Oct 19, 2025
5a4c2ff
rm testbench folder
n0thingNoob Oct 19, 2025
096359f
backup for fir kernel and histogram kernel
n0thingNoob Oct 19, 2025
db4e012
Use llvm extract to extract kernel from benchmarks
n0thingNoob Oct 19, 2025
ebcf014
unify the kernel name in the llvm extract command
n0thingNoob Oct 19, 2025
d4314ae
add issue link to mlir file
n0thingNoob Oct 19, 2025
a83fe7f
Fix GitHub CI: Add LLVM tools to PATH for llvm-extract
n0thingNoob Oct 19, 2025
811a674
Add TODO, remove redundant file
n0thingNoob Oct 19, 2025
6f683fa
rm extra file
n0thingNoob Oct 19, 2025
bf45e98
upload gitignore and remove the unnecessary mlir.llvm in test
n0thingNoob Oct 19, 2025
3176f6f
rm adding the build/bin to PATH
n0thingNoob Oct 19, 2025
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: 3 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ jobs:

cmake --build .
cmake --build . --target check-mlir

# Add LLVM tools to PATH
echo "${{github.workspace}}/llvm-project/build/bin" >> $GITHUB_PATH
# setup mlir-cgra
- name: setup dataflow tool-chain
working-directory: ${{github.workspace}}
Expand Down
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "test/CGRA-Bench"]
path = test/CGRA-Bench
url = https://github.com/tancheng/CGRA-Bench
[submodule "test/benchmark/CGRA-Bench"]
path = test/benchmark/CGRA-Bench
url = https://github.com/tancheng/CGRA-Bench.git
15 changes: 11 additions & 4 deletions include/NeuraDialect/NeuraOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,23 @@ def Neura_FMulOp : Op<NeuraDialect, "fmul"> {

def Neura_FDivOp : Op<NeuraDialect, "fdiv"> {
let summary = "Floating division operation";
let arguments = (ins AnyType:$lhs, Optional<AnyType>:$rhs);
let description = [{
Performs a floating-point division operation, computing the result of
a / b, where / is the floating-point division operator.

Example:
%result = neura.fdiv %a, %b : f32
}];
let arguments = (ins AnyType:$lhs, AnyType:$rhs);
let results = (outs AnyType:$result);
// let assemblyFormat = "$lhs `,` $rhs `,` $predicate attr-dict `:` type($result)";
let traits = [SameOperandsAndResultElementType];
}

// Defines a bitwise OR operation.
def Neura_OrOp : Op<NeuraDialect, "or"> {
let summary = "Bitwise OR operation";
let arguments = (ins AnySignlessInteger:$lhs, AnySignlessInteger:$rhs);
let results = (outs AnySignlessInteger:$result);
let arguments = (ins AnyType:$lhs, AnyType:$rhs);
let results = (outs AnyType:$result);
// let assemblyFormat = "$lhs `,` $rhs `,` attr-dict `:` type($result)";
let traits = [SameOperandsAndResultElementType];
}
Expand Down
55 changes: 55 additions & 0 deletions lib/Conversion/LlvmToNeura/LlvmToNeuraPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,58 @@ struct LlvmSRemToNeuraRem : public OpRewritePattern<LLVM::SRemOp> {
}
};

struct LlvmFDivToNeuraFDiv : public OpRewritePattern<mlir::LLVM::FDivOp> {
using OpRewritePattern::OpRewritePattern;

LogicalResult matchAndRewrite(mlir::LLVM::FDivOp op,
PatternRewriter &rewriter) const override {
Value lhs = op->getOperand(0);
Value rhs = op->getOperand(1);
Type result_type = op->getResult(0).getType();

// Only matches scalar float.
if (!mlir::isa<FloatType>(result_type))
return failure();

rewriter.replaceOpWithNewOp<neura::FDivOp>(op, result_type, lhs, rhs);
return success();
}
};

struct LlvmFPToSIToNeuraCast : public OpRewritePattern<mlir::LLVM::FPToSIOp> {
using OpRewritePattern::OpRewritePattern;

LogicalResult matchAndRewrite(mlir::LLVM::FPToSIOp op,
PatternRewriter &rewriter) const override {
Value input = op.getArg();
Type result_type = op.getType();

// Creates a cast operation with "fptosi" as the cast type.
rewriter.replaceOpWithNewOp<neura::CastOp>(op, result_type, input,
rewriter.getStringAttr("fptosi"));
return success();
}
};

struct LlvmFMulAddToNeuraFMulFAdd : public OpRewritePattern<mlir::LLVM::FMulAddOp> {
using OpRewritePattern::OpRewritePattern;

LogicalResult matchAndRewrite(mlir::LLVM::FMulAddOp op,
PatternRewriter &rewriter) const override {
Value a = op->getOperand(0);
Value b = op->getOperand(1);
Value c = op->getOperand(2);
Type result_type = op->getResult(0).getType();

// Only matches scalar float.
if (!mlir::isa<FloatType>(result_type))
return failure();

rewriter.replaceOpWithNewOp<neura::FMulFAddOp>(op, result_type, a, b, c);
return success();
}
};

struct LlvmVFMulToNeuraVFMul : public OpRewritePattern<mlir::LLVM::FMulOp> {
using OpRewritePattern::OpRewritePattern;

Expand Down Expand Up @@ -533,6 +585,9 @@ struct LowerLlvmToNeuraPass
patterns.add<LlvmShlToNeuraShl>(&getContext());
patterns.add<LlvmSDivToNeuraDiv>(&getContext());
patterns.add<LlvmSRemToNeuraRem>(&getContext());
patterns.add<LlvmFDivToNeuraFDiv>(&getContext());
patterns.add<LlvmFPToSIToNeuraCast>(&getContext());
patterns.add<LlvmFMulAddToNeuraFMulFAdd>(&getContext());

FrozenRewritePatternSet frozen(std::move(patterns));

Expand Down
37 changes: 37 additions & 0 deletions test/e2e/fir/fir_kernel.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Compiles the original C kernel to mlir, then lowers it via Neura.
// TODO: Got error when using -O3 -fno-vectorize -fno-slp-vectorize -mllvm -force-vector-width=1
// Issue: https://github.com/coredac/dataflow/issues/164
// RUN: clang++ -S -emit-llvm -O0 -o %t-kernel-full.ll %S/../../benchmark/CGRA-Bench/kernels/fir/fir.cpp
// RUN: llvm-extract --rfunc=".*kernel.*" %t-kernel-full.ll -o %t-kernel-only.ll
// RUN: mlir-translate --import-llvm %t-kernel-only.ll -o %t-kernel.mlir

// RUN: mlir-neura-opt %t-kernel.mlir \
// RUN: --assign-accelerator \
// RUN: --lower-llvm-to-neura \
// RUN: --canonicalize-live-in \
// RUN: --leverage-predicated-value \
// RUN: --transform-ctrl-to-data-flow \
// RUN: --promote-func-arg-to-const \
// RUN: --insert-data-mov \
// RUN: --map-to-accelerator="mapping-strategy=heuristic" \
// RUN: --architecture-spec=../../arch_spec/architecture.yaml \
// RUN: --generate-code -o %t-mapping.mlir
// RUN: FileCheck %s --input-file=%t-mapping.mlir -check-prefix=MAPPING
// RUN: FileCheck %s --input-file=tmp-generated-instructions.yaml --check-prefix=YAML
// RUN: FileCheck %s --input-file=tmp-generated-instructions.asm --check-prefix=ASM

// MAPPING: module
// MAPPING: func @_Z6kernelPfS_S_
// MAPPING: neura.constant
// MAPPING: neura.fmul_fadd
// MAPPING: neura.load
// MAPPING: neura.store

// YAML: instructions:
// YAML: - opcode: "CONSTANT"
// YAML: - opcode: "FMUL_FADD"
// YAML: - opcode: "LOAD"
// YAML: - opcode: "STORE"

// ASM: PE(0,0):
// ASM: CONSTANT
36 changes: 36 additions & 0 deletions test/e2e/histogram/histogram_kernel.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Compiles the original C kernel to mlir, then lowers it via Neura.
// TODO: Got error when using -O3 -fno-vectorize -fno-slp-vectorize -mllvm -force-vector-width=1
// Issue: https://github.com/coredac/dataflow/issues/164
// RUN: clang++ -S -emit-llvm -O2 -o %t-kernel-full.ll %S/../../benchmark/CGRA-Bench/kernels/histogram/histogram.cpp
// RUN: llvm-extract --rfunc=".*kernel.*" %t-kernel-full.ll -o %t-kernel-only.ll
// RUN: mlir-translate --import-llvm %t-kernel-only.ll -o %t-kernel.mlir

// RUN: mlir-neura-opt %t-kernel.mlir \
// RUN: --assign-accelerator \
// RUN: --lower-llvm-to-neura \
// RUN: --canonicalize-live-in \
// RUN: --leverage-predicated-value \
// RUN: --transform-ctrl-to-data-flow \
// RUN: --promote-func-arg-to-const \
// RUN: --insert-data-mov \
// RUN: --map-to-accelerator="mapping-strategy=heuristic" \
// RUN: --architecture-spec=%S/../../arch_spec/architecture.yaml \
// RUN: --generate-code -o %t-mapping.mlir
// RUN: FileCheck %s --input-file=%t-mapping.mlir -check-prefix=MAPPING
// RUN: FileCheck %s --input-file=tmp-generated-instructions.yaml --check-prefix=YAML
// RUN: FileCheck %s --input-file=tmp-generated-instructions.asm --check-prefix=ASM


// MAPPING: module
// MAPPING: func @_Z6kernelPfPi
// MAPPING: neura.constant
// MAPPING: neura.fdiv
// MAPPING: neura.cast

// YAML: instructions:
// YAML: - opcode: "CONSTANT"
// YAML: - opcode: "FDIV"
// YAML: - opcode: "CAST"

// ASM: PE(0,0):
// ASM: CONSTANT
Empty file removed test/testbench/Conv2D/.gitkeep
Empty file.
Empty file removed test/testbench/FFT/.gitkeep
Empty file.
Empty file removed test/testbench/SpMV/.gitkeep
Empty file.
Empty file removed test/testbench/dtw/.gitkeep
Empty file.
Empty file removed test/testbench/fir/.gitkeep
Empty file.
Empty file removed test/testbench/gemm/.gitkeep
Empty file.
Empty file removed test/testbench/histogram/.gitkeep
Empty file.
Empty file removed test/testbench/relu/.gitkeep
Empty file.