Improve std::plus void detection

This commit is contained in:
Carles Fernandez 2020-06-30 13:41:20 +02:00
parent 98bea8292c
commit b2fd68fe67
No known key found for this signature in database
GPG Key ID: 4C583C52B0C3877D
5 changed files with 35 additions and 30 deletions

View File

@ -460,17 +460,6 @@ else()
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
################################################################################

View File

@ -238,8 +238,8 @@ if(ARMADILLO_VERSION_STRING VERSION_GREATER 8.400)
add_definitions(-DARMADILLO_HAVE_MVNRND=1)
endif()
if(HAVE_STD_PLUS)
add_definitions(-DCOMPILER_HAS_STD_PLUS=1)
if(has_std_plus_void)
add_definitions(-DCOMPILER_HAS_STD_PLUS_VOID=1)
endif()
find_package(Gnuplot)

View File

@ -107,6 +107,6 @@ add_benchmark(benchmark_preamble core_system_parameters)
add_benchmark(benchmark_detector core_system_parameters)
if(HAVE_STD_PLUS)
target_compile_definitions(benchmark_detector PRIVATE -DCOMPILER_HAS_STD_PLUS=1)
if(has_std_plus_void)
target_compile_definitions(benchmark_detector PRIVATE -DCOMPILER_HAS_STD_PLUS_VOID=1)
endif()

View File

@ -83,7 +83,7 @@ void bm_accumulate(benchmark::State& state)
}
}
#if COMPILER_HAS_STD_PLUS
void bm_inner_product(benchmark::State& state)
{
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_preamble_samples.begin(),
0,
#if COMPILER_HAS_STD_PLUS_VOID
std::plus<>(),
#else
std::plus<float>(),
#endif
[&](float a, float b) { return (std::signbit(a) ? -b : b); });
}
}
#endif
BENCHMARK(bm_forloop);
BENCHMARK(bm_accumulate);
#if COMPILER_HAS_STD_PLUS
BENCHMARK(bm_inner_product);
#endif
BENCHMARK_MAIN();

View File

@ -84,7 +84,6 @@ TEST(PreambleCorrelationTest, TestMethods)
}
end2 = std::chrono::system_clock::now();
#if COMPILER_HAS_STD_PLUS
// Compute correlation, method 3
start3 = std::chrono::system_clock::now();
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_preamble_samples.begin(),
0,
#if COMPILER_HAS_STD_PLUS_VOID
std::plus<>(),
[&](float a, float b) { return (std::signbit(a) ? -b : b); });
#else
std::plus<float>(),
#endif
sum_corr3 += corr_value3;
}
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_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 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;
#endif
}