Skip to content
Closed
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
40 changes: 40 additions & 0 deletions test/neura/for_loop/relu.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <stdio.h>

#define N 32

int input[N] = {
1, -1, 2, -3, 4, -5, 6, -7,
8, -9, 10, -11, 12, -13, 14, -15,
16, -17, 18, -19, 20, -21, 22, -23,
24, -25, 26, -27, 28, -29, 30, -31
};

int output[N];

void kernel(float input[], float output[]);

int main(){
//init output
for(int i = 0; i < N; i++){
output[i] = 0;
}

kernel(intput, output);

//print outputs
for(int i = 0; i < N; i++){
print("output[%d] = %f\n", i, output[i]);
}

return 0;
}

void kernel(int input[], int output []){
for(int i = 0; i < N; ++i){
if(input[i] > 0){
output[i] += input[i];
} else {
output[i] += 0;
}
}
}
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.

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.

Hi, cheng. I’ve modified other parts of relu.cpp, but I’ll need a bit more time to provide the MLIR test.

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.

Sure, take your time.

The corresponding mlir test has no mlir IRs there, it is just a bunch of commands to transform your provided C++ to our neura dialect.

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.

Do you mean that we only need to provide the RUN part, but not the CHECK part?

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.

CHECK part is also necessary, but they are just what generated by the corresponding command. For example,

// RUN: mlir-neura-opt %t-kernel.mlir\
// RUN:   --assign-accelerator \
// RUN:   --lower-llvm-to-neura \
// RUN:   --canonicalize-live-in \
// RUN:   --leverage-predicated-value \
// RUN:  | FileCheck %s

the FileCheck %s is for making sure the code/IR after CHECK and CHECK-NEXT are generated from above commands.

// RUN: | FileCheck %s --check-prefix=CHECK-FUSED is for making sure the code/IR after CHECK-FUSED and CHECK-FUSED-NEXT are generated from following commands:

// 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:   --fold-constant \
// RUN:   --fuse-pattern \
// RUN:  | FileCheck %s --check-prefix=CHECK-FUSED

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.

Ok, I see. I will try to make a mlir test for relu.cpp.