LCOV - code coverage report
Current view: top level - tpglibs/unittest - avx_factory_test.cxx (source / functions) Coverage Total Hit
Test: code.result Lines: 100.0 % 55 55
Test Date: 2025-12-21 13:07:08 Functions: 100.0 % 2 2

            Line data    Source code
       1              : /**
       2              :  * @file avx_factory_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/AVXFactory.hpp"
      13              : 
      14              : #include <boost/test/unit_test.hpp>
      15              : #include <fmt/core.h>
      16              : #include <fmt/ranges.h>
      17              : 
      18              : namespace tpglibs {
      19              : 
      20            2 : BOOST_AUTO_TEST_CASE(test_macro_overview)
      21              : {
      22              :   // This is the focus test. The rest is just to make something interesting to pass.
      23            1 :   auto avx_factory = AVXFactory::get_instance();
      24            1 :   std::shared_ptr<AVXProcessor> threshold = avx_factory->create_processor("AVXThresholdProcessor");
      25            1 :   std::shared_ptr<AVXProcessor> abs_rs = avx_factory->create_processor("AVXAbsRunSumProcessor");
      26            1 :   std::shared_ptr<AVXProcessor> rs = avx_factory->create_processor("AVXRunSumProcessor");
      27              : 
      28            1 :   int16_t plane_numbers[16] = {0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2};
      29              : 
      30            1 :   nlohmann::json thr_config = {
      31            2 :     {"plane0", 300},
      32            2 :     {"plane1", 1000},
      33            2 :     {"plane2", 1600}
      34           10 :   };
      35            1 :   threshold->configure(thr_config, plane_numbers);
      36              : 
      37            1 :   nlohmann::json rs_config = {
      38            2 :     {"memory_factor_plane0", 8},
      39            2 :     {"memory_factor_plane1", 8},
      40            2 :     {"memory_factor_plane2", 8},
      41            2 :     {"scale_factor_plane0", 5},
      42            2 :     {"scale_factor_plane1", 5},
      43            2 :     {"scale_factor_plane2", 5},
      44            2 :     {"memory_divisor_plane0", 10},
      45            2 :     {"memory_divisor_plane1", 10},
      46            2 :     {"memory_divisor_plane2", 10},
      47            2 :     {"scale_divisor_plane0", 10},
      48            2 :     {"scale_divisor_plane1", 10},
      49            2 :     {"scale_divisor_plane2", 10}
      50           37 :   };
      51            1 :   abs_rs->configure(rs_config, plane_numbers);
      52            1 :   rs->configure(rs_config, plane_numbers);
      53              : 
      54            1 :   abs_rs->set_next_processor(threshold);
      55            1 :   rs->set_next_processor(threshold);
      56              : 
      57              :   // Arbitrary input choices. Set so RS resets to 0.
      58            1 :   __m256i input0 = _mm256_set_epi16(-1600, 1500, -1400, 1300, -1200, 1100, -1000,  900,
      59            1 :                                      -800,  700,  -600,  500,  -400,  300,  -200,  100);
      60            1 :   __m256i input1 = _mm256_set_epi16( 2880,-2700,  2520,-2340,  2160,-1980,  1800,-1620,
      61            1 :                                      1440,-1260,  1080, -900,   720, -540,   360, -180);
      62            1 :   __m256i input2 = _mm256_set_epi16(-1280, 1200, -1120, 1040,  -960,  880,  -800,  720,
      63            1 :                                      -640,  560,  -480,  400,  -320,  240,  -160,   80);
      64              : 
      65            1 :   __m256i avx_abs_output = abs_rs->process(input0);
      66            1 :   avx_abs_output = abs_rs->process(input1);
      67            1 :   avx_abs_output = abs_rs->process(input2);
      68              : 
      69            1 :   __m256i avx_rs_output = rs->process(input0);
      70            1 :   avx_rs_output = rs->process(input1);
      71            1 :   avx_rs_output = rs->process(input2);
      72              : 
      73            1 :   int16_t abs_output[16], rs_output[16];
      74            1 :   _mm256_storeu_si256(reinterpret_cast<__m256i*>(&abs_output), avx_abs_output);
      75            1 :   _mm256_storeu_si256(reinterpret_cast<__m256i*>(&rs_output),  avx_rs_output);
      76              : 
      77            1 :   bool same_abs = true;
      78            1 :   bool same_rs  = true;
      79              : 
      80            1 :   int16_t expected_abs[16] = {   0,    0,  432,  576,  720,    0, 1008, 1152,
      81              :                               1296, 1440,    0, 1728, 1872, 2016, 2160, 2304};
      82            1 :   int16_t expected_rs[16]  = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
      83              : 
      84           17 :   for (int i = 0; i < 16; i++) {
      85           16 :     if (expected_abs[i] != abs_output[i]) same_abs = false;
      86           16 :     if (expected_rs[i] != rs_output[i]) same_rs = false;
      87              :   }
      88              : 
      89              : //  fmt::print("AbsRS: [{:5}]\n", fmt::join(abs_output, ","));
      90              : //  fmt::print("RS:    [{:5}]\n", fmt::join(rs_output, ","));
      91              : 
      92            1 :   BOOST_TEST(same_abs);
      93            1 :   BOOST_TEST(same_rs);
      94           34 : }
      95              : 
      96              : } // namespace tpglibs
        

Generated by: LCOV version 2.0-1