Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding install capability #22

Merged
merged 15 commits into from
Jan 19, 2024
8 changes: 4 additions & 4 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ jobs:
run: |
docker run -v ${{github.workspace}}:/work ${{ env.container }} cmake -B build_OPENMP \
-DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_CXX_COMPILER=g++ \
-DCMAKE_CXX_STANDARD=17 -DKokkos_ENABLE_OPENMP=ON -DBUILD_TESTING=ON
-DCMAKE_CXX_STANDARD=17 -DKokkos_ENABLE_OPENMP=ON -DBUILD_TESTING=ON -DKokkosFFT_INTERNAL_Kokkos=ON

- name: Configure CMake for CUDA backend
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: |
docker run -v ${{github.workspace}}:/work ${{ env.container }} cmake -B build_CUDA \
-DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_CXX_COMPILER=${{env.CMAKE_CXX_COMPILER}} \
-DCMAKE_CXX_STANDARD=17 -DKokkos_ENABLE_CUDA=ON -DKokkos_ARCH_${{env.CUDA_ARCHITECTURES}}=ON -DBUILD_TESTING=ON
-DCMAKE_CXX_STANDARD=17 -DKokkos_ENABLE_CUDA=ON -DKokkos_ARCH_${{env.CUDA_ARCHITECTURES}}=ON -DBUILD_TESTING=ON -DKokkosFFT_INTERNAL_Kokkos=ON

- name: Configure CMake for CUDA backend with HOST and DEVICE option
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
Expand All @@ -71,7 +71,7 @@ jobs:
docker run -v ${{github.workspace}}:/work ${{ env.container }} cmake -B build_CUDA_HOST_DEVICE \
-DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_CXX_COMPILER=${{env.CMAKE_CXX_COMPILER}} \
-DCMAKE_CXX_STANDARD=17 -DKokkos_ENABLE_CUDA=ON -DKokkos_ARCH_${{env.CUDA_ARCHITECTURES}}=ON -DBUILD_TESTING=ON \
-DKokkosFFT_ENABLE_HOST_AND_DEVICE=ON
-DKokkosFFT_ENABLE_HOST_AND_DEVICE=ON -DKokkosFFT_INTERNAL_Kokkos=ON

- name: Build
# Build your program with the given configuration
Expand Down Expand Up @@ -123,7 +123,7 @@ jobs:
run: |
docker run -v ${{github.workspace}}:/work ${{ env.container }} cmake -B build_${{matrix.backend.name}} \
-DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_CXX_COMPILER=${{env.CMAKE_CXX_COMPILER}} \
-DCMAKE_CXX_STANDARD=17 -DKokkos_ENABLE_HIP=ON -DKokkos_ARCH_${{env.architecture}}=ON -DBUILD_TESTING=ON ${{matrix.backend.option}}
-DCMAKE_CXX_STANDARD=17 -DKokkos_ENABLE_HIP=ON -DKokkosFFT_INTERNAL_Kokkos=ON -DKokkos_ARCH_${{env.architecture}}=ON -DBUILD_TESTING=ON ${{matrix.backend.option}}

- name: Build
# Build your program with the given configuration
Expand Down
56 changes: 52 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_SOURCE_DIR}/cmake")
# Options
option(BUILD_EXAMPLES "Build kokkos-fft examples" ON)
option(KokkosFFT_ENABLE_HOST_AND_DEVICE "Enable fft on both host and device" OFF)
option(KokkosFFT_INTERNAL_Kokkos "Build internal Kokkos instead of relying on external one" OFF)

find_package(Kokkos CONFIG)
if(NOT kokkos_FOUND)
if (NOT KokkosFFT_INTERNAL_Kokkos)
find_package(Kokkos REQUIRED)
else ()
add_subdirectory(tpls/kokkos)
endif()
endif ()

# Googletest
include(CTest)
Expand All @@ -22,8 +24,54 @@ if(BUILD_TESTING)
endif()
endif()

# Set directories used for install
include(GNUInstallDirs)
set(INSTALL_INCLUDEDIR ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR})
set(INSTALL_LIBDIR ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR})

add_subdirectory(common)
add_subdirectory(fft)
if(BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
endif()

# Installation
include(CMakePackageConfigHelpers)

install(
TARGETS common fft
EXPORT KokkosFFT-targets
)

install(
EXPORT KokkosFFT-targets
cedricchevalier19 marked this conversation as resolved.
Show resolved Hide resolved
NAMESPACE KokkosFFT::
DESTINATION ${INSTALL_INCLUDEDIR}
)

install(
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/common/src/ ${CMAKE_CURRENT_SOURCE_DIR}/fft/src/
DESTINATION ${INSTALL_INCLUDEDIR}
)

install(
FILES ${CMAKE_SOURCE_DIR}/cmake/FindFFTW.cmake
DESTINATION ${INSTALL_INCLUDEDIR}
)

configure_package_config_file(cmake/KokkosFFTConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/KokkosFFTConfig.cmake
INSTALL_DESTINATION ${INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
)

write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/KokkosFFTConfigVersion.cmake
VERSION 0.0.0
COMPATIBILITY SameMajorVersion
)

install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/KokkosFFTConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/KokkosFFTConfigVersion.cmake
DESTINATION ${INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
)
29 changes: 29 additions & 0 deletions cmake/KokkosFFTConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
@PACKAGE_INIT@

# Set and Check must go first else macro might be redefined by find_dependency ...
set_and_check(KokkosFFT_TARGET_FILE
"${PACKAGE_PREFIX_DIR}/include/KokkosFFT-targets.cmake")

include(CMakeFindDependencyMacro)
list(INSERT CMAKE_MODULE_PATH 0 "${PACKAGE_PREFIX_DIR}/include")
find_dependency(Kokkos)

if(@Kokkos_ENABLE_CUDA@)
find_dependency(CUDAToolkit COMPONENTS cufft)
if(@KokkosFFT_ENABLE_HOST_AND_DEVICE@)
find_dependency(FFTW MODULE)
endif()
elseif(@Kokkos_ENABLE_HIP@)
find_dependency(hipfft)
if(@KokkosFFT_ENABLE_HOST_AND_DEVICE@)
find_dependency(FFTW MODULE)
endif()
elseif(@Kokkos_ENABLE_OPENMP@)
find_dependency(FFTW MODULE)
elseif(@Kokkos_ENABLE_SERIAL@)
find_dependency(FFTW MODULE)
endif()

include(${KokkosFFT_TARGET_FILE})

check_required_components(KokkosFFT)
5 changes: 4 additions & 1 deletion common/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,7 @@ elseif(Kokkos_ENABLE_SERIAL)
endif()

target_compile_features(common INTERFACE cxx_std_17)
target_include_directories(common INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
target_include_directories(common INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:${INSTALL_INCLUDEDIR}>
)
2 changes: 1 addition & 1 deletion examples/01_1DFFT/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
add_executable(01_1DFFT 01_1DFFT.cpp)
target_link_libraries(01_1DFFT PUBLIC Kokkos::fft)
target_link_libraries(01_1DFFT PUBLIC KokkosFFT::fft)
2 changes: 1 addition & 1 deletion examples/02_2DFFT/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
add_executable(02_2DFFT 02_2DFFT.cpp)
target_link_libraries(02_2DFFT PUBLIC Kokkos::fft)
target_link_libraries(02_2DFFT PUBLIC KokkosFFT::fft)
2 changes: 1 addition & 1 deletion examples/03_NDFFT/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
add_executable(03_NDFFT 03_NDFFT.cpp)
target_link_libraries(03_NDFFT PUBLIC Kokkos::fft)
target_link_libraries(03_NDFFT PUBLIC KokkosFFT::fft)
2 changes: 1 addition & 1 deletion examples/04_batchedFFT/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
add_executable(04_batchedFFT 04_batchedFFT.cpp)
target_link_libraries(04_batchedFFT PUBLIC Kokkos::fft)
target_link_libraries(04_batchedFFT PUBLIC KokkosFFT::fft)
2 changes: 1 addition & 1 deletion examples/05_1DFFT_HOST_DEVICE/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
add_executable(05_1DFFT_HOST_DEVICE 05_1DFFT_HOST_DEVICE.cpp)
target_link_libraries(05_1DFFT_HOST_DEVICE PUBLIC Kokkos::fft)
target_link_libraries(05_1DFFT_HOST_DEVICE PUBLIC KokkosFFT::fft)
2 changes: 1 addition & 1 deletion examples/06_1DFFT_reuse_plans/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
add_executable(06_1DFFT_reuse_plans 06_1DFFT_reuse_plans.cpp)
target_link_libraries(06_1DFFT_reuse_plans PUBLIC Kokkos::fft)
target_link_libraries(06_1DFFT_reuse_plans PUBLIC KokkosFFT::fft)
7 changes: 5 additions & 2 deletions fft/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@ target_link_libraries(fft
Kokkos::kokkos
)

target_include_directories(fft INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
add_library(Kokkos::fft ALIAS fft)
target_include_directories(fft INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:${INSTALL_INCLUDEDIR}>
)
add_library(KokkosFFT::fft ALIAS fft)
4 changes: 2 additions & 2 deletions fft/unit_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ add_executable(unit-tests-kokkos-fft-core
Test_Main.cpp
Test_Plans.cpp
Test_Transform.cpp
Test_Helpers.cpp
Test_Helpers.cpp
)

target_compile_features(unit-tests-kokkos-fft-core PUBLIC cxx_std_17)
target_compile_options(unit-tests-kokkos-fft-core PUBLIC -std=c++17)

target_link_libraries(unit-tests-kokkos-fft-core PUBLIC Kokkos::fft GTest::gtest)
target_link_libraries(unit-tests-kokkos-fft-core PUBLIC KokkosFFT::fft GTest::gtest)

# Enable GoogleTest
include(GoogleTest)
Expand Down
9 changes: 9 additions & 0 deletions install_test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cmake_minimum_required(VERSION 3.21)
project(install-test LANGUAGES CXX)

find_package(Kokkos CONFIG REQUIRED)
find_package(KokkosFFT CONFIG REQUIRED)
cedricchevalier19 marked this conversation as resolved.
Show resolved Hide resolved

add_executable(install-test main.cpp)
target_compile_features(install-test PUBLIC cxx_std_17)
target_link_libraries(install-test PUBLIC Kokkos::kokkos KokkosFFT::fft)
44 changes: 44 additions & 0 deletions install_test/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include <Kokkos_Core.hpp>
#include <Kokkos_Complex.hpp>
#include <Kokkos_Random.hpp>
#include <KokkosFFT.hpp>

using execution_space = Kokkos::DefaultExecutionSpace;
template <typename T>
using View1D = Kokkos::View<T*, execution_space>;

int main(int argc, char* argv[]) {
Kokkos::initialize(argc, argv);
{
constexpr int n0 = 128;
const Kokkos::complex<double> I(1.0, 1.0);

// 1D C2C FFT (Forward and Backward)
View1D<Kokkos::complex<double> > xc2c("xc2c", n0);
View1D<Kokkos::complex<double> > xc2c_hat("xc2c_hat", n0);
View1D<Kokkos::complex<double> > xc2c_inv("xc2c_inv", n0);

Kokkos::Random_XorShift64_Pool<> random_pool(12345);
Kokkos::fill_random(xc2c, random_pool, I);

KokkosFFT::fft(execution_space(), xc2c, xc2c_hat);
KokkosFFT::ifft(execution_space(), xc2c_hat, xc2c_inv);

// 1D R2C FFT
View1D<double> xr2c("xr2c", n0);
View1D<Kokkos::complex<double> > xr2c_hat("xr2c_hat", n0 / 2 + 1);
Kokkos::fill_random(xr2c, random_pool, 1);

KokkosFFT::rfft(execution_space(), xr2c, xr2c_hat);

// 1D C2R FFT
View1D<Kokkos::complex<double> > xc2r("xr2c_hat", n0 / 2 + 1);
View1D<double> xc2r_hat("xc2r", n0);
Kokkos::fill_random(xc2r, random_pool, I);

KokkosFFT::irfft(execution_space(), xc2r, xc2r_hat);
}
Kokkos::finalize();

return 0;
}