LCOV - code coverage report
Current view: top level - tpglibs/unittest - avx_processors_test.cxx (source / functions) Coverage Total Hit
Test: code.result Lines: 93.9 % 49 46
Test Date: 2026-10-11 15:05:20 Functions: 100.0 % 2 2

            Line data    Source code
       1              : /**
       2              :  * @file avx_processors_test.cxx
       3              :  *
       4              :  * @copyright This is part of the DUNE DAQ Software Suite, copyright 2020.
       5              :  * Licensing/copyright details are in the COPYING file that you should have
       6              :  * received with this code.
       7              :  */
       8              : 
       9              : #define BOOST_TEST_MODULE boost_test_macro_overview
      10              : #define FMT_HEADER_ONLY
      11              : 
      12              : #include "tpglibs/AVXAbsRunSumProcessor.hpp"
      13              : #include "tpglibs/AVXFrugalPedestalSubtractProcessor.hpp"
      14              : #include "tpglibs/AVXRunSumProcessor.hpp"
      15              : #include "tpglibs/AVXThresholdProcessor.hpp"
      16              : 
      17              : #include <atomic>
      18              : #include <boost/test/unit_test.hpp>
      19              : #include <fmt/core.h>
      20              : #include <fmt/ranges.h>
      21              : #include <immintrin.h>
      22              : #include <thread>
      23              : 
      24              : namespace tpglibs {
      25              : 
      26            2 : BOOST_AUTO_TEST_CASE(test_macro_overview)
      27              : {
      28            1 :   std::shared_ptr<AVXProcessor> thresholds = std::make_shared<AVXThresholdProcessor>();
      29            1 :   std::shared_ptr<AVXProcessor> abs_rs = std::make_shared<AVXAbsRunSumProcessor>();
      30            1 :   std::shared_ptr<AVXProcessor> rs = std::make_shared<AVXRunSumProcessor>();
      31              : 
      32            1 :   int16_t plane_numbers[16] = { 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2 };
      33              : 
      34           10 :   nlohmann::json thr_config = { { "plane0", 300 }, { "plane1", 700 }, { "plane2", 1300 } };
      35            1 :   thresholds->configure(thr_config, plane_numbers);
      36              : 
      37            5 :   nlohmann::json rs_config = { { "memory_factor_plane0", 4 },  { "memory_factor_plane1", 4 },
      38            4 :                                { "memory_factor_plane2", 4 },  { "scale_factor_plane0", 1 },
      39            4 :                                { "scale_factor_plane1", 1 },   { "scale_factor_plane2", 1 },
      40            4 :                                { "memory_divisor_plane0", 5 }, { "memory_divisor_plane1", 5 },
      41            4 :                                { "memory_divisor_plane2", 5 }, { "scale_divisor_plane0", 2 },
      42           37 :                                { "scale_divisor_plane1", 2 },  { "scale_divisor_plane2", 2 } };
      43            1 :   abs_rs->configure(rs_config, plane_numbers);
      44            1 :   rs->configure(rs_config, plane_numbers);
      45              : 
      46              :   // Arbitrary input choices. Set so RS resets to 0.
      47            1 :   __m256i input0 =
      48            1 :     _mm256_set_epi16(-1600, 1500, -1400, 1300, -1200, 1100, -1000, 900, -800, 700, -600, 500, -400, 300, -200, 100);
      49            1 :   __m256i input1 =
      50            1 :     _mm256_set_epi16(2880, -2700, 2520, -2340, 2160, -1980, 1800, -1620, 1440, -1260, 1080, -900, 720, -540, 360, -180);
      51            1 :   __m256i input2 =
      52            1 :     _mm256_set_epi16(-1280, 1200, -1120, 1040, -960, 880, -800, 720, -640, 560, -480, 400, -320, 240, -160, 80);
      53              : 
      54            1 :   __m256i avx_thr_output = thresholds->process(input0); // Only using the first.
      55              : 
      56            1 :   __m256i avx_abs_output = abs_rs->process(input0);
      57            1 :   avx_abs_output = abs_rs->process(input1);
      58            1 :   avx_abs_output = abs_rs->process(input2);
      59            1 :   __m256i avx_rs_output = rs->process(input0);
      60            1 :   avx_rs_output = rs->process(input1);
      61            1 :   avx_rs_output = rs->process(input2);
      62              : 
      63            1 :   int16_t abs_output[16], thr_output[16], rs_output[16];
      64            1 :   _mm256_storeu_si256(reinterpret_cast<__m256i*>(&abs_output), avx_abs_output);
      65            1 :   _mm256_storeu_si256(reinterpret_cast<__m256i*>(&thr_output), avx_thr_output);
      66            1 :   _mm256_storeu_si256(reinterpret_cast<__m256i*>(&rs_output), avx_rs_output);
      67              : 
      68            1 :   bool same_abs = true;
      69            1 :   bool same_thr = true;
      70            1 :   bool same_rs = true;
      71              : 
      72            1 :   int16_t expected_abs[16] = {
      73              :     144, 288, 432, 576, 720, 864, 1008, 1152, 1296, 1440, 1584, 1728, 1872, 2016, 2160, 2304
      74              :   };
      75            1 :   int16_t expected_thr[16] = { 0, 0, 0, 0, 500, 0, 0, 0, 900, 0, 0, 0, 0, 0, 1500, 0 };
      76            1 :   int16_t expected_rs[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
      77              : 
      78           17 :   for (int i = 0; i < 16; i++) {
      79           16 :     if (expected_abs[i] != abs_output[i])
      80            0 :       same_abs = false;
      81           16 :     if (expected_thr[i] != thr_output[i])
      82            0 :       same_thr = false;
      83           16 :     if (expected_rs[i] != rs_output[i])
      84            0 :       same_rs = false;
      85              :   }
      86              : 
      87              :   //  fmt::print("AbsRS: [{:5}]\n", fmt::join(abs_output, ","));
      88              :   //  fmt::print("Thr:   [{:5}]\n", fmt::join(thr_output, ","));
      89              :   //  fmt::print("RS:    [{:5}]\n", fmt::join(rs_output, ","));
      90              : 
      91            1 :   BOOST_TEST(same_abs);
      92            1 :   BOOST_TEST(same_thr);
      93            1 :   BOOST_TEST(same_rs);
      94           34 : }
      95              : 
      96              : } // namespace tpglibs
        

Generated by: LCOV version 2.0-1