From ec7278bd443800dd7267b1e46f17e751af33df1b Mon Sep 17 00:00:00 2001 From: Filip Leonarski Date: Wed, 18 Oct 2023 14:44:30 +0200 Subject: [PATCH] HLS: Changes to allow cosimulation with Vitis HLS --- fpga/hls/CMakeLists.txt | 2 +- fpga/hls/hls_bitshuffle.cpp | 2 +- fpga/hls/hls_jfjoch.h | 8 ++---- fpga/hls/spot_finder.cpp | 28 +++++++------------ fpga/hls/spot_finder_tb.cpp | 56 +++++++++++++++++++++++++++++++++++++ 5 files changed, 71 insertions(+), 25 deletions(-) create mode 100644 fpga/hls/spot_finder_tb.cpp diff --git a/fpga/hls/CMakeLists.txt b/fpga/hls/CMakeLists.txt index 2bbf389b..84e87841 100644 --- a/fpga/hls/CMakeLists.txt +++ b/fpga/hls/CMakeLists.txt @@ -26,7 +26,7 @@ ADD_LIBRARY( HLSSimulation STATIC TARGET_INCLUDE_DIRECTORIES(HLSSimulation PUBLIC ../include) TARGET_LINK_LIBRARIES(HLSSimulation CommonFunctions) -TARGET_COMPILE_DEFINITIONS(HLSSimulation PRIVATE -DNO_SYNTH) +TARGET_COMPILE_DEFINITIONS(HLSSimulation PUBLIC -DJFJOCH_HLS_NOSYNTH) IF(VIVADO_HLS) diff --git a/fpga/hls/hls_bitshuffle.cpp b/fpga/hls/hls_bitshuffle.cpp index f68639eb..dfe9603e 100644 --- a/fpga/hls/hls_bitshuffle.cpp +++ b/fpga/hls/hls_bitshuffle.cpp @@ -322,7 +322,7 @@ void bitshuffle(STREAM_512 &data_in, STREAM_512 &data_out) { BSHUF_STREAM fifo_4_3; #pragma HLS STREAM variable=fifo_4_3 depth=32 -#ifdef __SYNTHESIS__ +#ifndef JFJOCH_HLS_NOSYNTH bshuf256(data_in, fifo_0); bshuf1k_axis_split(fifo_0, fifo_1_0, fifo_1_1, fifo_1_2, fifo_1_3); bshuf1k_axis_combine(fifo_1_0, fifo_1_1, fifo_1_2, fifo_1_3, fifo_2); diff --git a/fpga/hls/hls_jfjoch.h b/fpga/hls/hls_jfjoch.h index 3e6cef7c..b9f73659 100644 --- a/fpga/hls/hls_jfjoch.h +++ b/fpga/hls/hls_jfjoch.h @@ -1,19 +1,17 @@ // Copyright (2019-2023) Paul Scherrer Institute - #ifndef JUNGFRAUJOCH_HLS_JFJOCH_H #define JUNGFRAUJOCH_HLS_JFJOCH_H #include #include #include +#include -#ifdef __SYNTHESIS__ +#ifndef JFJOCH_HLS_NOSYNTH #include #include -#include #else -#include "../include/hls_burst_maxi.h" #include "parallel_stream.h" #endif @@ -31,7 +29,7 @@ typedef ap_ufixed<16,12, AP_RND_CONV> strong_pixel_threshold_t; typedef ap_uint<256> hbm256_t; -#ifndef __SYNTHESIS__ +#ifdef JFJOCH_HLS_NOSYNTH template struct ap_axiu{ ap_uint data; diff --git a/fpga/hls/spot_finder.cpp b/fpga/hls/spot_finder.cpp index 1c3108a3..7ec448de 100644 --- a/fpga/hls/spot_finder.cpp +++ b/fpga/hls/spot_finder.cpp @@ -361,6 +361,7 @@ void spot_finder(STREAM_512 &data_in, hls::stream> &strong_pixel_out, volatile ap_int<16> &in_photon_count_threshold, volatile ap_uint<16> &in_strong_pixel_threshold) { +// Comment line below for Vitis HLS Cosimulation #pragma HLS INTERFACE ap_ctrl_none port=return #pragma HLS DATAFLOW @@ -370,37 +371,28 @@ void spot_finder(STREAM_512 &data_in, #pragma HLS INTERFACE ap_none register port=in_photon_count_threshold #pragma HLS INTERFACE ap_none register port=in_strong_pixel_threshold - hls::stream data_stream_0, data_stream_1, data_stream_2; - hls::stream> sum_stream_0, sum_stream_1, sum_stream_2; - hls::stream> sum2_stream_0, sum2_stream_1, sum2_stream_2; - hls::stream> valid_stream_0, valid_stream_1, valid_stream_2; -#pragma HLS STREAM variable=data_stream_0 depth=512 type=fifo + hls::stream data_stream_0; + hls::stream data_stream_1, data_stream_2; + hls::stream, 16> sum_stream_0; + hls::stream, 8> sum_stream_1, sum_stream_2; + hls::stream, 16> sum2_stream_0; + hls::stream, 8> sum2_stream_1, sum2_stream_2; + hls::stream, 16> valid_stream_0; + hls::stream, 8> valid_stream_1, valid_stream_2; #pragma HLS bind_storage variable=data_stream_0 type=fifo impl=bram -#pragma HLS STREAM variable=data_stream_1 depth=64 type=fifo #pragma HLS bind_storage variable=data_stream_1 type=fifo impl=bram -#pragma HLS STREAM variable=data_stream_2 depth=64 type=fifo #pragma HLS bind_storage variable=data_stream_2 type=fifo impl=bram - -#pragma HLS STREAM variable=sum_stream_0 depth=512 type=fifo #pragma HLS bind_storage variable=sum_stream_0 type=fifo impl=bram -#pragma HLS STREAM variable=sum_stream_1 depth=64 type=fifo #pragma HLS bind_storage variable=sum_stream_1 type=fifo impl=bram -#pragma HLS STREAM variable=sum_stream_2 depth=64 type=fifo #pragma HLS bind_storage variable=sum_stream_2 type=fifo impl=bram -#pragma HLS STREAM variable=sum2_stream_0 depth=512 type=fifo #pragma HLS bind_storage variable=sum2_stream_0 type=fifo impl=bram -#pragma HLS STREAM variable=sum2_stream_1 depth=64 type=fifo #pragma HLS bind_storage variable=sum2_stream_1 type=fifo impl=bram -#pragma HLS STREAM variable=sum2_stream_2 depth=64 type=fifo #pragma HLS bind_storage variable=sum2_stream_2 type=fifo impl=bram -#pragma HLS STREAM variable=valid_stream_0 depth=512 type=fifo #pragma HLS bind_storage variable=valid_stream_0 type=fifo impl=bram -#pragma HLS STREAM variable=valid_stream_1 depth=64 type=fifo #pragma HLS bind_storage variable=valid_stream_1 type=fifo impl=bram -#pragma HLS STREAM variable=valid_stream_2 depth=64 type=fifo #pragma HLS bind_storage variable=valid_stream_2 type=fifo impl=bram -#ifdef __SYNTHESIS__ +#ifndef JFJOCH_HLS_NOSYNTH spot_finder_col_sum(data_in, data_stream_0, sum_stream_0, sum2_stream_0, valid_stream_0); spot_finder_line_sum(data_stream_0, data_stream_1, sum_stream_0, sum2_stream_0, valid_stream_0, diff --git a/fpga/hls/spot_finder_tb.cpp b/fpga/hls/spot_finder_tb.cpp new file mode 100644 index 00000000..33ce43b5 --- /dev/null +++ b/fpga/hls/spot_finder_tb.cpp @@ -0,0 +1,56 @@ +#include "hls_jfjoch.h" +#include + +int main() { + + int ret = 0; + + STREAM_512 input; + STREAM_512 output; + hls::stream> strong_pixel; + + ap_int<16> in_photon_count_threshold = 8; + ap_uint<16> in_strong_pixel_threshold = 16; + + std::vector input_frame(4 * RAW_MODULE_SIZE), output_frame( + RAW_MODULE_SIZE); + for (int i = 0; i < 4 * RAW_MODULE_SIZE; i++) { + if (i % RAW_MODULE_COLS == 1023) + input_frame[i] = INT16_MIN; + else + input_frame[i] = i % RAW_MODULE_COLS; + } + auto input_frame_512 = (ap_uint<512>*) input_frame.data(); + auto output_frame_512 = (ap_uint<512>*) output_frame.data(); + + input << packet_512_t { .user = 0 }; + for (int i = 0; i < 4 * RAW_MODULE_SIZE * sizeof(uint16_t) / 64; i++) + input << packet_512_t { .data = input_frame_512[i], .user = 0 }; + + input << packet_512_t { .user = 1 }; + + spot_finder(input, output, strong_pixel, in_photon_count_threshold, + in_strong_pixel_threshold); + + if (input.size() != 0) + ret = 1; + if (output.size() != 4 * RAW_MODULE_SIZE * sizeof(uint16_t) / 64 + 2) + ret = 1; + for (int i = 0; i < 4 * RAW_MODULE_SIZE * sizeof(uint16_t) / 64 + 2; i++) + output.read(); + + if (strong_pixel.size() != 4 * RAW_MODULE_SIZE * sizeof(uint16_t) / 64 + 1) + ret = 1; + for (int i = 0; i < 4 * RAW_MODULE_SIZE * sizeof(uint16_t) / 64 + 1; i++) + strong_pixel.read(); + + + if (ret != 0) { + printf("Test failed !!!\n"); + ret = 1; + } else { + printf("Test passed !\n"); + } + + return ret; +}