O-RAN E Maintenance Release contribution for ODULOW
[o-du/phy.git] / fhi_lib / test / test_xran / mod_compression_unit_test.cc
1 /******************************************************************************
2 *
3 *   Copyright (c) 2020 Intel.
4 *
5 *   Licensed under the Apache License, Version 2.0 (the "License");
6 *   you may not use this file except in compliance with the License.
7 *   You may obtain a copy of the License at
8 *
9 *       http://www.apache.org/licenses/LICENSE-2.0
10 *
11 *   Unless required by applicable law or agreed to in writing, software
12 *   distributed under the License is distributed on an "AS IS" BASIS,
13 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 *   See the License for the specific language governing permissions and
15 *   limitations under the License.
16 *
17 *******************************************************************************/
18
19 #include "common.hpp"
20 #include "xran_fh_o_du.h"
21 #include "xran_mod_compression.h"
22
23 #include <stdint.h>
24 #include <random>
25 #include <algorithm>
26 #include <iterator>
27 #include <iostream>
28 #include <cstring>
29
30 const std::string module_name = "mod_compression";
31
32 extern int _may_i_use_cpu_feature(unsigned __int64);
33
34 int16_t loc_ModCompIn[273*12*14*2*16*2];
35 int8_t loc_ModCompOut[273*12*14*2*16];
36
37 class Mod_CompressionPerf : public KernelTests
38 {
39 protected:
40     struct xranlib_5gnr_mod_compression_request  mod_com_req;
41     struct xranlib_5gnr_mod_compression_response mod_com_rsp;
42
43     void SetUp() override {
44         init_test("mod_compression_performace");
45         // Create random number generator
46         std::random_device rd;
47         std::mt19937 gen(rd()); //Standard mersenne_twister_engine seeded with rd()
48         std::uniform_int_distribution<int16_t> randInt16(-32768, 32767);
49         std::uniform_int_distribution<int> randExpShift(0, 4);
50         std::memset(&loc_ModCompOut[0], 0, 273*12);
51
52         std::memset(&mod_com_req, 0, sizeof(struct xranlib_5gnr_mod_compression_request));
53         std::memset(&mod_com_rsp, 0, sizeof(struct xranlib_5gnr_mod_compression_response));
54         mod_com_req.unit = get_input_parameter<int16_t>("unit");
55         mod_com_req.modulation = get_input_parameter<xran_modulation_order>("modulation");
56         mod_com_req.num_symbols = get_input_parameter<int32_t>("num_symbols");
57
58         for (int m = 0; m < 2*mod_com_req.num_symbols; ++m) {
59             loc_ModCompIn[m] = int16_t(randInt16(gen));
60         }
61
62         mod_com_req.data_in    = (int16_t *)loc_ModCompIn;
63         mod_com_rsp.data_out   = (int8_t *)(loc_ModCompOut);
64     }
65
66     /* It's called after an execution of the each test case.*/
67     void TearDown() override {
68
69     }
70 };
71
72 TEST_P(Mod_CompressionPerf, AVX512_Mod_Comp)
73 {
74      performance("AVX512", module_name, xranlib_5gnr_mod_compression_avx512, &mod_com_req, &mod_com_rsp);
75 }
76
77
78 TEST_P(Mod_CompressionPerf,  AVXSNC_Mod_Comp)
79 {
80     if(_may_i_use_cpu_feature(_FEATURE_AVX512IFMA52))
81          performance("AVXSNC", module_name, xranlib_5gnr_mod_compression_snc, &mod_com_req, &mod_com_rsp);
82 }
83
84 INSTANTIATE_TEST_CASE_P(UnitTest, Mod_CompressionPerf,
85                         testing::ValuesIn(get_sequence(Mod_CompressionPerf::get_number_of_cases("mod_compression_performace"))));