From 736a181e5e24406de55c98bf182cbc506f415ee1 Mon Sep 17 00:00:00 2001 From: Filip Leonarski Date: Wed, 18 Oct 2023 15:19:01 +0200 Subject: [PATCH] HLS: Spot finder outputs parameters + statistics --- fpga/hls/host_writer.cpp | 3 ++- fpga/hls/spot_finder.cpp | 40 ++++++++++++++++++++++--------- fpga/hls/spot_finder_tb.cpp | 5 ++-- receiver/AcquisitionDevice.cpp | 4 ++-- tests/FPGASpotFindingUnitTest.cpp | 2 +- 5 files changed, 36 insertions(+), 18 deletions(-) diff --git a/fpga/hls/host_writer.cpp b/fpga/hls/host_writer.cpp index e7cf3c35..b9724873 100644 --- a/fpga/hls/host_writer.cpp +++ b/fpga/hls/host_writer.cpp @@ -130,6 +130,7 @@ void host_writer(STREAM_512 &data_in, read_request(s_axis_work_request, req_handle, req_host_offset); setup_datamover(datamover_out_cmd, req_host_offset, RAW_MODULE_SIZE * sizeof(uint16_t) * (16 + 1) / 16 + + 64 + (FPGA_INTEGRATION_BIN_COUNT/2)*64 + ADU_HISTO_BIN_COUNT / 16 * 64); @@ -148,7 +149,7 @@ void host_writer(STREAM_512 &data_in, host_memory_out << packet_out; } - for (int i = 0; i < RAW_MODULE_SIZE * sizeof(uint16_t) / (64 * 16); i++) { + for (int i = 0; i < RAW_MODULE_SIZE * sizeof(uint16_t) / (64 * 16) + 1; i++) { #pragma HLS PIPELINE II=1 spot_finder_in >> packet_out.data; host_memory_out << packet_out; diff --git a/fpga/hls/spot_finder.cpp b/fpga/hls/spot_finder.cpp index 7ec448de..4ba2026d 100644 --- a/fpga/hls/spot_finder.cpp +++ b/fpga/hls/spot_finder.cpp @@ -308,15 +308,23 @@ void spot_finder_line_sum_align(hls::stream &data_in, data_out << packet_in; } -strong_pixel_threshold_t calculate_threshold(volatile ap_uint<16> &in_strong_pixel_threshold) { +strong_pixel_threshold_t calculate_threshold(ap_uint<16> &in_snr_threshold) { #pragma HLS INLINE - ap_uint<16> tmp = in_strong_pixel_threshold; - strong_pixel_threshold_t strong_pixel_threshold = 0; + ap_uint<16> tmp = in_snr_threshold; + strong_pixel_threshold_t snr_threshold = 0; for (int i = 0; i < 16; i++) { #pragma HLS UNROLL - strong_pixel_threshold[i] = tmp[i]; + snr_threshold[i] = tmp[i]; } - return strong_pixel_threshold * strong_pixel_threshold; + return snr_threshold * snr_threshold; +} + +ap_uint<32> count_pixels(ap_uint<32> &in) { +#pragma HLS INLINE + ap_uint<32> ret = 0; + for (int i = 0; i < 32; i++) + ret += in[i]; + return ret; } void spot_finder_check_threshold(hls::stream &data_in, @@ -325,8 +333,8 @@ void spot_finder_check_threshold(hls::stream &data_in, hls::stream> &sum2_in, hls::stream> &valid_in, hls::stream> &strong_pixel_out, - volatile ap_int<16> &in_photon_count_threshold, - volatile ap_uint<16> &in_strong_pixel_threshold) { + volatile ap_int<16> &in_count_threshold, + volatile ap_uint<16> &in_snr_threshold) { spot_finder_packet packet_in; data_in >> packet_in; data_out << packet_512_t{.data=packet_in.data, .user=0, .last=0}; @@ -336,8 +344,11 @@ void spot_finder_check_threshold(hls::stream &data_in, data_in >> packet_in; while (!packet_in.user) { - ap_int<16> photon_count_threshold = in_photon_count_threshold; - strong_pixel_threshold_t strong_pixel_threshold_sq = calculate_threshold(in_strong_pixel_threshold); + ap_int<16> count_threshold = in_count_threshold; + ap_uint<16> snr_threshold = in_snr_threshold; + strong_pixel_threshold_t snr_threshold_sq = calculate_threshold(snr_threshold); + uint32_t strong_pixel_count = 0; + for (int i = 0; i < RAW_MODULE_SIZE * sizeof(uint16_t) / 64; i++) { #pragma HLS PIPELINE II=1 data_out << packet_512_t{.data=packet_in.data, .user=0, .last=0}; @@ -346,11 +357,18 @@ void spot_finder_check_threshold(hls::stream &data_in, valid_in >> line_valid; ap_axiu<32, 1, 1, 1> strong_pixel{.user = 0}; - strong_pixel.data = check_threshold(packet_in.data, line_sum, line_sum2, line_valid, - strong_pixel_threshold_sq, photon_count_threshold); + strong_pixel.data = check_threshold(packet_in.data, line_sum, line_sum2, line_valid, snr_threshold_sq, count_threshold); + strong_pixel_count += count_pixels(strong_pixel.data); strong_pixel_out << strong_pixel; data_in >> packet_in; } + + // Save parameters used for spot finding + count of + strong_pixel_out << ap_axiu<32, 1, 1, 1>{.data = count_threshold, .user = 0}; + strong_pixel_out << ap_axiu<32, 1, 1, 1>{.data = snr_threshold, .user = 0}; + strong_pixel_out << ap_axiu<32, 1, 1, 1>{.data = strong_pixel_count, .user = 0}; + for (int i = 0; i < 13; i++) + strong_pixel_out << ap_axiu<32, 1, 1, 1>{.data = 0, .user = 0}; } strong_pixel_out << ap_axiu<32,1,1,1>{.data = 0, .user = 1}; data_out << packet_512_t{.data=0, .user=1, .last=1}; diff --git a/fpga/hls/spot_finder_tb.cpp b/fpga/hls/spot_finder_tb.cpp index 33ce43b5..fb4407e0 100644 --- a/fpga/hls/spot_finder_tb.cpp +++ b/fpga/hls/spot_finder_tb.cpp @@ -39,12 +39,11 @@ int main() { 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) + if (strong_pixel.size() != 4 * (RAW_MODULE_SIZE * sizeof(uint16_t) / 64 + 1) + 1) ret = 1; - for (int i = 0; i < 4 * RAW_MODULE_SIZE * sizeof(uint16_t) / 64 + 1; i++) + for (int i = 0; i < 4 * (RAW_MODULE_SIZE * sizeof(uint16_t) / 64 + 1) + 1; i++) strong_pixel.read(); - if (ret != 0) { printf("Test failed !!!\n"); ret = 1; diff --git a/receiver/AcquisitionDevice.cpp b/receiver/AcquisitionDevice.cpp index c2aa80cb..1a0c5ecb 100644 --- a/receiver/AcquisitionDevice.cpp +++ b/receiver/AcquisitionDevice.cpp @@ -163,12 +163,12 @@ const int16_t *AcquisitionDevice::GetFrameBuffer(size_t frame_number, uint16_t m const IntegrationResult *AcquisitionDevice::GetIntegrationResult(size_t frame_number, uint16_t module_number) const { return reinterpret_cast(GetFrameBuffer(frame_number, module_number) - + 17 * RAW_MODULE_SIZE / 16); + + 17 * RAW_MODULE_SIZE / 16 + 32); } const uint32_t *AcquisitionDevice::GetADUHistogram(size_t frame_number, uint16_t module_number) const { return reinterpret_cast(GetFrameBuffer(frame_number, module_number) - + 17 * RAW_MODULE_SIZE / 16 + + 17 * RAW_MODULE_SIZE / 16 + 32 + FPGA_INTEGRATION_BIN_COUNT * sizeof(IntegrationResult) / sizeof(uint16_t)); } diff --git a/tests/FPGASpotFindingUnitTest.cpp b/tests/FPGASpotFindingUnitTest.cpp index d03de9c2..a34442ac 100644 --- a/tests/FPGASpotFindingUnitTest.cpp +++ b/tests/FPGASpotFindingUnitTest.cpp @@ -418,5 +418,5 @@ TEST_CASE("FPGA_spot_finder_core","[FPGA][SpotFinder]") { REQUIRE(input.size() == 0); REQUIRE(output.size() == RAW_MODULE_SIZE * sizeof(uint16_t) / 64 + 2); - REQUIRE(strong_pixel.size() == RAW_MODULE_SIZE * sizeof(uint16_t) / 64 + 1); + REQUIRE(strong_pixel.size() == RAW_MODULE_SIZE * sizeof(uint16_t) / 64 + 16 + 1); } \ No newline at end of file