Skip to content

Commit d4ebb3a

Browse files
committed
Fixed include dependencies in EmitHLS.cc as well as syntax errors due to porting from newer LLVM version
1 parent 15e7d6c commit d4ebb3a

File tree

13 files changed

+214
-78
lines changed

13 files changed

+214
-78
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ test-example:
2020
python3 scripts/pb-flow.py ./example/polybench -e $(example) --work-dir ./tmp/phism/pb-flow.tmp --cosim
2121

2222
test-emit:
23-
python3 scripts/pb-flow.py ./example/polybench -e 2mm --work-dir ./tmp/phism/pb-flow.tmp --skip-vitis --emit-HLS
23+
python3 scripts/pb-flow.py ./example/polybench -e 2mm --work-dir ./tmp/phism/pb-flow.tmp --skip-vitis --emit-hls
2424

2525
# Evaluate polybench (baseline) - need to be used in environment
2626
test-polybench:

emitHLS_test.mlir

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// RUN: mase-opt %s --emit-hls="hls-param=data_in,,in,,fixed,,(1,100),,(8,5);data_out,,out,,fixed,,(1,100),,(8,5);" | FileCheck %s
2+
3+
// CHECK: // =====================================
4+
// CHECK-NEXT: // Mase HLS Hardware
5+
// CHECK-NEXT: // Model: relu
6+
// CHECK-NEXT: // =====================================
7+
// CHECK-NEXT: #include <algorithm>
8+
// CHECK-NEXT: #include <ap_axi_sdata.h>
9+
// CHECK-NEXT: #include <ap_fixed.h>
10+
// CHECK-NEXT: #include <ap_int.h>
11+
// CHECK-NEXT: #include <hls_math.h>
12+
// CHECK-NEXT: #include <hls_stream.h>
13+
// CHECK-NEXT: #include <math.h>
14+
// CHECK-NEXT: #include <stdint.h>
15+
// CHECK-NEXT: #include <string.h>
16+
// CHECK-NEXT: using namespace std;
17+
// CHECK: void relu(ap_fixed<8, 5> data_in[1][100],ap_fixed<8, 5> data_out[1][100]) {
18+
// CHECK-NEXT: ap_fixed<8, 5> v0 = 0.000000;
19+
// CHECK-NEXT: ap_fixed<8, 5> v1;
20+
// CHECK-NEXT: bool v2;
21+
// CHECK-NEXT: ap_fixed<8, 5> v3;
22+
// CHECK-NEXT: b0:
23+
// CHECK-NEXT: for (int v4 = 0; v4 < 1; v4 += 1) {b1:
24+
// CHECK-NEXT: for (int v5 = 0; v5 < 100; v5 += 1) {b2:
25+
// CHECK-NEXT: v1 = data_in[0][v5];
26+
// CHECK-NEXT: v2 = v1 > v0;
27+
// CHECK-NEXT: v3 = v2 ? v1 : v0;
28+
// CHECK-NEXT: data_out[v4][v5] = v3;
29+
// CHECK-NEXT: }
30+
// CHECK-NEXT: }
31+
// CHECK-NEXT: }
32+
// CHECK-NEXT: module {
33+
// CHECK-NEXT: func.func @relu(%arg0: memref<1x100xf32>, %arg1: memref<1x100xf32>) {
34+
// CHECK-NEXT: %cst = arith.constant 0.000000e+00 : f32
35+
// CHECK-NEXT: affine.for %arg2 = 0 to 1 {
36+
// CHECK-NEXT: affine.for %arg3 = 0 to 100 {
37+
// CHECK-NEXT: %0 = affine.load %arg0[0, %arg3] : memref<1x100xf32>
38+
// CHECK-NEXT: %1 = arith.cmpf ugt, %0, %cst : f32
39+
// CHECK-NEXT: %2 = arith.select %1, %0, %cst : f32
40+
// CHECK-NEXT: affine.store %2, %arg1[%arg2, %arg3] : memref<1x100xf32>
41+
// CHECK-NEXT: }
42+
// CHECK-NEXT: }
43+
// CHECK-NEXT: return
44+
// CHECK-NEXT: }
45+
// CHECK-NEXT: }
46+
47+
func @relu(%arg0: memref<1x100xf32>, %arg1: memref<1x100xf32>) {
48+
%cst = arith.constant 0.000000e+00 : f32
49+
affine.for %arg2 = 0 to 1 {
50+
affine.for %arg3 = 0 to 100 {
51+
%0 = affine.load %arg0[0, %arg3] : memref<1x100xf32>
52+
%1 = arith.cmpf ugt, %0, %cst : f32
53+
%2 = select %1, %0, %cst : f32
54+
affine.store %2, %arg1[%arg2, %arg3] : memref<1x100xf32>
55+
}
56+
}
57+
return
58+
}

include/phism/mlir/Transforms/Passes.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ std::unique_ptr<mlir::OperationPass<mlir::FuncOp>> createLoadSwitchPass();
2424
std::unique_ptr<mlir::OperationPass<mlir::ModuleOp>> createLiftMemRefSubviewPass();
2525
std::unique_ptr<mlir::OperationPass<mlir::ModuleOp>> createSCoPDecompositionPass();
2626
std::unique_ptr<mlir::OperationPass<mlir::ModuleOp>> createInlineSCoPAffinePass();
27-
// TODO ModuleOp, FuncOp or just Pass?
2827
std::unique_ptr<mlir::OperationPass<mlir::ModuleOp>> createEmitHLSPass();
2928

3029
/// Generate the code for registering passes.

include/phism/mlir/Transforms/Passes.td

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,16 @@ def InlineSCoPAffine : Pass<"inline-scop-affine", "::mlir::ModuleOp"> {
130130
];
131131
}
132132

133-
def EmitHLS : FunctionPass<"emit-HLS"> {
134-
let summary = "Raise MLIR to HLS C/C++.";
133+
def EmitHLSPass : Pass<"emit-hls", "::mlir::ModuleOp"> {
134+
let summary = "Emit HLS code from MLIR";
135+
let description = [{
136+
Emit HLS code for the given program. It could be either default implementation of traditional HLS hardware,
137+
or a dataflow architecture by bufferizing the inputs and outputs.
138+
}];
135139
let constructor = "phism::createEmitHLSPass()";
136140
let options = [
141+
Option<"fileName", "file-name", "std::string", /*default=*/"", "The output HLS code">,
142+
Option<"hlsParam", "hls-param", "std::string", /*default=*/"", "The HLS parameters for quantization">
137143
];
138144
}
139145

include/phism/mlir/Transforms/PhismTransforms.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ void registerLoopTransformPasses();
1414
void registerFoldIfPasses();
1515
void registerAllPhismPasses();
1616
// void registerDependenceAnalysisPasses();
17+
void registerEmitHLSPass();
1718
} // namespace phism
1819

1920
#endif

lib/mlir/Transforms/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ add_mlir_library(PhismTransforms
1313
LiftMemRefSubview.cc
1414
SCoPDecomposition.cc
1515
LoadSwitch.cc
16+
EmitHLS.cc
1617
Utils.cc
1718

1819
ADDITIONAL_HEADER_DIRS
@@ -31,4 +32,9 @@ add_mlir_library(PhismTransforms
3132
MLIRStandard
3233
MLIRSupport
3334
MLIRAffineToStandard
35+
MLIRLinalgAnalysis
36+
MLIRLinalg
37+
MLIRLinalgTransforms
38+
MLIRLinalgUtils
39+
MLIRSCF
3440
)

0 commit comments

Comments
 (0)