Skip to content

Commit

Permalink
Merge pull request #459 from DiamonDinoia/spreader-vectorization-v2
Browse files Browse the repository at this point in the history
Spreader manual vectorization
  • Loading branch information
ahbarnett authored Jun 21, 2024
2 parents fcfe3dd + 3e24326 commit 84e6aec
Show file tree
Hide file tree
Showing 13 changed files with 1,644 additions and 713 deletions.
1 change: 0 additions & 1 deletion .github/workflows/C++.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ jobs:

steps:
- uses: actions/checkout@v4

- name: 'Setup MSYS2'
uses: msys2/setup-msys2@v2
with:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/python_wheel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ jobs:

steps:
- uses: actions/checkout@v4
- uses: git-for-windows/setup-git-for-windows-sdk
with:
flavor: minimal

- name: Install GCC and make
run: C:\msys64\usr\bin\bash.exe -lc "pacman -Sy --noconfirm make mingw-w64-x86_64-toolchain mingw-w64-x86_64-fftw"
Expand Down
47 changes: 26 additions & 21 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,24 @@ cmake_minimum_required(VERSION 3.19)

project(finufft VERSION 2.2.0 LANGUAGES C CXX)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

set(GNU_LIKE_FRONTENDS AppleClang Clang GNU)
if (CMAKE_CXX_COMPILER_ID IN_LIST GNU_LIKE_FRONTENDS)
# Set custom compiler flags for gcc-compatible compilers
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG -funroll-loops")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -g -DNDEBUG -funroll-loops")
set(FINUFFT_CXX_FLAGS_RELEASE -O3 -funroll-loops -ffp-contract=fast)
set(FINUFFT_CXX_FLAGS_RELWITHDEBINFO -g ${FINUFFT_CXX_FLAGS_RELEASE})
endif ()

include(CTest)

if (CMAKE_SYSTEM_PROCESSOR MATCHES "ppc|ppc64|powerpc|powerpc64" OR (APPLE AND CMAKE_OSX_ARCHITECTURES MATCHES "ppc|ppc64"))
# PowerPC arch does not have -march flag.
set(FINUFFT_ARCH_FLAGS "-mtune=native" CACHE STRING "Compiler flags for specifying target architecture.")
else ()
set(FINUFFT_ARCH_FLAGS "-march=native" CACHE STRING "Compiler flags for specifying target architecture.")
if (CMAKE_CXX_COMPILER_ID IN_LIST GNU_LIKE_FRONTENDS)
if (CMAKE_SYSTEM_PROCESSOR MATCHES "ppc|ppc64|powerpc|powerpc64" OR (APPLE AND CMAKE_OSX_ARCHITECTURES MATCHES "ppc|ppc64"))
# PowerPC arch does not have -march flag.
set(FINUFFT_ARCH_FLAGS "-mtune=native" CACHE STRING "Compiler flags for specifying target architecture.")
else ()
set(FINUFFT_ARCH_FLAGS "-march=native" CACHE STRING "Compiler flags for specifying target architecture.")
endif ()
endif ()
set(FINUFFT_FFTW_SUFFIX "OpenMP" CACHE STRING "Suffix for FFTW libraries (e.g. OpenMP, Threads etc.)")
set(FINUFFT_FFTW_LIBRARIES "DEFAULT" CACHE STRING "Specify a custom FFTW library")
Expand All @@ -31,7 +35,7 @@ option(FINUFFT_USE_OPENMP "Whether to use OpenMP for parallelization. If disable
option(FINUFFT_USE_CUDA "Whether to build CUDA accelerated FINUFFT library (libcufinufft). This is completely independent of the main FINUFFT library" OFF)
option(FINUFFT_USE_CPU "Whether to build the ordinary FINUFFT library (libfinufft)." ON)
option(FINUFFT_STATIC_LINKING "Whether to link the static FINUFFT library (libfinufft_static)." ON)
option(FINUFFT_BUILD_DEVEL "Whether to build developement executables" OFF)
option(FINUFFT_BUILD_DEVEL "Whether to build development executables" OFF)
# sphinx tag (don't remove): @cmake_opts_end

if (FINUFFT_USE_CPU)
Expand All @@ -47,10 +51,11 @@ if (FINUFFT_USE_CPU)

set(CPM_DOWNLOAD_VERSION 0.38.0)
set(FFTW_VERSION 3.3.10)

set(XTL_VERSION 0.7.7)
set(XSIMD_VERSION 13.0.0)
include(cmake/setupCPM.cmake)
include(cmake/setupFFTW.cmake)

include(cmake/setupXSIMD.cmake)
endif ()

if (FINUFFT_BUILD_MATLAB)
Expand Down Expand Up @@ -92,8 +97,8 @@ function(enable_asan target)

if (CMAKE_CXX_COMPILER_ID IN_LIST FINUFFT_GNU_LIKE_COMPILERS)
# Enable only on clang / gcc compilers.
target_compile_options(${target} PRIVATE $<$<CONFIG:DEBUG>:-fsanitize=address>)
target_link_options(${target} PRIVATE $<$<CONFIG:DEBUG>:-fsanitize=address>)
target_compile_options(${target} PRIVATE $<$<CONFIG:DEBUG>:-fsanitize=address -fsanitize=undefined -fsanitize=bounds-strict>)
target_link_options(${target} PRIVATE $<$<CONFIG:DEBUG>:-fsanitize=address -fsanitize=undefined -fsanitize=bounds-strict>)
endif ()
endfunction()

Expand All @@ -119,17 +124,18 @@ endfunction()
# Utility function to set finufft compilation options.
function(set_finufft_options target)
set_property(TARGET ${target} PROPERTY POSITION_INDEPENDENT_CODE ON)
set_property(TARGET ${target} PROPERTY CMAKE_CXX_STANDARD 14)
target_compile_features(${target} PRIVATE cxx_std_17)

enable_asan(${target})

target_compile_options(${target} PRIVATE SHELL:$<$<CONFIG:Release,RelWithDebInfo>:${FINUFFT_ARCH_FLAGS}>)
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
# Enable cx-limited-range on supported compilers
target_compile_options(${target} PRIVATE $<$<CONFIG:Release,RelWithDebInfo>:-fcx-limited-range>)
endif ()

target_include_directories(${target} PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>)
target_include_directories(${target} SYSTEM INTERFACE $<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/include>)
target_compile_options(${target} PRIVATE $<$<CONFIG:Release>:${FINUFFT_CXX_FLAGS_RELEASE}>)
target_compile_options(${target} PRIVATE $<$<CONFIG:RelWithDebInfo>:${FINUFFT_CXX_FLAGS_RELWITHDEBINFO}>)
target_include_directories(${target} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")
if (FINUFFT_USE_OPENMP)
target_link_libraries(${target} PRIVATE OpenMP::OpenMP_CXX)
# there are issues on windows with OpenMP and CMake, so we need to manually add the flags
Expand Down Expand Up @@ -163,12 +169,13 @@ if (FINUFFT_USE_CPU)
target_compile_definitions(finufft_f32 PRIVATE SINGLE)
set_finufft_options(finufft_f32)
target_link_libraries(finufft_f32 PUBLIC ${FINUFFT_FFTW_LIBRARIES})
target_link_libraries(finufft_f32 PRIVATE xsimd)

add_library(finufft_f64 OBJECT ${FINUFFT_PRECISION_DEPENDENT_SOURCES})
target_compile_definitions(finufft_f64 PRIVATE)
set_finufft_options(finufft_f64)
target_link_libraries(finufft_f64 PUBLIC ${FINUFFT_FFTW_LIBRARIES})

target_link_libraries(finufft_f64 PRIVATE xsimd)
if (WIN32)
add_library(finufft_f32_dll OBJECT ${FINUFFT_PRECISION_DEPENDENT_SOURCES})
target_compile_definitions(finufft_f32_dll PRIVATE SINGLE dll_EXPORTS FINUFFT_DLL)
Expand All @@ -193,8 +200,7 @@ if (FINUFFT_USE_CPU)
if (NOT WIN32)
target_link_libraries(finufft PUBLIC m)
endif ()
target_include_directories(finufft PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>)
target_include_directories(finufft SYSTEM INTERFACE $<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/include>)
target_include_directories(finufft PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")

add_library(finufft_static STATIC src/utils_precindep.cpp contrib/legendre_rule_fast.cpp)
set_finufft_options(finufft_static)
Expand All @@ -203,8 +209,7 @@ if (FINUFFT_USE_CPU)
if (NOT WIN32)
target_link_libraries(finufft_static PUBLIC m)
endif ()
target_include_directories(finufft_static PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>)
target_include_directories(finufft_static SYSTEM INTERFACE $<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/include>)
target_include_directories(finufft_static PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")

file(GLOB FINUFFT_PUBLIC_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/include/finufft*.h")
set_target_properties(finufft PROPERTIES PUBLIC_HEADER "${FINUFFT_PUBLIC_HEADERS}")
Expand Down
19 changes: 19 additions & 0 deletions cmake/setupXSIMD.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
CPMAddPackage(
NAME findxtl
GIT_REPOSITORY "https://github.com/xtensor-stack/xtl.git"
GIT_TAG ${XTL_VERSION}
EXCLUDE_FROM_ALL YES
GIT_SHALLOW YES
OPTIONS "XTL_DISABLE_EXCEPTIONS YES"
)

CPMAddPackage(
NAME findxsimd
GIT_REPOSITORY "https://github.com/xtensor-stack/xsimd.git"
GIT_TAG ${XSIMD_VERSION}
EXCLUDE_FROM_ALL YES
GIT_SHALLOW YES
OPTIONS
"XSIMD_SKIP_INSTALL YES"
"XSIMD_ENABLE_XTL_COMPLEX YES"
)
6 changes: 4 additions & 2 deletions devel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@ if (benchmark_ADDED)
endif()

add_executable(foldrescale foldrescale.cpp)
target_link_libraries(foldrescale finufft benchmark)
target_compile_options(foldrescale PRIVATE -mavx2)
target_link_libraries(foldrescale finufft benchmark xsimd)
add_executable(padding padding.cpp)
target_link_libraries(padding finufft xsimd)
target_compile_options(padding PRIVATE -march=native)
Loading

0 comments on commit 84e6aec

Please sign in to comment.