Skip to content

Commit

Permalink
Merge pull request #22 from CExA-project/cmake-install
Browse files Browse the repository at this point in the history
Adding install capability
  • Loading branch information
yasahi-hpc authored Jan 19, 2024
2 parents c854eb4 + 3a39e67 commit 231a82e
Show file tree
Hide file tree
Showing 17 changed files with 353 additions and 21 deletions.
28 changes: 22 additions & 6 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 All @@ -80,11 +80,23 @@ jobs:
docker run -v ${{github.workspace}}:/work ${{ env.container }} cmake --build build_${backend} --config ${{env.BUILD_TYPE}} -j 2
done
- name: Test on CPUs
- name: Test for OpenMP backend
# Execute tests defined by the CMake configuration. Testing on CPUs only
run: |
docker run -v ${{github.workspace}}:/work ${{ env.container }} ctest --output-on-failure --test-dir build_OPENMP -C ${{env.BUILD_TYPE}}
- name: Install test for OpenMP backend
run: |
docker run -v ${{github.workspace}}:/work ${{ env.container }} ./install_test/bin/install_cpu.sh /tmp
- name: Install test for CUDA backend
run: |
for backend in ${{ env.backends }}; do
if [ ${backend} != "OPENMP" ]; then
docker run -v ${{github.workspace}}:/work ${{ env.container }} ./install_test/bin/install_cuda.sh /tmp ${backend}
fi
done
build_amd:
# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac.
# You can convert this to a matrix build if you need cross-platform coverage.
Expand Down Expand Up @@ -123,9 +135,13 @@ 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
run: |
docker run -v ${{github.workspace}}:/work ${{ env.container }} cmake --build build_${{matrix.backend.name}} --config ${{env.BUILD_TYPE}} -j 2
docker run -v ${{github.workspace}}:/work ${{ env.container }} cmake --build build_${{matrix.backend.name}} --config ${{env.BUILD_TYPE}} -j 2
- name: Install test for HIP backend
run: |
docker run -v ${{github.workspace}}:/work ${{ env.container }} ./install_test/bin/install_hip.sh /tmp ${{matrix.backend.name}}
58 changes: 54 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,56 @@ if(BUILD_TESTING)
endif()
endif()

# Set directories used for install
include(GNUInstallDirs)
set(LIBDIR ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
set(INSTALL_INCLUDEDIR ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR})
set(INSTALL_LIBDIR ${CMAKE_INSTALL_PREFIX}/${LIBDIR})
set(KokkosFFT_EXPORT_TARGET "KokkosFFT-Targets")

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

# Installation
include(CMakePackageConfigHelpers)

install(
TARGETS common fft
EXPORT ${KokkosFFT_EXPORT_TARGET}
)

install(
EXPORT ${KokkosFFT_EXPORT_TARGET}
NAMESPACE KokkosFFT::
DESTINATION ${INSTALL_LIBDIR}
)

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_LIBDIR}
)

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

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}
)
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}/@LIBDIR@/@[email protected]")

include(CMakeFindDependencyMacro)
list(INSERT CMAKE_MODULE_PATH 0 "${PACKAGE_PREFIX_DIR}/@LIBDIR@")
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
48 changes: 48 additions & 0 deletions install_test/bin/install_cpu.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash

args=$#
ROOT_DIR=$1
WK_DIR=$(pwd)
TARGET="cpu"

# Install Kokkos
export KOKKOS_INSTALL_PREFIX=${ROOT_DIR}/usr/local/kokkos_${TARGET}
export Kokkos_DIR=${KOKKOS_INSTALL_PREFIX}/lib/cmake/Kokkos
export KOKKOS_BUILD_DIR=build_Kokkos_${TARGET}

export KOKKOSFFT_INSTALL_PREFIX=${ROOT_DIR}/usr/local/kokkosFFT_${TARGET}
export KokkosFFT_DIR=${KOKKOSFFT_INSTALL_PREFIX}/lib/cmake/kokkos-fft
export KOKKOSFFT_BUILD_DIR=build_KokkosFFT_${TARGET}

export EXAMPLE_BUILD_DIR=build_example_${TARGET}

# Install Kokkos
cd ${WK_DIR}
mkdir ${KOKKOS_BUILD_DIR} && cd ${KOKKOS_BUILD_DIR}

# Get Kokkos from github repo and build
git clone https://github.com/kokkos/kokkos.git
cmake -DBUILD_TESTING=OFF -DCMAKE_BUILD_TYPE=RelWithDebInfo -DKokkos_ENABLE_OPENMP=ON -DCMAKE_INSTALL_PREFIX=${KOKKOS_INSTALL_PREFIX} kokkos
cmake --build . -j 8
cmake --install .

# Install KokkosFFT
cd ${WK_DIR}
mkdir ${KOKKOSFFT_BUILD_DIR} && cd ${KOKKOSFFT_BUILD_DIR}
cmake -DBUILD_TESTING=OFF -DCMAKE_BUILD_TYPE=RelWithDebInfo -DKokkos_ENABLE_OPENMP=ON -DCMAKE_INSTALL_PREFIX=${KOKKOSFFT_INSTALL_PREFIX} ..
cmake --build . -j 8
cmake --install .

# Try to build an example
# Build KokkosFFT code using installed KokkosFFT
cd ${WK_DIR}
mkdir ${EXAMPLE_BUILD_DIR} && cd ${EXAMPLE_BUILD_DIR}
cmake -DCMAKE_BUILD_TYPE=Release -DKokkos_ENABLE_OPENMP=ON ../install_test/src
cmake --build . -j 8

if [ $? -eq 0 ]; then
echo "*** install test: build SUCCESSFUL ***"
else
echo "*** install test: build FAILED ***"
exit 1;
fi
64 changes: 64 additions & 0 deletions install_test/bin/install_cuda.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/bin/bash

args=$#
ROOT_DIR=$1
WK_DIR=$(pwd)
TARGET=$2
KOKKOS_TARGET=${TARGET}

# Install Kokkos
export KOKKOS_INSTALL_PREFIX=${ROOT_DIR}/usr/local/kokkos_${KOKKOS_TARGET}
export Kokkos_DIR=${KOKKOS_INSTALL_PREFIX}/lib/cmake/Kokkos
export KOKKOS_BUILD_DIR=build_Kokkos_${KOKKOS_TARGET}

export KOKKOSFFT_INSTALL_PREFIX=${ROOT_DIR}/usr/local/kokkosFFT_${TARGET}
export KokkosFFT_DIR=${KOKKOSFFT_INSTALL_PREFIX}/lib/cmake/kokkos-fft
export KOKKOSFFT_BUILD_DIR=build_KokkosFFT_${TARGET}

export EXAMPLE_BUILD_DIR=build_example_${TARGET}
export CXX_COMPILER=${WK_DIR}/${KOKKOS_BUILD_DIR}/kokkos/bin/nvcc_wrapper

# Install Kokkos if not exist
if [ ! -d ${Kokkos_DIR} ]; then
cd ${WK_DIR}
mkdir ${KOKKOS_BUILD_DIR} && cd ${KOKKOS_BUILD_DIR}

# Get Kokkos from github repo and build
git clone https://github.com/kokkos/kokkos.git
cmake -DCMAKE_CXX_COMPILER=${CXX_COMPILER} \
-DCMAKE_CXX_STANDARD=17 -DKokkos_ENABLE_CUDA=ON -DKokkos_ARCH_AMPERE80=ON \
-DCMAKE_INSTALL_PREFIX=${KOKKOS_INSTALL_PREFIX} kokkos

cmake --build . -j 8
cmake --install .
fi

# Install KokkosFFT
cd ${WK_DIR}
mkdir ${KOKKOSFFT_BUILD_DIR} && cd ${KOKKOSFFT_BUILD_DIR}
if [ $TARGET == "CUDA" ]; then
cmake -DCMAKE_CXX_COMPILER=${CXX_COMPILER} \
-DCMAKE_CXX_STANDARD=17 -DKokkos_ENABLE_CUDA=ON -DKokkos_ARCH_AMPERE80=ON \
-DCMAKE_INSTALL_PREFIX=${KOKKOSFFT_INSTALL_PREFIX} ..
else
cmake -DCMAKE_CXX_COMPILER=${CXX_COMPILER} \
-DCMAKE_CXX_STANDARD=17 -DKokkos_ENABLE_CUDA=ON -DKokkos_ARCH_AMPERE80=ON \
-DCMAKE_INSTALL_PREFIX=${KOKKOSFFT_INSTALL_PREFIX} -DKokkosFFT_ENABLE_HOST_AND_DEVICE=ON ..
fi
cmake --build . -j 8
cmake --install .

# Try to build an example
# Build KokkosFFT code using installed KokkosFFT
cd ${WK_DIR}
mkdir ${EXAMPLE_BUILD_DIR} && cd ${EXAMPLE_BUILD_DIR}
cmake -DCMAKE_CXX_COMPILER=${CXX_COMPILER} \
-DCMAKE_CXX_STANDARD=17 -DKokkos_ENABLE_CUDA=ON -DKokkos_ARCH_AMPERE80=ON ../install_test/src
cmake --build . -j 8

if [ $? -eq 0 ]; then
echo "*** install test: build SUCCESSFUL ***"
else
echo "*** install test: build FAILED ***"
exit 1;
fi
Loading

0 comments on commit 231a82e

Please sign in to comment.