X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=fhi_lib%2Ftest%2Fcommon%2Fcommon.hpp;h=2516dba17d5efbb4a7da26b0b9cc8a03c722d32c;hb=892daba4c616407f16506415d5a69549519ef11d;hp=9b01b06988b7b902b2235155157159859ff7228f;hpb=70d9d920dd4e575f085f1f1a9050fefd1c10e127;p=o-du%2Fphy.git diff --git a/fhi_lib/test/common/common.hpp b/fhi_lib/test/common/common.hpp index 9b01b06..2516dba 100644 --- a/fhi_lib/test/common/common.hpp +++ b/fhi_lib/test/common/common.hpp @@ -229,6 +229,29 @@ protected: parallelization_factor = factor; } + /*! + \brief Run the given function and return the mean run time and stddev. + \param [in] function Function to benchmark. + \param [in] args Function's arguments. + \return std::pair where the first element is mean and the second one is standard deviation. + */ + template + std::pair run_benchmark(F function, Args ... args) + { + std::vector results((unsigned long) BenchmarkParameters::repetition); + + for(unsigned int outer_loop = 0; outer_loop < BenchmarkParameters::repetition; outer_loop++) { + const auto start_time = __rdtsc(); + for (unsigned int inner_loop = 0; inner_loop < BenchmarkParameters::loop; inner_loop++) { + function(args ...); + } + const auto end_time = __rdtsc(); + results.push_back(end_time - start_time); + } + + return calculate_statistics(results); + }; + /*! \brief Run performance test case for a given function. \param [in] isa Used Instruction Set. @@ -575,29 +598,6 @@ private: const double stddev); }; -/*! - \brief Run the given function and return the mean run time and stddev. - \param [in] function Function to benchmark. - \param [in] args Function's arguments. - \return std::pair where the first element is mean and the second one is standard deviation. -*/ -template -std::pair run_benchmark(F function, Args ... args) -{ - std::vector results((unsigned long) BenchmarkParameters::repetition); - - for(unsigned int outer_loop = 0; outer_loop < BenchmarkParameters::repetition; outer_loop++) { - const auto start_time = __rdtsc(); - for (unsigned int inner_loop = 0; inner_loop < BenchmarkParameters::loop; inner_loop++) { - function(args ...); - } - const auto end_time = __rdtsc(); - results.push_back(end_time - start_time); - } - - return calculate_statistics(results); -}; - /*! \brief Assert elements of two arrays. It calls ASSERT_EQ for each element of the array. \param [in] reference Array with reference values. @@ -605,7 +605,7 @@ std::pair run_benchmark(F function, Args ... args) \param [in] size Size of the array. */ template -void assert_array_eq(const T* reference, const T* actual, const int size) +inline void assert_array_eq(const T* reference, const T* actual, const int size) { for(int index = 0; index < size ; index++) { @@ -622,7 +622,7 @@ void assert_array_eq(const T* reference, const T* actual, const int size) \param [in] precision Precision fo the comparision used by ASSERT_NEAR. */ template -void assert_array_near(const T* reference, const T* actual, const int size, const double precision) +inline void assert_array_near(const T* reference, const T* actual, const int size, const double precision) { for(int index = 0; index < size ; index++) { @@ -632,7 +632,7 @@ void assert_array_near(const T* reference, const T* actual, const int size, cons } template <> -void assert_array_near(const complex_float* reference, const complex_float* actual, const int size, const double precision) +inline void assert_array_near(const complex_float* reference, const complex_float* actual, const int size, const double precision) { for(int index = 0; index < size ; index++) { @@ -651,7 +651,7 @@ void assert_array_near(const complex_float* reference, const comp \param [in] precision Precision for the comparison used by ASSERT_GT. */ template -void assert_avg_greater_complex(const T* reference, const T* actual, const int size, const double precision) +inline void assert_avg_greater_complex(const T* reference, const T* actual, const int size, const double precision) { float mseDB, MSE; double avgMSEDB = 0.0; @@ -701,7 +701,7 @@ void assert_avg_greater_complex(const T* reference, const T* actual, const int s \return Pointer to the allocated memory. */ template -T* aligned_malloc(const int size, const unsigned alignment) +inline T* aligned_malloc(const int size, const unsigned alignment) { #ifdef _BBLIB_DPDK_ return (T*) rte_malloc(NULL, sizeof(T) * size, alignment); @@ -723,7 +723,7 @@ T* aligned_malloc(const int size, const unsigned alignment) \param [in] ptr Pointer to the allocated memory. */ template -void aligned_free(T* ptr) +inline void aligned_free(T* ptr) { #ifdef _BBLIB_DPDK_ rte_free((void*)ptr); @@ -750,7 +750,7 @@ void aligned_free(T* ptr) \return Pointer to the allocated memory with random data. */ template -T* generate_random_numbers(const long size, const unsigned alignment, U& distribution) +inline T* generate_random_numbers(const long size, const unsigned alignment, U& distribution) { auto array = (T*) aligned_malloc(size * sizeof(T), alignment); @@ -775,7 +775,7 @@ T* generate_random_numbers(const long size, const unsigned alignment, U& distrib \return Pointer to the allocated memory with random data. */ template -T* generate_random_data(const long size, const unsigned alignment) +inline T* generate_random_data(const long size, const unsigned alignment) { std::uniform_int_distribution<> random(0, 255); @@ -797,7 +797,7 @@ T* generate_random_data(const long size, const unsigned alignment) \return Pointer to the allocated memory with random data. */ template -T* generate_random_int_numbers(const long size, const unsigned alignment, const T lo_range, +inline T* generate_random_int_numbers(const long size, const unsigned alignment, const T lo_range, const T up_range) { std::uniform_int_distribution random(lo_range, up_range); @@ -820,7 +820,7 @@ T* generate_random_int_numbers(const long size, const unsigned alignment, const \return Pointer to the allocated memory with random data. */ template -T* generate_random_real_numbers(const long size, const unsigned alignment, const T lo_range, +inline T* generate_random_real_numbers(const long size, const unsigned alignment, const T lo_range, const T up_range) { std::uniform_real_distribution distribution(lo_range, up_range);