mirror of
https://github.com/gnss-sdr/gnss-sdr
synced 2025-01-19 05:33:02 +00:00
Improve std::plus void detection
This commit is contained in:
parent
98bea8292c
commit
b2fd68fe67
@ -460,17 +460,6 @@ else()
|
|||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Availability of std::plus without class specifier
|
|
||||||
if(CMAKE_CXX_STANDARD VERSION_GREATER 11)
|
|
||||||
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
|
||||||
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 5.4.0)
|
|
||||||
set(HAVE_STD_PLUS ON)
|
|
||||||
endif()
|
|
||||||
else()
|
|
||||||
set(HAVE_STD_PLUS ON)
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
@ -901,6 +890,22 @@ check_cxx_source_compiles("
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# Detect availability of std::plus without class specifier
|
||||||
|
################################################################################
|
||||||
|
unset(has_std_plus_void CACHE)
|
||||||
|
if(CMAKE_CXX_STANDARD VERSION_GREATER 11)
|
||||||
|
include(CheckCXXSourceCompiles)
|
||||||
|
check_cxx_source_compiles("
|
||||||
|
#include <functional>
|
||||||
|
int main()
|
||||||
|
{ [](float a=1, float b=0){return std::plus<>();}; };"
|
||||||
|
has_std_plus_void
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# VOLK - Vector-Optimized Library of Kernels
|
# VOLK - Vector-Optimized Library of Kernels
|
||||||
################################################################################
|
################################################################################
|
||||||
|
@ -238,8 +238,8 @@ if(ARMADILLO_VERSION_STRING VERSION_GREATER 8.400)
|
|||||||
add_definitions(-DARMADILLO_HAVE_MVNRND=1)
|
add_definitions(-DARMADILLO_HAVE_MVNRND=1)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(HAVE_STD_PLUS)
|
if(has_std_plus_void)
|
||||||
add_definitions(-DCOMPILER_HAS_STD_PLUS=1)
|
add_definitions(-DCOMPILER_HAS_STD_PLUS_VOID=1)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
find_package(Gnuplot)
|
find_package(Gnuplot)
|
||||||
|
@ -107,6 +107,6 @@ add_benchmark(benchmark_preamble core_system_parameters)
|
|||||||
add_benchmark(benchmark_detector core_system_parameters)
|
add_benchmark(benchmark_detector core_system_parameters)
|
||||||
|
|
||||||
|
|
||||||
if(HAVE_STD_PLUS)
|
if(has_std_plus_void)
|
||||||
target_compile_definitions(benchmark_detector PRIVATE -DCOMPILER_HAS_STD_PLUS=1)
|
target_compile_definitions(benchmark_detector PRIVATE -DCOMPILER_HAS_STD_PLUS_VOID=1)
|
||||||
endif()
|
endif()
|
||||||
|
@ -83,7 +83,7 @@ void bm_accumulate(benchmark::State& state)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if COMPILER_HAS_STD_PLUS
|
|
||||||
void bm_inner_product(benchmark::State& state)
|
void bm_inner_product(benchmark::State& state)
|
||||||
{
|
{
|
||||||
std::vector<float> d_symbol_history(GPS_CA_PREAMBLE_LENGTH_SYMBOLS, 0.0);
|
std::vector<float> d_symbol_history(GPS_CA_PREAMBLE_LENGTH_SYMBOLS, 0.0);
|
||||||
@ -104,15 +104,16 @@ void bm_inner_product(benchmark::State& state)
|
|||||||
d_symbol_history.end(),
|
d_symbol_history.end(),
|
||||||
d_preamble_samples.begin(),
|
d_preamble_samples.begin(),
|
||||||
0,
|
0,
|
||||||
|
#if COMPILER_HAS_STD_PLUS_VOID
|
||||||
std::plus<>(),
|
std::plus<>(),
|
||||||
|
#else
|
||||||
|
std::plus<float>(),
|
||||||
|
#endif
|
||||||
[&](float a, float b) { return (std::signbit(a) ? -b : b); });
|
[&](float a, float b) { return (std::signbit(a) ? -b : b); });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
BENCHMARK(bm_forloop);
|
BENCHMARK(bm_forloop);
|
||||||
BENCHMARK(bm_accumulate);
|
BENCHMARK(bm_accumulate);
|
||||||
#if COMPILER_HAS_STD_PLUS
|
|
||||||
BENCHMARK(bm_inner_product);
|
BENCHMARK(bm_inner_product);
|
||||||
#endif
|
|
||||||
BENCHMARK_MAIN();
|
BENCHMARK_MAIN();
|
||||||
|
@ -84,7 +84,6 @@ TEST(PreambleCorrelationTest, TestMethods)
|
|||||||
}
|
}
|
||||||
end2 = std::chrono::system_clock::now();
|
end2 = std::chrono::system_clock::now();
|
||||||
|
|
||||||
#if COMPILER_HAS_STD_PLUS
|
|
||||||
// Compute correlation, method 3
|
// Compute correlation, method 3
|
||||||
start3 = std::chrono::system_clock::now();
|
start3 = std::chrono::system_clock::now();
|
||||||
for (int64_t iter = 0; iter < n_iter; iter++)
|
for (int64_t iter = 0; iter < n_iter; iter++)
|
||||||
@ -93,25 +92,25 @@ TEST(PreambleCorrelationTest, TestMethods)
|
|||||||
d_symbol_history.begin() + GPS_CA_PREAMBLE_LENGTH_BITS,
|
d_symbol_history.begin() + GPS_CA_PREAMBLE_LENGTH_BITS,
|
||||||
d_preamble_samples.begin(),
|
d_preamble_samples.begin(),
|
||||||
0,
|
0,
|
||||||
|
#if COMPILER_HAS_STD_PLUS_VOID
|
||||||
std::plus<>(),
|
std::plus<>(),
|
||||||
[&](float a, float b) { return (std::signbit(a) ? -b : b); });
|
#else
|
||||||
|
std::plus<float>(),
|
||||||
|
#endif
|
||||||
sum_corr3 += corr_value3;
|
sum_corr3 += corr_value3;
|
||||||
}
|
}
|
||||||
end3 = std::chrono::system_clock::now();
|
end3 = std::chrono::system_clock::now();
|
||||||
std::chrono::duration<double> elapsed_seconds3 = end3 - start3;
|
|
||||||
EXPECT_EQ(corr_value, corr_value3);
|
|
||||||
EXPECT_EQ(sum_corr1, sum_corr3);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
EXPECT_EQ(corr_value, corr_value2);
|
|
||||||
EXPECT_EQ(sum_corr1, sum_corr2);
|
|
||||||
|
|
||||||
std::chrono::duration<double> elapsed_seconds = end - start;
|
std::chrono::duration<double> elapsed_seconds = end - start;
|
||||||
std::chrono::duration<double> elapsed_seconds2 = end2 - start2;
|
std::chrono::duration<double> elapsed_seconds2 = end2 - start2;
|
||||||
|
std::chrono::duration<double> elapsed_seconds3 = end3 - start3;
|
||||||
|
|
||||||
|
EXPECT_EQ(corr_value, corr_value2);
|
||||||
|
EXPECT_EQ(sum_corr1, sum_corr2);
|
||||||
|
EXPECT_EQ(corr_value, corr_value3);
|
||||||
|
EXPECT_EQ(sum_corr1, sum_corr3);
|
||||||
|
|
||||||
std::cout << "Correlation computed with 'C for' : done in " << elapsed_seconds.count() * 1.0e9 / n_iter << " nanoseconds" << std::endl;
|
std::cout << "Correlation computed with 'C for' : done in " << elapsed_seconds.count() * 1.0e9 / n_iter << " nanoseconds" << std::endl;
|
||||||
std::cout << "Correlation computed with accumulate : done in " << elapsed_seconds2.count() * 1.0e9 / n_iter << " nanoseconds" << std::endl;
|
std::cout << "Correlation computed with accumulate : done in " << elapsed_seconds2.count() * 1.0e9 / n_iter << " nanoseconds" << std::endl;
|
||||||
#if COMPILER_HAS_STD_PLUS
|
|
||||||
std::cout << "Correlation computed with inner_product : done in " << elapsed_seconds3.count() * 1.0e9 / n_iter << " nanoseconds" << std::endl;
|
std::cout << "Correlation computed with inner_product : done in " << elapsed_seconds3.count() * 1.0e9 / n_iter << " nanoseconds" << std::endl;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user