diff --git a/CMakeLists.txt b/CMakeLists.txt index 1644baf4..ea75655b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 - $ - $ +# 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() diff --git a/cmake/Config.cmake.in b/cmake/Config.cmake.in index 47388a45..36720136 100644 --- a/cmake/Config.cmake.in +++ b/cmake/Config.cmake.in @@ -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@" ) \ No newline at end of file +INCLUDE("${KokkosComm_CMAKE_DIR}/KokkosCommTargets.cmake") +UNSET(KokkosComm_CMAKE_DIR) diff --git a/cmake/flags.cmake b/cmake/flags.cmake deleted file mode 100644 index 7badcf83..00000000 --- a/cmake/flags.cmake +++ /dev/null @@ -1,66 +0,0 @@ -# if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") -# # using Clang -# elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") -# # using GCC -# elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Intel") -# # using Intel C++ -# elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") -# # using Visual Studio C++ -# endif() - -include(CheckCXXCompilerFlag) - -check_cxx_compiler_flag(-Wall CXX_HAS_WALL) -check_cxx_compiler_flag(-Wextra CXX_HAS_WEXTRA) -check_cxx_compiler_flag(-Wshadow CXX_HAS_WSHADOW) -check_cxx_compiler_flag(-Wpedantic CXX_HAS_WPEDANTIC) -check_cxx_compiler_flag(-pedantic CXX_HAS_PEDANTIC) -check_cxx_compiler_flag(-Wcast-align CXX_HAS_CAST_ALIGN) -check_cxx_compiler_flag(-Wformat=2 CXX_HAS_WFORMAT2) -check_cxx_compiler_flag(-Wmissing-include-dirs CXX_HAS_WMISSING_INCLUDE_DIRS) -check_cxx_compiler_flag(-Wno-gnu-zero-variadic-macro-arguments CXX_HAS_NO_GNU_ZERO_VARIADIC_MACRO_ARGUMENTS) - - -function(kokkoscomm_add_cxx_flags) - - cmake_parse_arguments(ADD_CXX_FLAGS "INTERFACE" "TARGET" "" ${ARGN}) - - if(ADD_CXX_FLAGS_INTERFACE) - set(TARGET_COMPILE_OPTIONS_KEYWORD INTERFACE) - set(TARGET_COMPILE_FEATURES_KEYWORD INTERFACE) - else() - set(TARGET_COMPILE_OPTIONS_KEYWORD PRIVATE) - set(TARGET_COMPILE_FEATURES_KEYWORD PRIVATE) - endif() - - if(CXX_HAS_WEXTRA) - target_compile_options(${ADD_CXX_FLAGS_TARGET} ${TARGET_COMPILE_OPTIONS_KEYWORD} $) - endif() - if(CXX_HAS_WSHADOW) - target_compile_options(${ADD_CXX_FLAGS_TARGET} ${TARGET_COMPILE_OPTIONS_KEYWORD} $) - endif() - if(CXX_HAS_WPEDANTIC) - target_compile_options(${ADD_CXX_FLAGS_TARGET} ${TARGET_COMPILE_OPTIONS_KEYWORD} $) - endif() - if(NOT CXX_HAS_WPEDANTIC AND CXX_HAS_PEDANTIC) - target_compile_options(${ADD_CXX_FLAGS_TARGET} ${TARGET_COMPILE_OPTIONS_KEYWORD} $) - endif() - if(CXX_HAS_CAST_ALIGN) - target_compile_options(${ADD_CXX_FLAGS_TARGET} ${TARGET_COMPILE_OPTIONS_KEYWORD} $) - endif() - if(CXX_HAS_WFORMAT2) - target_compile_options(${ADD_CXX_FLAGS_TARGET} ${TARGET_COMPILE_OPTIONS_KEYWORD} $) - endif() - if(CXX_HAS_WMISSING_INCLUDE_DIRS) - target_compile_options(${ADD_CXX_FLAGS_TARGET} ${TARGET_COMPILE_OPTIONS_KEYWORD} $) - endif() - # gtest includes sometimes yield this warning - if(CXX_HAS_NO_GNU_ZERO_VARIADIC_MACRO_ARGUMENTS) - target_compile_options(${ADD_CXX_FLAGS_TARGET} ${TARGET_COMPILE_OPTIONS_KEYWORD} $) - endif() - - # choose cxx standard - set_target_properties(${ADD_CXX_FLAGS_TARGET} PROPERTIES CXX_EXTENSIONS OFF) - target_compile_features(${ADD_CXX_FLAGS_TARGET} ${TARGET_COMPILE_FEATURES_KEYWORD} cxx_std_20) - -endfunction() diff --git a/perf_tests/CMakeLists.txt b/perf_tests/CMakeLists.txt index 82194239..9926e18d 100644 --- a/perf_tests/CMakeLists.txt +++ b/perf_tests/CMakeLists.txt @@ -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) diff --git a/perf_tests/mpi/CMakeLists.txt b/perf_tests/mpi/CMakeLists.txt index 0a08c203..95849c65 100644 --- a/perf_tests/mpi/CMakeLists.txt +++ b/perf_tests/mpi/CMakeLists.txt @@ -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) \ No newline at end of file +) +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 +) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 138f7e34..b10f47d4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,12 +1,17 @@ -add_library(KokkosComm INTERFACE) -add_library(KokkosComm::KokkosComm ALIAS KokkosComm) - -target_include_directories(KokkosComm INTERFACE - $ -) - -target_include_directories(KokkosComm INTERFACE - $ -) -target_link_libraries(KokkosComm INTERFACE MPI::MPI_CXX Kokkos::kokkos) +#@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_subdirectory(KokkosComm) diff --git a/src/KokkosComm/CMakeLists.txt b/src/KokkosComm/CMakeLists.txt new file mode 100644 index 00000000..9a8fb7d7 --- /dev/null +++ b/src/KokkosComm/CMakeLists.txt @@ -0,0 +1,135 @@ +#@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 + +set(TARGET_LIBRARY kokkoscomm) + +add_library(KokkosComm INTERFACE) +add_library(KokkosComm::KokkosComm ALIAS KokkosComm) + +# Public headers +target_sources( + KokkosComm + INTERFACE + FILE_SET kokkoscomm_public_headers + TYPE HEADERS + BASE_DIRS ${PROJECT_SOURCE_DIR}/src + FILES KokkosComm.hpp collective.hpp concepts.hpp fwd.hpp point_to_point.hpp traits.hpp +) + +# Implementation detail headers +target_sources( + KokkosComm + INTERFACE + FILE_SET kokkoscomm_impl_headers + TYPE HEADERS + BASE_DIRS ${PROJECT_SOURCE_DIR}/src + FILES impl/KokkosComm_contiguous.hpp +) + +# Configuration header +target_sources( + KokkosComm + INTERFACE + FILE_SET kokkoscomm_config_headers + TYPE HEADERS + BASE_DIRS ${CMAKE_BINARY_DIR}/src + FILES ${PROJECT_BINARY_DIR}/src/KokkosComm/config.hpp +) + +if(KOKKOSCOMM_ENABLE_MPI) + # Public MPI headers + target_sources( + KokkosComm + INTERFACE + FILE_SET kokkoscomm_mpi_headers + TYPE HEADERS + BASE_DIRS ${PROJECT_SOURCE_DIR}/src + FILES + mpi/mpi.hpp + mpi/allgather.hpp + mpi/alltoall.hpp + mpi/barrier.hpp + mpi/commmode.hpp + mpi/handle.hpp + mpi/irecv.hpp + mpi/isend.hpp + mpi/recv.hpp + mpi/reduce.hpp + mpi/req.hpp + mpi/send.hpp + ) + + # Implementation detail MPI headers + target_sources( + KokkosComm + INTERFACE + FILE_SET kokkoscomm_mpi_impl_headers + TYPE HEADERS + BASE_DIRS ${PROJECT_SOURCE_DIR}/src + FILES mpi/impl/include_mpi.hpp mpi/impl/pack_traits.hpp mpi/impl/packer.hpp mpi/impl/tags.hpp mpi/impl/types.hpp + ) +endif() + +# --- COMPILE FLAGS --- # +include(CheckCXXCompilerFlag) + +macro(kokkoscomm_check_and_add_compile_options) + set(target ${ARGV0}) + set(flag ${ARGV1}) + + check_cxx_compiler_flag(${flag} HAS_${flag}) + if(HAS_${flag}) + target_compile_options(${target} INTERFACE ${flag}) + endif() +endmacro() + +# KokkosComm is a C++20 project +add_library(KokkosCommFlags INTERFACE) +add_library(KokkosComm::KokkosCommFlags ALIAS KokkosCommFlags) +target_compile_features(KokkosCommFlags INTERFACE cxx_std_20) +set_target_properties(KokkosCommFlags PROPERTIES CXX_EXTENSIONS OFF) + +kokkoscomm_check_and_add_compile_options(KokkosCommFlags -Wall) +kokkoscomm_check_and_add_compile_options(KokkosCommFlags -Wextra) +kokkoscomm_check_and_add_compile_options(KokkosCommFlags -Wshadow) +kokkoscomm_check_and_add_compile_options(KokkosCommFlags -Wpedantic) +kokkoscomm_check_and_add_compile_options(KokkosCommFlags -pedantic) +kokkoscomm_check_and_add_compile_options(KokkosCommFlags -Wcast-align) +kokkoscomm_check_and_add_compile_options(KokkosCommFlags -Wformat=2) +kokkoscomm_check_and_add_compile_options(KokkosCommFlags -Wmissing-include-dirs) +kokkoscomm_check_and_add_compile_options(KokkosCommFlags -Wno-gnu-zero-variadic-macro-arguments) + +# Linking +target_link_libraries(KokkosComm INTERFACE KokkosComm::KokkosCommFlags Kokkos::kokkos) +if(KOKKOSCOMM_ENABLE_MPI) + target_link_libraries(KokkosComm INTERFACE MPI::MPI_CXX) +endif() + +# Install library +install( + TARGETS KokkosComm KokkosCommFlags + EXPORT KokkosCommTargets + FILE_SET + kokkoscomm_public_headers + FILE_SET + kokkoscomm_impl_headers + FILE_SET + kokkoscomm_mpi_headers + FILE_SET + kokkoscomm_mpi_impl_headers + FILE_SET + kokkoscomm_config_headers +) diff --git a/src/KokkosComm/fwd.hpp b/src/KokkosComm/fwd.hpp index 0bd3c255..948227d4 100644 --- a/src/KokkosComm/fwd.hpp +++ b/src/KokkosComm/fwd.hpp @@ -19,7 +19,7 @@ #include #include "concepts.hpp" -#include "KokkosComm_config.hpp" +#include namespace KokkosComm { #if defined(KOKKOSCOMM_ENABLE_MPI) diff --git a/unit_tests/CMakeLists.txt b/unit_tests/CMakeLists.txt index 6a13c96f..1a4ae48c 100644 --- a/unit_tests/CMakeLists.txt +++ b/unit_tests/CMakeLists.txt @@ -1,62 +1,84 @@ -cmake_minimum_required(VERSION 3.12) # same as Kokkos Comm -project(KokkosCommUnitTests 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( + KokkosCommUnitTests + VERSION 0.2.0 + LANGUAGES + CXX + DESCRIPTION "Unit tests for the KokkosComm experimental communication interfaces" +) + enable_testing() # Treat the unit 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() FetchContent_Declare( googletest - URL https://github.com/google/googletest/archive/a7f443b80b105f940225332ed3c31f2790092f47.zip # 05-28-2024 + URL + https://github.com/google/googletest/archive/a7f443b80b105f940225332ed3c31f2790092f47.zip # 05-28-2024 ) # For Windows: Prevent overriding the parent project's compiler/linker settings set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) # FetchContent_MakeAvailable(googletest) was making install install googletest as well # EXCLUDE_FROM_ALL here seems to be the magic FetchContent_GetProperties(googletest) -if (NOT googletest_POPULATED) +if(NOT googletest_POPULATED) FetchContent_Populate(googletest) add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR} EXCLUDE_FROM_ALL) endif() -# Standalone MPI smoke tests (do not use KokkosComm) - - -# Kokkos Comm tests -set(KOKKOSCOMM_TEST_SOURCES) -list(APPEND KOKKOSCOMM_TEST_SOURCES test_main.cpp - test_sendrecv.cpp - test_barrier.cpp - -) if(KOKKOSCOMM_ENABLE_MPI) - - add_executable(test-mpi mpi/test_mpi.cpp) - add_test(NAME test-mpi-1 - COMMAND mpirun -np 1 ./test-mpi - ) - add_test(NAME test-mpi-2 - COMMAND mpirun -np 2 ./test-mpi - ) + # Standalone MPI smoke tests (do not use KokkosComm) + add_executable(test-mpi) + target_sources(test-mpi PRIVATE mpi/test_mpi.cpp) # doesn't use KokkosComm, so explicitly link MPI target_link_libraries(test-mpi MPI::MPI_CXX) + add_test( + NAME test-mpi-1 + COMMAND + ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} 1 ./test-mpi + ) + add_test( + NAME test-mpi-2 + COMMAND + ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} 2 ./test-mpi + ) +endif() - - list(PREPEND KOKKOSCOMM_TEST_SOURCES +# Tests using the MPI communication space, but not linking with MPI itself +add_executable(test-main) +target_sources( + test-main + PRIVATE + test_main.cpp mpi/test_gtest_mpi.cpp - ) - list(APPEND KOKKOSCOMM_TEST_SOURCES mpi/test_sendrecv.cpp mpi/test_allgather.cpp mpi/test_alltoall.cpp @@ -64,18 +86,15 @@ if(KOKKOSCOMM_ENABLE_MPI) mpi/test_alltoall.cpp mpi/test_reduce.cpp mpi/test_allgather.cpp - ) -endif() - add_executable(test-main ${KOKKOSCOMM_TEST_SOURCES} ) - -target_link_libraries(test-main KokkosComm::KokkosComm gtest) -if(KOKKOSCOMM_ENABLE_TESTS) - kokkoscomm_add_cxx_flags(TARGET test-main) -endif() - -add_test(NAME test-main - COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} 2 ./test-main +target_link_libraries( + test-main + PRIVATE + KokkosComm::KokkosComm + gtest +) +add_test( + NAME test-main + COMMAND + ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} 2 ./test-main ) - - diff --git a/unit_tests/test_main.cpp b/unit_tests/test_main.cpp index de3bd1ac..8292fad5 100644 --- a/unit_tests/test_main.cpp +++ b/unit_tests/test_main.cpp @@ -20,7 +20,7 @@ #include -#include +#include #include #include "KokkosComm/mpi/impl/include_mpi.hpp"