forked from OAID/AutoKernel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
04_test_relu.cpp
49 lines (43 loc) · 1.51 KB
/
04_test_relu.cpp
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "HalideBuffer.h"
#include <iostream>
#include "halide_relu.h"
int main(int argc, char **argv)
{
int C = 1, W = 4, H = 4, N = 1;
Halide::Runtime::Buffer<float> input_tensor(nullptr, W, H, C, N);
Halide::Runtime::Buffer<float> output_tensor(nullptr, W, H, C, N);
input_tensor.allocate();
output_tensor.allocate();
input_tensor.for_each_value([](float &x) {
x = 2.0 * rand() / RAND_MAX - 1.0;
});
output_tensor.for_each_value([](float &x) {
x = 2.0 * rand() / RAND_MAX - 1.0;
});
halide_relu(input_tensor, 0, output_tensor);
printf("input:\n");
for (int c = 0; c < input_tensor.dim(3).extent(); c++) {
for (int z = 0; z < input_tensor.channels(); z++) {
for (int y = 0; y < input_tensor.height(); y++) {
for (int x = 0; x < input_tensor.width(); x++) {
std::cout<<input_tensor(x,y,z,0)<<" ";
}
std::cout<<"\n";
}
std::cout<<"\n";
}
}
printf("output:\n");
for (int c = 0; c < output_tensor.dim(3).extent(); c++) {
for (int z = 0; z < output_tensor.channels(); z++) {
for (int y = 0; y < output_tensor.height(); y++) {
for (int x = 0; x < output_tensor.width(); x++) {
std::cout<<output_tensor(x,y,z,0)<<" ";
}
std::cout<<"\n";
}
std::cout<<"\n";
}
}
return 0;
}