From 2cfde3a82db2798602a38e7faa4fa9f6783d6b72 Mon Sep 17 00:00:00 2001 From: Filip Leonarski Date: Fri, 22 Sep 2023 20:43:52 +0200 Subject: [PATCH] FPGA: spot_finder early work in progress --- fpga/hls/CMakeLists.txt | 5 ++++- fpga/hls/hls_jfjoch.h | 4 ++++ fpga/hls/spot_finder.cpp | 46 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 fpga/hls/spot_finder.cpp diff --git a/fpga/hls/CMakeLists.txt b/fpga/hls/CMakeLists.txt index 02a7aa59..aebcaad3 100644 --- a/fpga/hls/CMakeLists.txt +++ b/fpga/hls/CMakeLists.txt @@ -17,7 +17,8 @@ ADD_LIBRARY( HLSSimulation STATIC save_to_hbm.cpp load_from_hbm.cpp integration.cpp - mask_missing.cpp) + mask_missing.cpp + spot_finder.cpp) TARGET_INCLUDE_DIRECTORIES(HLSSimulation PUBLIC ../include) TARGET_LINK_LIBRARIES(HLSSimulation CommonFunctions) @@ -54,6 +55,7 @@ MAKE_HLS_MODULE(load_from_hbm.cpp load_from_hbm) MAKE_HLS_MODULE(save_to_hbm.cpp save_to_hbm) MAKE_HLS_MODULE(mask_missing.cpp mask_missing) MAKE_HLS_MODULE(integration.cpp integration) +MAKE_HLS_MODULE(spot_finder.cpp spot_finder) SET (HLS_IPS psi_ch_hls_data_collection_fsm_1_0.zip psi_ch_hls_timer_host_1_0.zip @@ -70,6 +72,7 @@ SET (HLS_IPS psi_ch_hls_data_collection_fsm_1_0.zip psi_ch_hls_save_to_hbm_1_0.zip psi_ch_hls_mask_missing_1_0.zip psi_ch_hls_frame_generator_1_0.zip + psi_ch_hls_spot_finder_1_0.zip psi_ch_hls_integration_1_0.zip psi_ch_hls_stream_merge_1_0.zip) diff --git a/fpga/hls/hls_jfjoch.h b/fpga/hls/hls_jfjoch.h index 122d7d99..9505b416 100644 --- a/fpga/hls/hls_jfjoch.h +++ b/fpga/hls/hls_jfjoch.h @@ -185,6 +185,10 @@ void integration(STREAM_512 &data_in, ap_uint<256> *d_hbm_p0, ap_uint<256> *d_hbm_p1); +void spot_finder(STREAM_512 &data_in, + STREAM_512 &data_out, + hls::stream> &result_out); + template ap_uint pack32(ap_int in[32]) { #pragma HLS INLINE ap_uint out; diff --git a/fpga/hls/spot_finder.cpp b/fpga/hls/spot_finder.cpp new file mode 100644 index 00000000..f5d13af7 --- /dev/null +++ b/fpga/hls/spot_finder.cpp @@ -0,0 +1,46 @@ +// Copyright (2019-2023) Paul Scherrer Institute + +// Copyright (2019-2023) Paul Scherrer Institute + +#include "hls_jfjoch.h" + +void spot_finder(STREAM_512 &data_in, + STREAM_512 &data_out, + hls::stream> &result_out) { +#pragma HLS INTERFACE ap_ctrl_none port=return +#pragma HLS INTERFACE register both axis port=data_in +#pragma HLS INTERFACE register both axis port=data_out +#pragma HLS INTERFACE register both axis port=result_out + + packet_512_t packet; + data_in >> packet; + data_out << packet; + + ap_uint<32> result[RAW_MODULE_SIZE * sizeof(uint16_t) / 64]; +#pragma HLS ARRAY_PARTITION variable=result type=cyclic factor=16 + + ap_int<16> val[32]; + data_in >> packet; + while (!packet.user) { + for (int i = 0; i < RAW_MODULE_SIZE * sizeof(uint16_t) / 64; i++) { +#pragma HLS PIPELINE II=1 + ap_uint<32> output = 0; + data_out << packet; + unpack32(packet.data, val); + for (int j = 0; j < 32; j++) { + if (val[j] > 5) + output[j] = 1; + } + data_in >> packet; + result[i] = output; + } + for (int i = 0; i < RAW_MODULE_SIZE * sizeof(uint16_t) / (64 * 16); i++) { +#pragma HLS PIPELINE II=1 + ap_uint<512> output = 0; + for (int j = 0; j < 16; j++) + output(j*32+31, j * 32) = result[i * 16 + j]; + result_out << output; + } + } + data_out << packet; +}