@@ -12,6 +12,7 @@ option(TRIGDX_BUILD_TESTS "Build tests" ON)
|
|||||||
option(TRIGDX_BUILD_BENCHMARKS "Build tests" ON)
|
option(TRIGDX_BUILD_BENCHMARKS "Build tests" ON)
|
||||||
option(TRIGDX_BUILD_PYTHON "Build Python interface" ON)
|
option(TRIGDX_BUILD_PYTHON "Build Python interface" ON)
|
||||||
|
|
||||||
|
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
|
||||||
configure_file(
|
configure_file(
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/cmake/trigdx_config.hpp.in
|
${CMAKE_CURRENT_SOURCE_DIR}/cmake/trigdx_config.hpp.in
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/include/trigdx/trigdx_config.hpp @ONLY)
|
${CMAKE_CURRENT_BINARY_DIR}/include/trigdx/trigdx_config.hpp @ONLY)
|
||||||
|
|||||||
@@ -13,8 +13,11 @@ target_link_libraries(benchmark_reference PRIVATE trigdx benchmark::benchmark)
|
|||||||
add_executable(benchmark_lookup benchmark_lookup.cpp)
|
add_executable(benchmark_lookup benchmark_lookup.cpp)
|
||||||
target_link_libraries(benchmark_lookup PRIVATE trigdx benchmark::benchmark)
|
target_link_libraries(benchmark_lookup PRIVATE trigdx benchmark::benchmark)
|
||||||
|
|
||||||
add_executable(benchmark_lookup_avx benchmark_lookup_avx.cpp)
|
if(HAVE_AVX)
|
||||||
target_link_libraries(benchmark_lookup_avx PRIVATE trigdx benchmark::benchmark)
|
add_executable(benchmark_lookup_avx benchmark_lookup_avx.cpp)
|
||||||
|
target_link_libraries(benchmark_lookup_avx PRIVATE trigdx
|
||||||
|
benchmark::benchmark)
|
||||||
|
endif()
|
||||||
|
|
||||||
if(TRIGDX_USE_MKL)
|
if(TRIGDX_USE_MKL)
|
||||||
add_executable(benchmark_mkl benchmark_mkl.cpp)
|
add_executable(benchmark_mkl benchmark_mkl.cpp)
|
||||||
|
|||||||
42
cmake/FindAVX.cmake
Normal file
42
cmake/FindAVX.cmake
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
include(CheckCXXSourceRuns)
|
||||||
|
|
||||||
|
set(SUPPORTED_COMPILERS Clang;GNU;Intel;IntelLLVM)
|
||||||
|
|
||||||
|
if(CMAKE_CXX_COMPILER_ID IN_LIST SUPPORTED_COMPILERS)
|
||||||
|
if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
|
||||||
|
set(CMAKE_REQUIRED_FLAGS "-xHost") # ICC
|
||||||
|
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM")
|
||||||
|
set(CMAKE_REQUIRED_FLAGS "-march=native") # ICX
|
||||||
|
else()
|
||||||
|
set(CMAKE_REQUIRED_FLAGS "-march=native") # GCC/Clang
|
||||||
|
endif()
|
||||||
|
else()
|
||||||
|
message(FATAL_ERROR "Unsupported compiler: ${CMAKE_CXX_COMPILER_ID}.")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# AVX check
|
||||||
|
check_cxx_source_runs(
|
||||||
|
"
|
||||||
|
#include <immintrin.h>
|
||||||
|
int main() {
|
||||||
|
__m256 a = _mm256_setzero_ps(); // AVX
|
||||||
|
(void) a;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
"
|
||||||
|
HAVE_AVX)
|
||||||
|
|
||||||
|
if(HAVE_AVX)
|
||||||
|
# AVX2 check
|
||||||
|
check_cxx_source_runs(
|
||||||
|
"
|
||||||
|
#include <immintrin.h>
|
||||||
|
int main() {
|
||||||
|
__m256i a = _mm256_set1_epi32(-1);
|
||||||
|
__m256i b = _mm256_abs_epi32(a); // AVX2
|
||||||
|
(void) b;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
"
|
||||||
|
HAVE_AVX2)
|
||||||
|
endif()
|
||||||
@@ -1,10 +1,12 @@
|
|||||||
include(FetchContent)
|
include(FetchContent)
|
||||||
|
include(FindAVX)
|
||||||
add_library(trigdx reference.cpp lookup.cpp lookup_avx.cpp)
|
add_library(trigdx reference.cpp lookup.cpp)
|
||||||
|
|
||||||
target_include_directories(trigdx PUBLIC ${PROJECT_SOURCE_DIR}/include)
|
target_include_directories(trigdx PUBLIC ${PROJECT_SOURCE_DIR}/include)
|
||||||
|
|
||||||
target_compile_options(trigdx PRIVATE -O3 -march=native)
|
if(HAVE_AVX)
|
||||||
|
target_sources(trigdx PRIVATE lookup_avx.cpp)
|
||||||
|
endif()
|
||||||
|
|
||||||
if(TRIGDX_USE_MKL)
|
if(TRIGDX_USE_MKL)
|
||||||
find_package(MKL REQUIRED)
|
find_package(MKL REQUIRED)
|
||||||
@@ -22,7 +24,8 @@ if(TRIGDX_USE_GPU)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(TRIGDX_USE_XSIMD)
|
if(TRIGDX_USE_XSIMD)
|
||||||
find_package(xsimd QUIET)
|
# Requires XSIMD > 13 for architecture independent dispatching
|
||||||
|
find_package(xsimd 13 QUIET)
|
||||||
if(NOT TARGET xsimd)
|
if(NOT TARGET xsimd)
|
||||||
FetchContent_Declare(
|
FetchContent_Declare(
|
||||||
xsimd
|
xsimd
|
||||||
|
|||||||
@@ -160,7 +160,6 @@ template <std::size_t NR_SAMPLES> struct LookupAVXBackend<NR_SAMPLES>::Impl {
|
|||||||
for (std::size_t i = 0; i < n; ++i) {
|
for (std::size_t i = 0; i < n; ++i) {
|
||||||
std::size_t idx = static_cast<std::size_t>(x[i] * SCALE) & MASK;
|
std::size_t idx = static_cast<std::size_t>(x[i] * SCALE) & MASK;
|
||||||
std::size_t idx_cos = (idx + NR_SAMPLES / 4) & MASK;
|
std::size_t idx_cos = (idx + NR_SAMPLES / 4) & MASK;
|
||||||
s[i] = lookup[idx];
|
|
||||||
c[i] = lookup[idx_cos];
|
c[i] = lookup[idx_cos];
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -10,9 +10,11 @@ target_link_libraries(test_lookup PRIVATE trigdx Catch2::Catch2WithMain)
|
|||||||
add_test(NAME test_lookup COMMAND test_lookup)
|
add_test(NAME test_lookup COMMAND test_lookup)
|
||||||
|
|
||||||
# LookupAVX backend test
|
# LookupAVX backend test
|
||||||
add_executable(test_lookup_avx test_lookup_avx.cpp)
|
if(HAVE_AVX)
|
||||||
target_link_libraries(test_lookup_avx PRIVATE trigdx Catch2::Catch2WithMain)
|
add_executable(test_lookup_avx test_lookup_avx.cpp)
|
||||||
add_test(NAME test_lookup_avx COMMAND test_lookup_avx)
|
target_link_libraries(test_lookup_avx PRIVATE trigdx Catch2::Catch2WithMain)
|
||||||
|
add_test(NAME test_lookup_avx COMMAND test_lookup_avx)
|
||||||
|
endif()
|
||||||
|
|
||||||
# MKL backend test
|
# MKL backend test
|
||||||
if(TRIGDX_USE_MKL)
|
if(TRIGDX_USE_MKL)
|
||||||
|
|||||||
Reference in New Issue
Block a user