LCOV - code coverage report
Current view: top level - tpglibs/unittest - avx_processors_test.cxx (source / functions) Coverage Total Hit
Test: code.result Lines: 100.0 % 58 58
Test Date: 2025-12-21 13:07:08 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/AVXRunSumProcessor.hpp"
      13              : #include "tpglibs/AVXAbsRunSumProcessor.hpp"
      14              : #include "tpglibs/AVXThresholdProcessor.hpp"
      15              : #include "tpglibs/AVXFrugalPedestalSubtractProcessor.hpp"
      16              : 
      17              : #include <boost/test/unit_test.hpp>
      18              : #include <fmt/core.h>
      19              : #include <fmt/ranges.h>
      20              : #include <immintrin.h>
      21              : #include <thread>
      22              : #include <atomic>
      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            1 :   nlohmann::json thr_config = {
      35            2 :     {"plane0", 300},
      36            2 :     {"plane1", 700},
      37            2 :     {"plane2", 1300}
      38           10 :   };
      39            1 :   thresholds->configure(thr_config, plane_numbers);
      40              : 
      41            1 :   nlohmann::json rs_config = {
      42            2 :     {"memory_factor_plane0", 4},
      43            2 :     {"memory_factor_plane1", 4},
      44            2 :     {"memory_factor_plane2", 4},
      45            2 :     {"scale_factor_plane0", 1},
      46            2 :     {"scale_factor_plane1", 1},
      47            2 :     {"scale_factor_plane2", 1},
      48            2 :     {"memory_divisor_plane0", 5},
      49            2 :     {"memory_divisor_plane1", 5},
      50            2 :     {"memory_divisor_plane2", 5},
      51            2 :     {"scale_divisor_plane0", 2},
      52            2 :     {"scale_divisor_plane1", 2},
      53            2 :     {"scale_divisor_plane2", 2}
      54           37 :   };
      55            1 :   abs_rs->configure(rs_config, plane_numbers);
      56            1 :   rs->configure(rs_config, plane_numbers);
      57              : 
      58              :   // Arbitrary input choices. Set so RS resets to 0.
      59            1 :   __m256i input0 = _mm256_set_epi16(-1600, 1500, -1400, 1300, -1200, 1100, -1000,  900,
      60            1 :                                      -800,  700,  -600,  500,  -400,  300,  -200,  100);
      61            1 :   __m256i input1 = _mm256_set_epi16( 2880,-2700,  2520,-2340,  2160,-1980,  1800,-1620,
      62            1 :                                      1440,-1260,  1080, -900,   720, -540,   360, -180);
      63            1 :   __m256i input2 = _mm256_set_epi16(-1280, 1200, -1120, 1040,  -960,  880,  -800,  720,
      64            1 :                                      -640,  560,  -480,  400,  -320,  240,  -160,   80);
      65              : 
      66            1 :   __m256i avx_thr_output = thresholds->process(input0);  // Only using the first.
      67              : 
      68            1 :   __m256i avx_abs_output = abs_rs->process(input0);
      69            1 :   avx_abs_output = abs_rs->process(input1);
      70            1 :   avx_abs_output = abs_rs->process(input2);
      71            1 :   __m256i avx_rs_output = rs->process(input0);
      72            1 :   avx_rs_output = rs->process(input1);
      73            1 :   avx_rs_output = rs->process(input2);
      74              : 
      75            1 :   int16_t abs_output[16], thr_output[16], rs_output[16];
      76            1 :   _mm256_storeu_si256(reinterpret_cast<__m256i*>(&abs_output), avx_abs_output);
      77            1 :   _mm256_storeu_si256(reinterpret_cast<__m256i*>(&thr_output), avx_thr_output);
      78            1 :   _mm256_storeu_si256(reinterpret_cast<__m256i*>(&rs_output),  avx_rs_output);
      79              : 
      80            1 :   bool same_abs = true;
      81            1 :   bool same_thr = true;
      82            1 :   bool same_rs  = true;
      83              : 
      84            1 :   int16_t expected_abs[16] = { 144,  288,  432,  576,  720,  864, 1008, 1152,
      85              :                               1296, 1440, 1584, 1728, 1872, 2016, 2160, 2304};
      86            1 :   int16_t expected_thr[16] = {0, 0, 0, 0, 500, 0, 0, 0, 900, 0, 0, 0, 0, 0, 1500, 0};
      87            1 :   int16_t expected_rs[16]  = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
      88              : 
      89           17 :   for (int i = 0; i < 16; i++) {
      90           16 :     if (expected_abs[i] != abs_output[i]) same_abs = false;
      91           16 :     if (expected_thr[i] != thr_output[i]) same_thr = false;
      92           16 :     if (expected_rs[i] != rs_output[i]) same_rs = false;
      93              :   }
      94              : 
      95              : //  fmt::print("AbsRS: [{:5}]\n", fmt::join(abs_output, ","));
      96              : //  fmt::print("Thr:   [{:5}]\n", fmt::join(thr_output, ","));
      97              : //  fmt::print("RS:    [{:5}]\n", fmt::join(rs_output, ","));
      98              : 
      99            1 :   BOOST_TEST(same_abs);
     100            1 :   BOOST_TEST(same_thr);
     101            1 :   BOOST_TEST(same_rs);
     102           34 : }
     103              : 
     104              : } // namespace tpglibs
        

Generated by: LCOV version 2.0-1