d1291681960d97437de0e678c6c60fbdf8590997
[o-du/phy.git] / fhi_lib / test / test_xran / compander_functional.cc
1 /******************************************************************************
2 *
3 *   Copyright (c) 2019 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_compression.h"
22 #include "xran_compression.hpp"
23
24 #include <stdint.h>
25 #include <random>
26 #include <algorithm>
27 #include <iterator>
28 #include <iostream>
29 #include <cstring>
30
31 const std::string module_name = "bfp";
32
33 template <typename T>
34 int checkData(T* inVec1, T* inVec2, int numVals)
35 {
36   int checkSum = 0;
37   for (int n = 0; n < numVals; ++n)
38   {
39     checkSum += std::abs(inVec1[n] - inVec2[n]);
40   }
41   if (checkSum == 0)
42   {
43     //std::cout << "Test Passed\n";
44     return 0;
45   }
46   else
47   {
48     //std::cout << "Test Failed\n";
49     return 1;
50   }
51 }
52 template int checkData(int8_t*, int8_t*, int);
53 template int checkData(int16_t*, int16_t*, int);
54
55 int checkDataApprox(int16_t *inVec1, int16_t *inVec2, int numVals)
56 {
57   int checkSum = 0;
58   for (int n = 0; n < numVals; ++n)
59   {
60     if (std::abs(inVec1[n] & 0xFF00)   - std::abs(inVec2[n] & 0xFF00)){;
61         printf("%d %d\n", inVec1[n] & 0xFF00, inVec2[n] & 0xFF00);
62         checkSum += 1;
63     }
64   }
65   if (checkSum == 0)
66   {
67     //std::cout << "Test Passed\n";
68     return 0;
69   }
70   else
71   {
72     //std::cout << "Test Failed\n";
73     return 1;
74   }
75 }
76
77
78 class BfpCheck : public KernelTests
79 {
80 protected:
81     void SetUp() override {
82         init_test("bfp_functional");
83     }
84
85     /* It's called after an execution of the each test case.*/
86     void TearDown() override {
87     }
88 };
89
90 class BfpPerf : public KernelTests
91 {
92 protected:
93     void SetUp() override {
94         init_test("bfp_performace");
95     }
96
97     /* It's called after an execution of the each test case.*/
98     void TearDown() override {
99     }
100 };
101 CACHE_ALIGNED int16_t loc_dataExpandedIn[288*BlockFloatCompander::k_numREReal];
102 CACHE_ALIGNED int16_t loc_dataExpandedRes[288*BlockFloatCompander::k_numREReal];
103 CACHE_ALIGNED uint8_t loc_dataCompressedDataOut[2*288*BlockFloatCompander::k_numREReal];
104
105 class BfpPerfEx : public KernelTests
106 {
107 protected:
108     struct xranlib_decompress_request  bfp_decom_req;
109     struct xranlib_decompress_response bfp_decom_rsp;
110     struct xranlib_compress_request  bfp_com_req;
111     struct xranlib_compress_response bfp_com_rsp;
112
113     void SetUp() override {
114         init_test("bfp_performace_ex");
115         int32_t resSum  = 0;
116         int16_t len = 0;
117         int16_t compMethod = XRAN_COMPMETHOD_BLKFLOAT;
118         int16_t iqWidth    = get_input_parameter<int16_t>("iqWidth");
119         int16_t numRBs = get_input_parameter<int16_t>("nRBsize");
120         // Create random number generator
121         std::random_device rd;
122         std::mt19937 gen(rd()); //Standard mersenne_twister_engine seeded with rd()
123         std::uniform_int_distribution<int16_t> randInt16(-32768, 32767);
124         std::uniform_int_distribution<int> randExpShift(0, 4);
125
126         BlockFloatCompander::ExpandedData expandedData;
127         expandedData.dataExpanded = &loc_dataExpandedIn[0];
128         BlockFloatCompander::ExpandedData expandedDataRes;
129         expandedDataRes.dataExpanded = &loc_dataExpandedRes[0];
130
131         //printf("iqWidth %d numRBs %d\n", iqWidth, numRBs);
132
133         for (int m = 0; m < 18*BlockFloatCompander::k_numRB; ++m) {
134             auto shiftVal = randExpShift(gen);
135             for (int n = 0; n < BlockFloatCompander::k_numREReal; ++n) {
136                 expandedData.dataExpanded[m*BlockFloatCompander::k_numREReal+n] = int16_t(randInt16(gen) >> shiftVal);
137             }
138         }
139
140         BlockFloatCompander::CompressedData compressedData;
141         compressedData.dataCompressed = &loc_dataCompressedDataOut[0];
142
143         std::memset(&loc_dataCompressedDataOut[0], 0, 288*BlockFloatCompander::k_numREReal);
144         std::memset(&loc_dataExpandedRes[0], 0, 288*BlockFloatCompander::k_numREReal);
145
146         std::memset(&bfp_com_req, 0, sizeof(struct xranlib_compress_request));
147         std::memset(&bfp_com_rsp, 0, sizeof(struct xranlib_compress_response));
148         std::memset(&bfp_decom_req, 0, sizeof(struct xranlib_decompress_request));
149         std::memset(&bfp_decom_rsp, 0, sizeof(struct xranlib_decompress_response));
150
151         bfp_com_req.data_in    = (int16_t *)expandedData.dataExpanded;
152         bfp_com_req.numRBs     = numRBs;
153         bfp_com_req.len        = numRBs*12*2*2;
154         bfp_com_req.compMethod = compMethod;
155         bfp_com_req.iqWidth    = iqWidth;
156
157         bfp_com_rsp.data_out   = (int8_t *)(compressedData.dataCompressed);
158         bfp_com_rsp.len        = 0;
159
160         bfp_decom_req.data_in    = (int8_t *)(compressedData.dataCompressed);
161         bfp_decom_req.numRBs     = numRBs;
162         bfp_decom_req.len        = ((3 * iqWidth) + 1) * numRBs;
163         bfp_decom_req.compMethod = compMethod;
164         bfp_decom_req.iqWidth    = iqWidth;
165
166         bfp_decom_rsp.data_out   = (int16_t *)expandedDataRes.dataExpanded;
167         bfp_decom_rsp.len        = 0;
168     }
169
170     /* It's called after an execution of the each test case.*/
171     void TearDown() override {
172
173     }
174 };
175
176 TEST_P(BfpCheck, AVX512_12bit)
177 {
178   int resSum = 0;
179
180   // Create random number generator
181   std::random_device rd;
182   std::mt19937 gen(rd()); //Standard mersenne_twister_engine seeded with rd()
183   std::uniform_int_distribution<int16_t> randInt16(-32768, 32767);
184   std::uniform_int_distribution<int> randExpShift(0, 4);
185
186   // Generate random test data for compression kernel
187   BlockFloatCompander::ExpandedData expandedDataInput;
188   expandedDataInput.dataExpanded = &expandedDataInput.dataExpandedIn[0];
189   for (int m = 0; m < BlockFloatCompander::k_numRB; ++m)
190     {
191         auto shiftVal = randExpShift(gen);
192         for (int n = 0; n < BlockFloatCompander::k_numREReal; ++n)
193         {
194             expandedDataInput.dataExpanded[m*BlockFloatCompander::k_numREReal+n] = int16_t(randInt16(gen) >> shiftVal);
195         }
196     }
197
198     BlockFloatCompander::CompressedData compressedDataRef;
199     compressedDataRef.dataCompressed = &compressedDataRef.dataCompressedDataOut[0];
200     BlockFloatCompander::ExpandedData expandedDataRef;
201     expandedDataRef.dataExpanded = &expandedDataRef.dataExpandedIn[0];
202     BlockFloatCompander::CompressedData compressedDataKern;
203     compressedDataKern.dataCompressed = &compressedDataKern.dataCompressedDataOut[0];
204     BlockFloatCompander::ExpandedData expandedDataKern;
205     expandedDataKern.dataExpanded = &expandedDataKern.dataExpandedIn[0];
206
207     //std::cout << "Verifying AVX512 12b iqWidth Kernel\n";
208     expandedDataInput.iqWidth = 12;
209     // Generate reference
210     BlockFloatCompander::BlockFloatCompress_Basic(expandedDataInput, &compressedDataRef);
211     BlockFloatCompander::BlockFloatExpand_Basic(compressedDataRef, &expandedDataRef);
212     // Generate kernel output
213     BlockFloatCompander::BlockFloatCompress_12b_AVX512(expandedDataInput, &compressedDataKern);
214     BlockFloatCompander::BlockFloatExpand_12b_AVX512(compressedDataRef, &expandedDataKern);
215     // Verify
216     auto totNumBytes = ((3 * compressedDataRef.iqWidth) + 1) * BlockFloatCompander::k_numRB;
217     //std::cout << "Compression: ";
218     resSum += checkData(compressedDataRef.dataCompressed, compressedDataKern.dataCompressed, totNumBytes);
219     //std::cout << "Expansion: ";
220     resSum += checkData(expandedDataRef.dataExpanded, expandedDataKern.dataExpanded, BlockFloatCompander::k_numSampsExpanded);
221
222     ASSERT_EQ(0, resSum);
223 }
224
225 TEST_P(BfpCheck, AVX512_10bit)
226 {
227   int resSum = 0;
228
229   // Create random number generator
230   std::random_device rd;
231   std::mt19937 gen(rd()); //Standard mersenne_twister_engine seeded with rd()
232   std::uniform_int_distribution<int16_t> randInt16(-32768, 32767);
233   std::uniform_int_distribution<int> randExpShift(0, 4);
234
235   // Generate random test data for compression kernel
236   BlockFloatCompander::ExpandedData expandedDataInput;
237   expandedDataInput.dataExpanded = &expandedDataInput.dataExpandedIn[0];
238   for (int m = 0; m < BlockFloatCompander::k_numRB; ++m)
239     {
240         auto shiftVal = randExpShift(gen);
241         for (int n = 0; n < BlockFloatCompander::k_numREReal; ++n)
242         {
243             expandedDataInput.dataExpanded[m*BlockFloatCompander::k_numREReal+n] = int16_t(randInt16(gen) >> shiftVal);
244         }
245     }
246
247     BlockFloatCompander::CompressedData compressedDataRef;
248     compressedDataRef.dataCompressed = &compressedDataRef.dataCompressedDataOut[0];
249     BlockFloatCompander::ExpandedData expandedDataRef;
250     expandedDataRef.dataExpanded = &expandedDataRef.dataExpandedIn[0];
251     BlockFloatCompander::CompressedData compressedDataKern;
252     compressedDataKern.dataCompressed = &compressedDataKern.dataCompressedDataOut[0];
253     BlockFloatCompander::ExpandedData expandedDataKern;
254     expandedDataKern.dataExpanded = &expandedDataKern.dataExpandedIn[0];
255
256     //std::cout << "Verifying AVX512 10b iqWidth Kernel\n";
257     expandedDataInput.iqWidth = 10;
258     // Generate reference
259     BlockFloatCompander::BlockFloatCompress_Basic(expandedDataInput, &compressedDataRef);
260     BlockFloatCompander::BlockFloatExpand_Basic(compressedDataRef, &expandedDataRef);
261     // Generate kernel output
262     BlockFloatCompander::BlockFloatCompress_10b_AVX512(expandedDataInput, &compressedDataKern);
263     BlockFloatCompander::BlockFloatExpand_10b_AVX512(compressedDataRef, &expandedDataKern);
264     // Verify
265     auto totNumBytes = ((3 * compressedDataRef.iqWidth) + 1) * BlockFloatCompander::k_numRB;
266     //std::cout << "Compression: ";
267     resSum += checkData(compressedDataRef.dataCompressed, compressedDataKern.dataCompressed, totNumBytes);
268     //std::cout << "Expansion: ";
269     resSum += checkData(expandedDataRef.dataExpanded, expandedDataKern.dataExpanded, BlockFloatCompander::k_numSampsExpanded);
270
271     ASSERT_EQ(0, resSum);
272
273 //    performance("AVX512", module_name, BlockFloatCompander::BlockFloatCompress_10b_AVX512, expandedDataInput, &compressedDataKern);
274 }
275
276 TEST_P(BfpCheck, AVX512_9bit)
277 {
278   int resSum = 0;
279
280   // Create random number generator
281   std::random_device rd;
282   std::mt19937 gen(rd()); //Standard mersenne_twister_engine seeded with rd()
283   std::uniform_int_distribution<int16_t> randInt16(-32768, 32767);
284   std::uniform_int_distribution<int> randExpShift(0, 4);
285
286   // Generate random test data for compression kernel
287   BlockFloatCompander::ExpandedData expandedDataInput;
288   expandedDataInput.dataExpanded = &expandedDataInput.dataExpandedIn[0];
289   for (int m = 0; m < BlockFloatCompander::k_numRB; ++m)
290     {
291         auto shiftVal = randExpShift(gen);
292         for (int n = 0; n < BlockFloatCompander::k_numREReal; ++n)
293         {
294             expandedDataInput.dataExpanded[m*BlockFloatCompander::k_numREReal+n] = int16_t(randInt16(gen) >> shiftVal);
295         }
296     }
297
298     BlockFloatCompander::CompressedData compressedDataRef;
299     compressedDataRef.dataCompressed = &compressedDataRef.dataCompressedDataOut[0];
300     BlockFloatCompander::ExpandedData expandedDataRef;
301     expandedDataRef.dataExpanded = &expandedDataRef.dataExpandedIn[0];
302     BlockFloatCompander::CompressedData compressedDataKern;
303     compressedDataKern.dataCompressed = &compressedDataKern.dataCompressedDataOut[0];
304     BlockFloatCompander::ExpandedData expandedDataKern;
305     expandedDataKern.dataExpanded = &expandedDataKern.dataExpandedIn[0];
306
307     //std::cout << "Verifying AVX512 9b iqWidth Kernel\n";
308     expandedDataInput.iqWidth = 9;
309     // Generate reference
310     BlockFloatCompander::BlockFloatCompress_Basic(expandedDataInput, &compressedDataRef);
311     BlockFloatCompander::BlockFloatExpand_Basic(compressedDataRef, &expandedDataRef);
312     // Generate kernel output
313     BlockFloatCompander::BlockFloatCompress_9b_AVX512(expandedDataInput, &compressedDataKern);
314     BlockFloatCompander::BlockFloatExpand_9b_AVX512(compressedDataRef, &expandedDataKern);
315     // Verify
316     auto totNumBytes = ((3 * compressedDataRef.iqWidth) + 1) * BlockFloatCompander::k_numRB;
317     //std::cout << "Compression: ";
318     resSum += checkData(compressedDataRef.dataCompressed, compressedDataKern.dataCompressed, totNumBytes);
319     //std::cout << "Expansion: ";
320     resSum += checkData(expandedDataRef.dataExpanded, expandedDataKern.dataExpanded, BlockFloatCompander::k_numSampsExpanded);
321
322     ASSERT_EQ(0, resSum);
323 }
324
325
326 TEST_P(BfpCheck, AVX512_8bit)
327 {
328   int resSum = 0;
329
330   // Create random number generator
331   std::random_device rd;
332   std::mt19937 gen(rd()); //Standard mersenne_twister_engine seeded with rd()
333   std::uniform_int_distribution<int16_t> randInt16(-32768, 32767);
334   std::uniform_int_distribution<int> randExpShift(0, 4);
335
336   // Generate random test data for compression kernel
337   BlockFloatCompander::ExpandedData expandedDataInput;
338   expandedDataInput.dataExpanded = &expandedDataInput.dataExpandedIn[0];
339   for (int m = 0; m < BlockFloatCompander::k_numRB; ++m)
340     {
341         auto shiftVal = randExpShift(gen);
342         for (int n = 0; n < BlockFloatCompander::k_numREReal; ++n)
343         {
344             expandedDataInput.dataExpanded[m*BlockFloatCompander::k_numREReal+n] = int16_t(randInt16(gen) >> shiftVal);
345         }
346     }
347
348     BlockFloatCompander::CompressedData compressedDataRef;
349     compressedDataRef.dataCompressed = &compressedDataRef.dataCompressedDataOut[0];
350     BlockFloatCompander::ExpandedData expandedDataRef;
351     expandedDataRef.dataExpanded = &expandedDataRef.dataExpandedIn[0];
352     BlockFloatCompander::CompressedData compressedDataKern;
353     compressedDataKern.dataCompressed = &compressedDataKern.dataCompressedDataOut[0];
354     BlockFloatCompander::ExpandedData expandedDataKern;
355     expandedDataKern.dataExpanded = &expandedDataKern.dataExpandedIn[0];
356
357     //std::cout << "Verifying AVX512 8bit Kernel\n";
358     expandedDataInput.iqWidth = 8;
359     // Generate reference
360     BlockFloatCompander::BlockFloatCompress_Basic(expandedDataInput, &compressedDataRef);
361     BlockFloatCompander::BlockFloatExpand_Basic(compressedDataRef, &expandedDataRef);
362     // Generate kernel output
363     BlockFloatCompander::BlockFloatCompress_8b_AVX512(expandedDataInput, &compressedDataKern);
364     BlockFloatCompander::BlockFloatExpand_8b_AVX512(compressedDataRef, &expandedDataKern);
365     // Verify
366     auto totNumBytes = ((3 * compressedDataRef.iqWidth) + 1) * BlockFloatCompander::k_numRB;
367     //std::cout << "Compression: ";
368     resSum += checkData(compressedDataRef.dataCompressed, compressedDataKern.dataCompressed, totNumBytes);
369     //std::cout << "Expansion: ";
370     resSum += checkData(expandedDataRef.dataExpanded, expandedDataKern.dataExpanded, BlockFloatCompander::k_numSampsExpanded);
371
372     ASSERT_EQ(0, resSum);
373 }
374
375 TEST_P(BfpPerf, AVX512_8bit_compression)
376 {
377   int resSum = 0;
378
379   // Create random number generator
380   std::random_device rd;
381   std::mt19937 gen(rd()); //Standard mersenne_twister_engine seeded with rd()
382   std::uniform_int_distribution<int16_t> randInt16(-32768, 32767);
383   std::uniform_int_distribution<int> randExpShift(0, 4);
384
385   // Generate random test data for compression kernel
386   BlockFloatCompander::ExpandedData expandedDataInput;
387   expandedDataInput.dataExpanded = &expandedDataInput.dataExpandedIn[0];
388   for (int m = 0; m < BlockFloatCompander::k_numRB; ++m)
389     {
390         auto shiftVal = randExpShift(gen);
391         for (int n = 0; n < BlockFloatCompander::k_numREReal; ++n)
392         {
393             expandedDataInput.dataExpanded[m*BlockFloatCompander::k_numREReal+n] = int16_t(randInt16(gen) >> shiftVal);
394         }
395     }
396
397     BlockFloatCompander::CompressedData compressedDataRef;
398     compressedDataRef.dataCompressed = &compressedDataRef.dataCompressedDataOut[0];
399     BlockFloatCompander::ExpandedData expandedDataRef;
400     expandedDataRef.dataExpanded = &expandedDataRef.dataExpandedIn[0];
401     BlockFloatCompander::CompressedData compressedDataKern;
402     compressedDataKern.dataCompressed = &compressedDataKern.dataCompressedDataOut[0];
403     BlockFloatCompander::ExpandedData expandedDataKern;
404     expandedDataKern.dataExpanded = &expandedDataKern.dataExpandedIn[0];
405
406     //std::cout << "Verifying AVX512 8bit Kernel\n";
407     expandedDataInput.iqWidth = 8;
408     // Generate reference
409     BlockFloatCompander::BlockFloatCompress_Basic(expandedDataInput, &compressedDataRef);
410     BlockFloatCompander::BlockFloatExpand_Basic(compressedDataRef, &expandedDataRef);
411     // Generate kernel output
412     BlockFloatCompander::BlockFloatCompress_8b_AVX512(expandedDataInput, &compressedDataKern);
413     BlockFloatCompander::BlockFloatExpand_8b_AVX512(compressedDataRef, &expandedDataKern);
414     // Verify
415     auto totNumBytes = ((3 * compressedDataRef.iqWidth) + 1) * BlockFloatCompander::k_numRB;
416     //std::cout << "Compression: ";
417     resSum += checkData(compressedDataRef.dataCompressed, compressedDataKern.dataCompressed, totNumBytes);
418     //std::cout << "Expansion: ";
419     resSum += checkData(expandedDataRef.dataExpanded, expandedDataKern.dataExpanded, BlockFloatCompander::k_numSampsExpanded);
420
421     ASSERT_EQ(0, resSum);
422
423     performance("AVX512", module_name, BlockFloatCompander::BlockFloatCompress_8b_AVX512, expandedDataInput, &compressedDataKern);
424 }
425
426 TEST_P(BfpPerf, AVX512_8bit_decompression)
427 {
428   int resSum = 0;
429
430   // Create random number generator
431   std::random_device rd;
432   std::mt19937 gen(rd()); //Standard mersenne_twister_engine seeded with rd()
433   std::uniform_int_distribution<int16_t> randInt16(-32768, 32767);
434   std::uniform_int_distribution<int> randExpShift(0, 4);
435
436   // Generate random test data for compression kernel
437   BlockFloatCompander::ExpandedData expandedDataInput;
438   expandedDataInput.dataExpanded = &expandedDataInput.dataExpandedIn[0];
439   for (int m = 0; m < BlockFloatCompander::k_numRB; ++m)
440     {
441         auto shiftVal = randExpShift(gen);
442         for (int n = 0; n < BlockFloatCompander::k_numREReal; ++n)
443         {
444             expandedDataInput.dataExpanded[m*BlockFloatCompander::k_numREReal+n] = int16_t(randInt16(gen) >> shiftVal);
445         }
446     }
447
448     BlockFloatCompander::CompressedData compressedDataRef;
449     compressedDataRef.dataCompressed = &compressedDataRef.dataCompressedDataOut[0];
450     BlockFloatCompander::ExpandedData expandedDataRef;
451     expandedDataRef.dataExpanded = &expandedDataRef.dataExpandedIn[0];
452     BlockFloatCompander::CompressedData compressedDataKern;
453     compressedDataKern.dataCompressed = &compressedDataKern.dataCompressedDataOut[0];
454     BlockFloatCompander::ExpandedData expandedDataKern;
455     expandedDataKern.dataExpanded = &expandedDataKern.dataExpandedIn[0];
456
457     //std::cout << "Verifying AVX512 8bit Kernel\n";
458     expandedDataInput.iqWidth = 8;
459     // Generate reference
460     BlockFloatCompander::BlockFloatCompress_Basic(expandedDataInput, &compressedDataRef);
461     BlockFloatCompander::BlockFloatExpand_Basic(compressedDataRef, &expandedDataRef);
462     // Generate kernel output
463     BlockFloatCompander::BlockFloatCompress_8b_AVX512(expandedDataInput, &compressedDataKern);
464     BlockFloatCompander::BlockFloatExpand_8b_AVX512(compressedDataRef, &expandedDataKern);
465     // Verify
466     auto totNumBytes = ((3 * compressedDataRef.iqWidth) + 1) * BlockFloatCompander::k_numRB;
467     //std::cout << "Compression: ";
468     resSum += checkData(compressedDataRef.dataCompressed, compressedDataKern.dataCompressed, totNumBytes);
469     //std::cout << "Expansion: ";
470     resSum += checkData(expandedDataRef.dataExpanded, expandedDataKern.dataExpanded, BlockFloatCompander::k_numSampsExpanded);
471
472     ASSERT_EQ(0, resSum);
473
474     performance("AVX512", module_name, BlockFloatCompander::BlockFloatExpand_8b_AVX512, compressedDataRef, &expandedDataKern);
475 }
476
477
478
479 TEST_P(BfpPerf, AVX512_9bit_compression)
480 {
481   int resSum = 0;
482
483   // Create random number generator
484   std::random_device rd;
485   std::mt19937 gen(rd()); //Standard mersenne_twister_engine seeded with rd()
486   std::uniform_int_distribution<int16_t> randInt16(-32768, 32767);
487   std::uniform_int_distribution<int> randExpShift(0, 4);
488
489   // Generate random test data for compression kernel
490   BlockFloatCompander::ExpandedData expandedDataInput;
491   expandedDataInput.dataExpanded = &expandedDataInput.dataExpandedIn[0];
492   for (int m = 0; m < BlockFloatCompander::k_numRB; ++m)
493     {
494         auto shiftVal = randExpShift(gen);
495         for (int n = 0; n < BlockFloatCompander::k_numREReal; ++n)
496         {
497             expandedDataInput.dataExpanded[m*BlockFloatCompander::k_numREReal+n] = int16_t(randInt16(gen) >> shiftVal);
498         }
499     }
500
501     BlockFloatCompander::CompressedData compressedDataRef;
502     compressedDataRef.dataCompressed = &compressedDataRef.dataCompressedDataOut[0];
503     BlockFloatCompander::ExpandedData expandedDataRef;
504     expandedDataRef.dataExpanded = &expandedDataRef.dataExpandedIn[0];
505     BlockFloatCompander::CompressedData compressedDataKern;
506     compressedDataKern.dataCompressed = &compressedDataKern.dataCompressedDataOut[0];
507     BlockFloatCompander::ExpandedData expandedDataKern;
508     expandedDataKern.dataExpanded = &expandedDataKern.dataExpandedIn[0];
509
510     //std::cout << "Verifying AVX512 8bit Kernel\n";
511     expandedDataInput.iqWidth = 9;
512     // Generate reference
513     BlockFloatCompander::BlockFloatCompress_Basic(expandedDataInput, &compressedDataRef);
514     BlockFloatCompander::BlockFloatExpand_Basic(compressedDataRef, &expandedDataRef);
515     // Generate kernel output
516     BlockFloatCompander::BlockFloatCompress_9b_AVX512(expandedDataInput, &compressedDataKern);
517     BlockFloatCompander::BlockFloatExpand_9b_AVX512(compressedDataRef, &expandedDataKern);
518     // Verify
519     auto totNumBytes = ((3 * compressedDataRef.iqWidth) + 1) * BlockFloatCompander::k_numRB;
520     //std::cout << "Compression: ";
521     resSum += checkData(compressedDataRef.dataCompressed, compressedDataKern.dataCompressed, totNumBytes);
522     //std::cout << "Expansion: ";
523     resSum += checkData(expandedDataRef.dataExpanded, expandedDataKern.dataExpanded, BlockFloatCompander::k_numSampsExpanded);
524
525     ASSERT_EQ(0, resSum);
526
527     performance("AVX512", module_name, BlockFloatCompander::BlockFloatCompress_9b_AVX512, expandedDataInput, &compressedDataKern);
528 }
529
530
531 TEST_P(BfpPerf, AVX512_9bit_decompression)
532 {
533   int resSum = 0;
534
535   // Create random number generator
536   std::random_device rd;
537   std::mt19937 gen(rd()); //Standard mersenne_twister_engine seeded with rd()
538   std::uniform_int_distribution<int16_t> randInt16(-32768, 32767);
539   std::uniform_int_distribution<int> randExpShift(0, 4);
540
541   // Generate random test data for compression kernel
542   BlockFloatCompander::ExpandedData expandedDataInput;
543   expandedDataInput.dataExpanded = &expandedDataInput.dataExpandedIn[0];
544   for (int m = 0; m < BlockFloatCompander::k_numRB; ++m)
545     {
546         auto shiftVal = randExpShift(gen);
547         for (int n = 0; n < BlockFloatCompander::k_numREReal; ++n)
548         {
549             expandedDataInput.dataExpanded[m*BlockFloatCompander::k_numREReal+n] = int16_t(randInt16(gen) >> shiftVal);
550         }
551     }
552
553     BlockFloatCompander::CompressedData compressedDataRef;
554     compressedDataRef.dataCompressed = &compressedDataRef.dataCompressedDataOut[0];
555     BlockFloatCompander::ExpandedData expandedDataRef;
556     expandedDataRef.dataExpanded = &expandedDataRef.dataExpandedIn[0];
557     BlockFloatCompander::CompressedData compressedDataKern;
558     compressedDataKern.dataCompressed = &compressedDataKern.dataCompressedDataOut[0];
559     BlockFloatCompander::ExpandedData expandedDataKern;
560     expandedDataKern.dataExpanded = &expandedDataKern.dataExpandedIn[0];
561
562     //std::cout << "Verifying AVX512 8bit Kernel\n";
563     expandedDataInput.iqWidth = 9;
564     // Generate reference
565     BlockFloatCompander::BlockFloatCompress_Basic(expandedDataInput, &compressedDataRef);
566     BlockFloatCompander::BlockFloatExpand_Basic(compressedDataRef, &expandedDataRef);
567     // Generate kernel output
568     BlockFloatCompander::BlockFloatCompress_9b_AVX512(expandedDataInput, &compressedDataKern);
569     BlockFloatCompander::BlockFloatExpand_9b_AVX512(compressedDataRef, &expandedDataKern);
570     // Verify
571     auto totNumBytes = ((3 * compressedDataRef.iqWidth) + 1) * BlockFloatCompander::k_numRB;
572     //std::cout << "Compression: ";
573     resSum += checkData(compressedDataRef.dataCompressed, compressedDataKern.dataCompressed, totNumBytes);
574     //std::cout << "Expansion: ";
575     resSum += checkData(expandedDataRef.dataExpanded, expandedDataKern.dataExpanded, BlockFloatCompander::k_numSampsExpanded);
576
577     ASSERT_EQ(0, resSum);
578
579     performance("AVX512", module_name, BlockFloatCompander::BlockFloatExpand_9b_AVX512, compressedDataRef, &expandedDataKern);
580 }
581
582
583 TEST_P(BfpPerf, AVX512_10bit_compression)
584 {
585   int resSum = 0;
586
587   // Create random number generator
588   std::random_device rd;
589   std::mt19937 gen(rd()); //Standard mersenne_twister_engine seeded with rd()
590   std::uniform_int_distribution<int16_t> randInt16(-32768, 32767);
591   std::uniform_int_distribution<int> randExpShift(0, 4);
592
593   // Generate random test data for compression kernel
594   BlockFloatCompander::ExpandedData expandedDataInput;
595   expandedDataInput.dataExpanded = &expandedDataInput.dataExpandedIn[0];
596   for (int m = 0; m < BlockFloatCompander::k_numRB; ++m)
597     {
598         auto shiftVal = randExpShift(gen);
599         for (int n = 0; n < BlockFloatCompander::k_numREReal; ++n)
600         {
601             expandedDataInput.dataExpanded[m*BlockFloatCompander::k_numREReal+n] = int16_t(randInt16(gen) >> shiftVal);
602         }
603     }
604
605     BlockFloatCompander::CompressedData compressedDataRef;
606     compressedDataRef.dataCompressed = &compressedDataRef.dataCompressedDataOut[0];
607     BlockFloatCompander::ExpandedData expandedDataRef;
608     expandedDataRef.dataExpanded = &expandedDataRef.dataExpandedIn[0];
609     BlockFloatCompander::CompressedData compressedDataKern;
610     compressedDataKern.dataCompressed = &compressedDataKern.dataCompressedDataOut[0];
611     BlockFloatCompander::ExpandedData expandedDataKern;
612     expandedDataKern.dataExpanded = &expandedDataKern.dataExpandedIn[0];
613
614     //std::cout << "Verifying AVX512 8bit Kernel\n";
615     expandedDataInput.iqWidth = 10;
616     // Generate reference
617     BlockFloatCompander::BlockFloatCompress_Basic(expandedDataInput, &compressedDataRef);
618     BlockFloatCompander::BlockFloatExpand_Basic(compressedDataRef, &expandedDataRef);
619     // Generate kernel output
620     BlockFloatCompander::BlockFloatCompress_10b_AVX512(expandedDataInput, &compressedDataKern);
621     BlockFloatCompander::BlockFloatExpand_10b_AVX512(compressedDataRef, &expandedDataKern);
622     // Verify
623     auto totNumBytes = ((3 * compressedDataRef.iqWidth) + 1) * BlockFloatCompander::k_numRB;
624     //std::cout << "Compression: ";
625     resSum += checkData(compressedDataRef.dataCompressed, compressedDataKern.dataCompressed, totNumBytes);
626     //std::cout << "Expansion: ";
627     resSum += checkData(expandedDataRef.dataExpanded, expandedDataKern.dataExpanded, BlockFloatCompander::k_numSampsExpanded);
628
629     ASSERT_EQ(0, resSum);
630
631     performance("AVX512", module_name, BlockFloatCompander::BlockFloatCompress_10b_AVX512, expandedDataInput, &compressedDataKern);
632 }
633
634 TEST_P(BfpPerf, AVX512_10bit_decompression)
635 {
636   int resSum = 0;
637
638   // Create random number generator
639   std::random_device rd;
640   std::mt19937 gen(rd()); //Standard mersenne_twister_engine seeded with rd()
641   std::uniform_int_distribution<int16_t> randInt16(-32768, 32767);
642   std::uniform_int_distribution<int> randExpShift(0, 4);
643
644   // Generate random test data for compression kernel
645   BlockFloatCompander::ExpandedData expandedDataInput;
646   expandedDataInput.dataExpanded = &expandedDataInput.dataExpandedIn[0];
647   for (int m = 0; m < BlockFloatCompander::k_numRB; ++m)
648     {
649         auto shiftVal = randExpShift(gen);
650         for (int n = 0; n < BlockFloatCompander::k_numREReal; ++n)
651         {
652             expandedDataInput.dataExpanded[m*BlockFloatCompander::k_numREReal+n] = int16_t(randInt16(gen) >> shiftVal);
653         }
654     }
655
656     BlockFloatCompander::CompressedData compressedDataRef;
657     compressedDataRef.dataCompressed = &compressedDataRef.dataCompressedDataOut[0];
658     BlockFloatCompander::ExpandedData expandedDataRef;
659     expandedDataRef.dataExpanded = &expandedDataRef.dataExpandedIn[0];
660     BlockFloatCompander::CompressedData compressedDataKern;
661     compressedDataKern.dataCompressed = &compressedDataKern.dataCompressedDataOut[0];
662     BlockFloatCompander::ExpandedData expandedDataKern;
663     expandedDataKern.dataExpanded = &expandedDataKern.dataExpandedIn[0];
664
665     //std::cout << "Verifying AVX512 8bit Kernel\n";
666     expandedDataInput.iqWidth = 10;
667     // Generate reference
668     BlockFloatCompander::BlockFloatCompress_Basic(expandedDataInput, &compressedDataRef);
669     BlockFloatCompander::BlockFloatExpand_Basic(compressedDataRef, &expandedDataRef);
670     // Generate kernel output
671     BlockFloatCompander::BlockFloatCompress_10b_AVX512(expandedDataInput, &compressedDataKern);
672     BlockFloatCompander::BlockFloatExpand_10b_AVX512(compressedDataRef, &expandedDataKern);
673     // Verify
674     auto totNumBytes = ((3 * compressedDataRef.iqWidth) + 1) * BlockFloatCompander::k_numRB;
675     //std::cout << "Compression: ";
676     resSum += checkData(compressedDataRef.dataCompressed, compressedDataKern.dataCompressed, totNumBytes);
677     //std::cout << "Expansion: ";
678     resSum += checkData(expandedDataRef.dataExpanded, expandedDataKern.dataExpanded, BlockFloatCompander::k_numSampsExpanded);
679
680     ASSERT_EQ(0, resSum);
681
682     performance("AVX512", module_name, BlockFloatCompander::BlockFloatExpand_10b_AVX512, compressedDataRef, &expandedDataKern);
683 }
684
685 TEST_P(BfpPerf, AVX512_12bit_compression)
686 {
687   int resSum = 0;
688
689   // Create random number generator
690   std::random_device rd;
691   std::mt19937 gen(rd()); //Standard mersenne_twister_engine seeded with rd()
692   std::uniform_int_distribution<int16_t> randInt16(-32768, 32767);
693   std::uniform_int_distribution<int> randExpShift(0, 4);
694
695   // Generate random test data for compression kernel
696   BlockFloatCompander::ExpandedData expandedDataInput;
697   expandedDataInput.dataExpanded = &expandedDataInput.dataExpandedIn[0];
698   for (int m = 0; m < BlockFloatCompander::k_numRB; ++m)
699     {
700         auto shiftVal = randExpShift(gen);
701         for (int n = 0; n < BlockFloatCompander::k_numREReal; ++n)
702         {
703             expandedDataInput.dataExpanded[m*BlockFloatCompander::k_numREReal+n] = int16_t(randInt16(gen) >> shiftVal);
704         }
705     }
706
707     BlockFloatCompander::CompressedData compressedDataRef;
708     compressedDataRef.dataCompressed = &compressedDataRef.dataCompressedDataOut[0];
709     BlockFloatCompander::ExpandedData expandedDataRef;
710     expandedDataRef.dataExpanded = &expandedDataRef.dataExpandedIn[0];
711     BlockFloatCompander::CompressedData compressedDataKern;
712     compressedDataKern.dataCompressed = &compressedDataKern.dataCompressedDataOut[0];
713     BlockFloatCompander::ExpandedData expandedDataKern;
714     expandedDataKern.dataExpanded = &expandedDataKern.dataExpandedIn[0];
715
716     //std::cout << "Verifying AVX512 8bit Kernel\n";
717     expandedDataInput.iqWidth = 12;
718     // Generate reference
719     BlockFloatCompander::BlockFloatCompress_Basic(expandedDataInput, &compressedDataRef);
720     BlockFloatCompander::BlockFloatExpand_Basic(compressedDataRef, &expandedDataRef);
721     // Generate kernel output
722     BlockFloatCompander::BlockFloatCompress_12b_AVX512(expandedDataInput, &compressedDataKern);
723     BlockFloatCompander::BlockFloatExpand_12b_AVX512(compressedDataRef, &expandedDataKern);
724     // Verify
725     auto totNumBytes = ((3 * compressedDataRef.iqWidth) + 1) * BlockFloatCompander::k_numRB;
726     //std::cout << "Compression: ";
727     resSum += checkData(compressedDataRef.dataCompressed, compressedDataKern.dataCompressed, totNumBytes);
728     //std::cout << "Expansion: ";
729     resSum += checkData(expandedDataRef.dataExpanded, expandedDataKern.dataExpanded, BlockFloatCompander::k_numSampsExpanded);
730
731     ASSERT_EQ(0, resSum);
732
733     performance("AVX512", module_name, BlockFloatCompander::BlockFloatCompress_12b_AVX512, expandedDataInput, &compressedDataKern);
734 }
735
736
737 TEST_P(BfpPerf, AVX512_12bit_decompression)
738 {
739   int resSum = 0;
740
741   // Create random number generator
742   std::random_device rd;
743   std::mt19937 gen(rd()); //Standard mersenne_twister_engine seeded with rd()
744   std::uniform_int_distribution<int16_t> randInt16(-32768, 32767);
745   std::uniform_int_distribution<int> randExpShift(0, 4);
746
747   // Generate random test data for compression kernel
748   BlockFloatCompander::ExpandedData expandedDataInput;
749   expandedDataInput.dataExpanded = &expandedDataInput.dataExpandedIn[0];
750   for (int m = 0; m < BlockFloatCompander::k_numRB; ++m)
751     {
752         auto shiftVal = randExpShift(gen);
753         for (int n = 0; n < BlockFloatCompander::k_numREReal; ++n)
754         {
755             expandedDataInput.dataExpanded[m*BlockFloatCompander::k_numREReal+n] = int16_t(randInt16(gen) >> shiftVal);
756         }
757     }
758
759     BlockFloatCompander::CompressedData compressedDataRef;
760     compressedDataRef.dataCompressed = &compressedDataRef.dataCompressedDataOut[0];
761     BlockFloatCompander::ExpandedData expandedDataRef;
762     expandedDataRef.dataExpanded = &expandedDataRef.dataExpandedIn[0];
763     BlockFloatCompander::CompressedData compressedDataKern;
764     compressedDataKern.dataCompressed = &compressedDataKern.dataCompressedDataOut[0];
765     BlockFloatCompander::ExpandedData expandedDataKern;
766     expandedDataKern.dataExpanded = &expandedDataKern.dataExpandedIn[0];
767
768     //std::cout << "Verifying AVX512 8bit Kernel\n";
769     expandedDataInput.iqWidth = 12;
770     // Generate reference
771     BlockFloatCompander::BlockFloatCompress_Basic(expandedDataInput, &compressedDataRef);
772     BlockFloatCompander::BlockFloatExpand_Basic(compressedDataRef, &expandedDataRef);
773     // Generate kernel output
774     BlockFloatCompander::BlockFloatCompress_12b_AVX512(expandedDataInput, &compressedDataKern);
775     BlockFloatCompander::BlockFloatExpand_12b_AVX512(compressedDataRef, &expandedDataKern);
776     // Verify
777     auto totNumBytes = ((3 * compressedDataRef.iqWidth) + 1) * BlockFloatCompander::k_numRB;
778     //std::cout << "Compression: ";
779     resSum += checkData(compressedDataRef.dataCompressed, compressedDataKern.dataCompressed, totNumBytes);
780     //std::cout << "Expansion: ";
781     resSum += checkData(expandedDataRef.dataExpanded, expandedDataKern.dataExpanded, BlockFloatCompander::k_numSampsExpanded);
782
783     ASSERT_EQ(0, resSum);
784
785     performance("AVX512", module_name, BlockFloatCompander::BlockFloatExpand_12b_AVX512, compressedDataRef, &expandedDataKern);
786 }
787
788 TEST_P(BfpCheck, AVX512_sweep_xranlib)
789 {
790     int32_t resSum  = 0;
791     int16_t len = 0;
792
793     int16_t compMethod = XRAN_COMPMETHOD_BLKFLOAT;
794     int16_t iqWidth[]    = {8, 9, 10, 12};
795
796     int16_t numRBs[] = {16, 18, 32, 36, 48, 70, 113, 273};
797     struct xranlib_decompress_request  bfp_decom_req;
798     struct xranlib_decompress_response bfp_decom_rsp;
799
800     struct xranlib_compress_request  bfp_com_req;
801     struct xranlib_compress_response bfp_com_rsp;
802
803     // Create random number generator
804     std::random_device rd;
805     std::mt19937 gen(rd()); //Standard mersenne_twister_engine seeded with rd()
806     std::uniform_int_distribution<int16_t> randInt16(-32768, 32767);
807     std::uniform_int_distribution<int> randExpShift(0, 4);
808
809     BlockFloatCompander::ExpandedData expandedData;
810     expandedData.dataExpanded = &loc_dataExpandedIn[0];
811     BlockFloatCompander::ExpandedData expandedDataRes;
812     expandedDataRes.dataExpanded = &loc_dataExpandedRes[0];
813     for (int iq_w_id = 0; iq_w_id < sizeof(iqWidth)/sizeof(iqWidth[0]); iq_w_id ++){
814         for (int tc = 0; tc < sizeof(numRBs)/sizeof(numRBs[0]); tc ++){
815
816             //printf("[%d]numRBs %d [%d] iqWidth %d\n",tc, numRBs[tc], iq_w_id, iqWidth[iq_w_id]);
817             // Generate random test data for compression kernel
818
819             for (int m = 0; m < 18*BlockFloatCompander::k_numRB; ++m) {
820                 auto shiftVal = randExpShift(gen);
821                 for (int n = 0; n < BlockFloatCompander::k_numREReal; ++n) {
822                     expandedData.dataExpanded[m*BlockFloatCompander::k_numREReal+n] = int16_t(randInt16(gen) >> shiftVal);
823                 }
824             }
825
826             BlockFloatCompander::CompressedData compressedData;
827             compressedData.dataCompressed = &loc_dataCompressedDataOut[0];
828
829             std::memset(&loc_dataCompressedDataOut[0], 0, 288*BlockFloatCompander::k_numREReal);
830             std::memset(&loc_dataExpandedRes[0], 0, 288*BlockFloatCompander::k_numREReal);
831
832             std::memset(&bfp_com_req, 0, sizeof(struct xranlib_compress_request));
833             std::memset(&bfp_com_rsp, 0, sizeof(struct xranlib_compress_response));
834             std::memset(&bfp_decom_req, 0, sizeof(struct xranlib_decompress_request));
835             std::memset(&bfp_decom_rsp, 0, sizeof(struct xranlib_decompress_response));
836
837             bfp_com_req.data_in    = (int16_t *)expandedData.dataExpanded;
838             bfp_com_req.numRBs     = numRBs[tc];
839             bfp_com_req.len        = numRBs[tc]*12*2*2;
840             bfp_com_req.compMethod = compMethod;
841             bfp_com_req.iqWidth    = iqWidth[iq_w_id];
842
843             bfp_com_rsp.data_out   = (int8_t *)(compressedData.dataCompressed);
844             bfp_com_rsp.len        = 0;
845
846             xranlib_compress_avx512(&bfp_com_req, &bfp_com_rsp);
847
848             bfp_decom_req.data_in    = (int8_t *)(compressedData.dataCompressed);
849             bfp_decom_req.numRBs     = numRBs[tc];
850             bfp_decom_req.len        = bfp_com_rsp.len;
851             bfp_decom_req.compMethod = compMethod;
852             bfp_decom_req.iqWidth    = iqWidth[iq_w_id];
853
854             bfp_decom_rsp.data_out   = (int16_t *)expandedDataRes.dataExpanded;
855             bfp_decom_rsp.len        = 0;
856
857             xranlib_decompress_avx512(&bfp_decom_req, &bfp_decom_rsp);
858
859             resSum += checkDataApprox(expandedData.dataExpanded, expandedDataRes.dataExpanded, numRBs[tc]*BlockFloatCompander::k_numREReal);
860
861             ASSERT_EQ(numRBs[tc]*12*2*2, bfp_decom_rsp.len);
862             ASSERT_EQ(0, resSum);
863          }
864     }
865 }
866
867 TEST_P(BfpPerfEx, AVX512_Comp)
868 {
869      performance("AVX512", module_name, xranlib_compress_avx512, &bfp_com_req, &bfp_com_rsp);
870 }
871
872 TEST_P(BfpPerfEx, AVX512_DeComp)
873 {
874      performance("AVX512", module_name, xranlib_decompress_avx512, &bfp_decom_req, &bfp_decom_rsp);
875 }
876
877 INSTANTIATE_TEST_CASE_P(UnitTest, BfpCheck,
878                         testing::ValuesIn(get_sequence(BfpCheck::get_number_of_cases("bfp_functional"))));
879
880 INSTANTIATE_TEST_CASE_P(UnitTest, BfpPerf,
881                         testing::ValuesIn(get_sequence(BfpPerf::get_number_of_cases("bfp_performace"))));
882
883
884 INSTANTIATE_TEST_CASE_P(UnitTest, BfpPerfEx,
885                         testing::ValuesIn(get_sequence(BfpPerf::get_number_of_cases("bfp_performace_ex"))));
886
887