Skip to content

Commit

Permalink
Merge pull request #122 from dssgabriel/cmake
Browse files Browse the repository at this point in the history
Modernizing CMake and packaging
  • Loading branch information
dssgabriel authored Sep 20, 2024
2 parents be3f6c6 + 27fc42d commit 8e177a9
Show file tree
Hide file tree
Showing 10 changed files with 365 additions and 233 deletions.
144 changes: 66 additions & 78 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,108 +1,96 @@
#@HEADER
# ************************************************************************
#
# Kokkos v. 4.0
# Copyright (2022) National Technology & Engineering
# Solutions of Sandia, LLC (NTESS).
#
# Under the terms of Contract DE-NA0003525 with NTESS,
# the U.S. Government retains certain rights in this software.
#
# Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions.
# See https://kokkos.org/LICENSE for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
#@HEADER

# 3.9: MPI::MPI_CXX
# 3.12: CMAKE_PROJECT_VERSION_MAJOR
# 3.15: PUBLIC_HEADER files for interface libraries
cmake_minimum_required(VERSION 3.12)
project(KokkosComm VERSION 0.0.2)
# 3.23: FILE_SETs for easy export of header-only libraries
cmake_minimum_required(VERSION 3.23)

project(
KokkosComm
LANGUAGES
CXX
VERSION 0.2.0
DESCRIPTION "Experimental MPI interfaces (and more!) for the Kokkos C++ Performance Portability Programming ecosystem"
HOMEPAGE_URL "https://kokkos.org/kokkos-comm/"
)

option(KokkosComm_ENABLE_PERFTESTS "Build KokkosComm perf tests" OFF)
option(KokkosComm_ENABLE_TESTS "Build KokkosComm perf tests" OFF)
option(KokkosComm_ENABLE_TESTS "Build KokkosComm tests" OFF)
option(KokkosComm_ENABLE_MPI "Build KokkosComm with MPI transport" ON)


## resolve options
# Resolve options
set(KOKKOSCOMM_ENABLE_PERFTESTS ${KokkosComm_ENABLE_PERFTESTS} CACHE BOOL "" FORCE)
set(KOKKOSCOMM_ENABLE_TESTS ${KokkosComm_ENABLE_TESTS} CACHE BOOL "" FORCE)
set(KOKKOSCOMM_ENABLE_MPI ${KokkosComm_ENABLE_MPI} CACHE BOOL "" FORCE)

find_package(Kokkos REQUIRED)
find_package(MPI REQUIRED)

message(STATUS "Kokkos Comm: MPI_VERSION = ${MPI_VERSION}")
message(STATUS "Kokkos Comm: MPI_CXX_COMPILER = ${MPI_CXX_COMPILER}")
message(STATUS "Kokkos Comm: MPI_CXX_COMPILE_OPTIONS = ${MPI_CXX_COMPILE_OPTIONS}")
message(STATUS "Kokkos Comm: MPI_CXX_COMPILE_DEFINITIONS = ${MPI_CXX_COMPILE_DEFINITIONS}")
message(STATUS "Kokkos Comm: MPI_CXX_INCLUDE_DIRS = ${MPI_CXX_INCLUDE_DIRS}")
message(STATUS "Kokkos Comm: MPI_CXX_LINK_FLAGS = ${MPI_CXX_LINK_FLAGS}")
message(STATUS "Kokkos Comm: MPI_CXX_LIBRARIES = ${MPI_CXX_LIBRARIES}")

if(KOKKOSCOMM_ENABLE_MPI)
find_package(MPI REQUIRED)
endif()

include(cmake/flags.cmake)
add_subdirectory(src)
kokkoscomm_add_cxx_flags(TARGET KokkosComm INTERFACE)
if(KOKKOSCOMM_ENABLE_TESTS)
add_subdirectory(unit_tests)
endif()
if(KOKKOSCOMM_ENABLE_PERFTESTS)
add_subdirectory(perf_tests)
endif()

## Version config file
# -- PACKAGING -- #
include(CMakePackageConfigHelpers)
include(GNUInstallDirs)

# Generate version config header
set(KOKKOSCOMM_VERSION_MAJOR ${CMAKE_PROJECT_VERSION_MAJOR} CACHE STRING "" FORCE)
set(KOKKOSCOMM_VERSION_MINOR ${CMAKE_PROJECT_VERSION_MINOR} CACHE STRING "" FORCE)
set(KOKKOSCOMM_VERSION_PATCH ${CMAKE_PROJECT_VERSION_PATCH} CACHE STRING "" FORCE)
configure_file(
${CMAKE_CURRENT_LIST_DIR}/cmake/KokkosComm_config.hpp.in
${CMAKE_CURRENT_BINARY_DIR}/src/KokkosComm_config.hpp
@ONLY
${PROJECT_SOURCE_DIR}/cmake/KokkosComm_config.hpp.in
${PROJECT_BINARY_DIR}/src/KokkosComm/config.hpp
@ONLY
)

# this sets CMAKE_INSTALL_[...]DIR
include(GNUInstallDirs)

target_include_directories(KokkosComm INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/src/>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
# Generate package config file
configure_package_config_file(
${PROJECT_SOURCE_DIR}/cmake/Config.cmake.in
${PROJECT_BINARY_DIR}/cmake/KokkosComm/KokkosCommConfig.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/KokkosComm
NO_SET_AND_CHECK_MACRO
NO_CHECK_REQUIRED_COMPONENTS_MACRO
)

## Package config file
include(CMakePackageConfigHelpers)
configure_package_config_file (
${PROJECT_SOURCE_DIR}/cmake/Config.cmake.in
${PROJECT_BINARY_DIR}/cmake/KokkosComm/${PROJECT_NAME}Config.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
NO_SET_AND_CHECK_MACRO
NO_CHECK_REQUIRED_COMPONENTS_MACRO
)
# Generate package version file
write_basic_package_version_file(
${PROJECT_BINARY_DIR}/cmake/KokkosComm/${PROJECT_NAME}Version.cmake
COMPATIBILITY SameMajorVersion
)

export (
TARGETS KokkosComm
NAMESPACE "${PROJECT_NAME}::"
FILE ${PROJECT_BINARY_DIR}/cmake/KokkosComm/KokkosCommTargets.cmake
${PROJECT_BINARY_DIR}/cmake/KokkosComm/KokkosCommVersion.cmake
COMPATIBILITY SameMajorVersion
ARCH_INDEPENDENT # KokkosComm is a header-only library
)


install(
TARGETS KokkosComm
EXPORT KokkosCommTargets # does this do anything?
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
# install the include tree
install(
DIRECTORY "src/"
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING PATTERN "*.hpp")
# install the configured files
# Install CMake package files
install(
DIRECTORY "${PROJECT_BINARY_DIR}/src/"
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING PATTERN "*.hpp")
install(
FILES
"${PROJECT_BINARY_DIR}/cmake/KokkosComm/KokkosCommConfig.cmake"
"${PROJECT_BINARY_DIR}/cmake/KokkosComm/KokkosCommVersion.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/KokkosComm/
FILES
${PROJECT_BINARY_DIR}/cmake/KokkosComm/KokkosCommConfig.cmake
${PROJECT_BINARY_DIR}/cmake/KokkosComm/KokkosCommVersion.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/KokkosComm
)
install(
EXPORT KokkosCommTargets
NAMESPACE "${PROJECT_NAME}::"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
EXPORT KokkosCommTargets
FILE KokkosCommTargets.cmake
NAMESPACE KokkosComm::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/KokkosComm
)


if(KOKKOSCOMM_ENABLE_TESTS)
enable_testing()
add_subdirectory(unit_tests)
endif()
if(KOKKOSCOMM_ENABLE_PERFTESTS)
enable_testing()
add_subdirectory(perf_tests)
endif()
27 changes: 18 additions & 9 deletions cmake/Config.cmake.in
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
#@HEADER
# ************************************************************************
#
# Kokkos v. 4.0
# Copyright (2022) National Technology & Engineering
# Solutions of Sandia, LLC (NTESS).
#
# Under the terms of Contract DE-NA0003525 with NTESS,
# the U.S. Government retains certain rights in this software.
#
# Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions.
# See https://kokkos.org/LICENSE for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
#@HEADER

@PACKAGE_INIT@

GET_FILENAME_COMPONENT(KokkosComm_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
INCLUDE("${KokkosComm_CMAKE_DIR}/KokkosCommTargets.cmake")
UNSET(KokkosComm_CMAKE_DIR)

include(CMakeFindDependencyMacro)
find_dependency(MPI)
find_dependency(Kokkos)

set(KOKKOSCOMM_ENABLE_MPI @KOKKOSCOMM_ENABLE_MPI@)

## FIXME: do we need this?
set(KokkosComm_INCLUDE_DIR "@CMAKE_INSTALL_FULL_INCLUDEDIR@" )
set(KokkosComm_DATA_DIR "@CMAKE_INSTALL_PREFIX@/@RELATIVE_DATA_INSTALL_DIR@" )
set(KokkosComm_ICONS_DIR "@CMAKE_INSTALL_PREFIX@/share/icons" )
set(KokkosComm_CONFIG_DIR "${installedPrefix}/@CONFIG_INSTALL_DIR@" )
INCLUDE("${KokkosComm_CMAKE_DIR}/KokkosCommTargets.cmake")
UNSET(KokkosComm_CMAKE_DIR)
66 changes: 0 additions & 66 deletions cmake/flags.cmake

This file was deleted.

48 changes: 33 additions & 15 deletions perf_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,36 +1,54 @@
cmake_minimum_required(VERSION 3.12) # same as Kokkos Comm
project(KokkosCommPerfTests VERSION 0.0.2)
#@HEADER
# ************************************************************************
#
# Kokkos v. 4.0
# Copyright (2022) National Technology & Engineering
# Solutions of Sandia, LLC (NTESS).
#
# Under the terms of Contract DE-NA0003525 with NTESS,
# the U.S. Government retains certain rights in this software.
#
# Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions.
# See https://kokkos.org/LICENSE for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
#@HEADER

cmake_minimum_required(VERSION 3.23) # same as KokkosComm

project(
KokkosCommPerfTests
VERSION 0.2.0
LANGUAGES
CXX
DESCRIPTION "Performance tests for the KokkosComm experimental communication interfaces"
)

enable_testing()

# Treat the perf tests as a separate project
# If not included in the Kokkos Comm build,
# find Kokkos Comm to do a standalone build
if (NOT TARGET KokkosComm::KokkosComm)
# If not included in the Kokkos Comm build, find Kokkos Comm to do a standalone build
if(NOT TARGET KokkosComm::KokkosComm)
find_package(KokkosComm REQUIRED)
endif()

include(FetchContent)

# Avoid warning about DOWNLOAD_EXTRACT_TIMESTAMP in CMake 3.24:
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
cmake_policy(SET CMP0135 NEW)
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
cmake_policy(SET CMP0135 NEW)
endif()

set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "" FORCE)
FetchContent_Declare(
benchmark
URL https://github.com/google/benchmark/archive/refs/tags/v1.8.3.zip
)
# FetchContent_MakeAvailable(benchmark)
# was making install install benchmark as well
FetchContent_Declare(benchmark URL https://github.com/google/benchmark/archive/refs/tags/v1.8.3.zip)
# FetchContent_MakeAvailable(benchmark) was making install benchmark as well
# EXCLUDE_FROM_ALL here seems to be the magic
if (NOT benchmark_POPULATED)
if(NOT benchmark_POPULATED)
FetchContent_Populate(benchmark)
add_subdirectory(${benchmark_SOURCE_DIR} ${benchmark_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()
unset(BENCHMARK_ENABLE_TESTING)

if (KOKKOSCOMM_ENABLE_MPI)
if(KOKKOSCOMM_ENABLE_MPI)
add_subdirectory(mpi)
endif(KOKKOSCOMM_ENABLE_MPI)
40 changes: 32 additions & 8 deletions perf_tests/mpi/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,35 @@
add_executable(perf_test-main test_main.cpp
#@HEADER
# ************************************************************************
#
# Kokkos v. 4.0
# Copyright (2022) National Technology & Engineering
# Solutions of Sandia, LLC (NTESS).
#
# Under the terms of Contract DE-NA0003525 with NTESS,
# the U.S. Government retains certain rights in this software.
#
# Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions.
# See https://kokkos.org/LICENSE for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
#@HEADER

add_executable(perf-test-main)
target_sources(
perf-test-main
PRIVATE
test_main.cpp
test_sendrecv.cpp
test_2dhalo.cpp
test_osu_latency.cpp
)
if(KOKKOSCOMM_ENABLE_TESTS)
kokkoscomm_add_cxx_flags(TARGET perf_test-main)
endif()
target_link_libraries(perf_test-main KokkosComm::KokkosComm benchmark::benchmark)
add_test(NAME perf_test-main
COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} 2 ./perf_test-main)
)
target_link_libraries(
perf-test-main
KokkosComm::KokkosComm
benchmark::benchmark
)
add_test(
NAME perf-test-main
COMMAND
${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} 2 ./perf-test-main
)
Loading

0 comments on commit 8e177a9

Please sign in to comment.