diff --git a/tests/input_0.npy b/tests/input_0.npy index fe284575770741535ba3ef7d5db9a363590a866f..c76e417f1297d18ac69b9c4dfc8747bb883d77d0 100644 Binary files a/tests/input_0.npy and b/tests/input_0.npy differ diff --git a/tests/layer_streaming_maxpool b/tests/layer_streaming_maxpool deleted file mode 100755 index 14d084ce2b1bdc4b96562c93caa57f163690d8bd..0000000000000000000000000000000000000000 Binary files a/tests/layer_streaming_maxpool and /dev/null differ diff --git a/tests/layer_streaming_maxpool.cpp b/tests/layer_streaming_maxpool.cpp index 94c926ac912ee38f0a8ed9ae04b59c65f3202674..26d27377956a12bae4f810d72c918de0ec387742 100755 --- a/tests/layer_streaming_maxpool.cpp +++ b/tests/layer_streaming_maxpool.cpp @@ -2,25 +2,56 @@ #include<complex> #include<cstdlib> #include<map> +#include <vector> #include "bnn-library.h" +#include "maxpool.h" #define ImgDim 4 #define PoolDim 2 #define NumChannels 2 int main(){ - std::cout << "TEST" << std::endl; + typedef struct{ + ap_uint<2> last_data; + std::vector<ap_uint<2>> data; + bool valid; + bool invert; + } input_interface; + input_interface i, k; cnpy::NpyArray arr = cnpy::npy_load("input_0.npy"); float* loaded_data = arr.data<float>(); - std::cout << arr.shape.size() << std::endl; int Nx = arr.shape[0]; int Ny = arr.shape[1]; int Nz = arr.shape[2]; - for(int i = 0; i < Nx*Ny*Nz;i++) { - std::cout << loaded_data[i] << std::endl; + + hls::stream<ap_uint<2>> in ("in"); + hls::stream<ap_uint<2>> out ("out"); + #pragma HLS DATAFLOW + #pragma HLS stream depth=1024 variable=in + #pragma HLS stream depth=1024 variable=out + for(int i=0;i < Nx*Ny*Nz;i++){ + in << loaded_data[i]; } - hls::stream<ap_uint<2>> in; - cnpy::npy_save("output.npy",&loaded_data[0],{Nx,Ny,Nz},"w"); + //while(in.read_nb(i.last_data)){ + // i.data.push_back(i.last_data); + //} + //for(std::vector<ap_uint<2>>::iterator it = i.data.begin(); it!= i.data.end(); ++it){ + // std::cout << "Next value: " << *it << std::endl; + //} + + StreamingMaxPool<ImgDim, PoolDim, NumChannels>(in, out); + while(out.read_nb(k.last_data)){ + k.data.push_back(k.last_data); + } + std::vector<float> output_data; + for(std::vector<ap_uint<2>>::iterator it = k.data.begin(); it!= k.data.end(); ++it){ + ap_uint<2> test = *it; + output_data.push_back(test.range(0,0)); + output_data.push_back(test.range(1,1)); + + + } + cnpy::npy_save("output.npy",&output_data[0],{2,2,2},"w"); } diff --git a/tests/layer_test.sh b/tests/layer_test.sh index 5140538c91683b3ccc49dda101e1698e097c914b..0dc0e2457ebfa214006bd155ecdd82188b742cd6 100755 --- a/tests/layer_test.sh +++ b/tests/layer_test.sh @@ -1,4 +1,4 @@ #!/bin/sh -g++ -o layer_streaming_maxpool layer_streaming_maxpool.cpp /workspace/finn/cnpy/cnpy.cpp -I/workspace/finn/cnpy/ -I/workspace/finn/finn-hlslib --std=c++11 -lz +g++ -o layer_streaming_maxpool layer_streaming_maxpool.cpp /workspace/finn/cnpy/cnpy.cpp -I/workspace/finn/cnpy/ -I/workspace/finn/finn-hlslib -I/workspace/vivado-hlslib --std=c++11 -lz diff --git a/tests/output.npy b/tests/output.npy index ef0cf595b190c091938cb0dc947d1b115a0f84a0..013e68979bf26a22c79cbf0dc7ac0045c75eb317 100644 Binary files a/tests/output.npy and b/tests/output.npy differ diff --git a/tests/test_layer_streaming_maxpool.py b/tests/test_layer_streaming_maxpool.py index 5900662271fef4b4e5aaa03cb9099d426e64fef8..83c8726d7c724c3be027c17fc895323e31e62779 100644 --- a/tests/test_layer_streaming_maxpool.py +++ b/tests/test_layer_streaming_maxpool.py @@ -39,40 +39,41 @@ def test_layer_streaming_maxpool(): input_tensor = np.asarray( [ 1, - -1, 1, - -1, - -1, 1, 1, 1, 1, - -1, - -1, 1, 1, - -1, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, 1, - -1, 1, 1, - -1, 1, - -1, - -1, - -1, - -1, - -1, 1, 1, - -1, 1, 1, - 1, - -1, ], dtype=np.float32, ).reshape(2, 4, 4) + print(input_tensor) input_dict = {"in": input_tensor} output_dict = oxe.execute_onnx(model, input_dict)