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

Fixing External Include of Build Directory #1532

Merged
merged 5 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -730,19 +730,6 @@ subdir-build:
CI_PROJECT_PATH_SUFFIX: "/test_subdir"
allow_failure: no

# Ensure Ginkgo can be used when exporting the build directory
export-build:
stage: code_quality
extends:
- .build_template
- .default_variables
- .full_test_condition
- .use_gko-nocuda-nompi-gnu9-llvm8
variables:
BUILD_OMP: "ON"
EXPORT_BUILD_DIR: "ON"
allow_failure: no

# Run clang-tidy and iwyu
clang-tidy:
stage: code_quality
Expand Down
8 changes: 3 additions & 5 deletions .gitlab/scripts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,8 @@
-DGINKGO_RUN_EXAMPLES=${RUN_EXAMPLES}
-DGINKGO_CONFIG_LOG_DETAILED=${CONFIG_LOG}
-DGINKGO_DPCPP_SINGLE_MODE=${DPCPP_SINGLE_MODE}
-DGINKGO_EXPORT_BUILD_DIR=${EXPORT_BUILD_DIR}
- ninja -j${NUM_CORES} -l${CI_LOAD_LIMIT} install
- awk '!/^#/ { print ($2 - $1)/1000 " " $4 }' .ninja_log | sort -nr
- if [ "${EXPORT_BUILD_DIR}" == "ON" ]; then ninja test_exportbuild; fi
- LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH ninja test_pkgconfig
dependencies: []

.build_and_test_template:
Expand Down Expand Up @@ -95,12 +92,12 @@
-DGINKGO_CONFIG_LOG_DETAILED=${CONFIG_LOG}
-DGINKGO_DPCPP_SINGLE_MODE=${DPCPP_SINGLE_MODE}
-DGINKGO_RUN_EXAMPLES=${RUN_EXAMPLES}
-DGINKGO_EXPORT_BUILD_DIR=${EXPORT_BUILD_DIR}
- ninja -j${NUM_CORES} -l${CI_LOAD_LIMIT} install
- awk '!/^#/ { print ($2 - $1)/1000 " " $4 }' .ninja_log | sort -nr
- |
(( $(ctest -N | tail -1 | sed 's/Total Tests: //') != 0 )) || exit 1
- ctest --output-on-failure --timeout 6000 ${CTEST_EXTRA_ARGS}
- ninja test_exportbuild
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to ensure it still works after installation?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that should not be necessary. The export test is only allowed to use the *_ROOT to find ginkgo, so the previous install should have no effect.
I would still keep this test before to prevent the current situation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Side-note: The reason we do ninja install directly in the beginning is that the HIP compilation doesn't create (or didn't used to create) the correct depfiles or something like that on the first pass, so calling ninja and then ninja install caused the HIP objects to be rebuilt. If we tackle #1334, that is no longer an issue and we can separate between ninja and ninja install again

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH, I think we should push the CMake update for HIP, even if that would mean to drop support for rocm < 5.0.1. I don't think it's even possible to find the documentation for rocm 4.5 from visiting amd.com, so it seems to me that these versions are not really supported anymore.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for the issue that hip needs built twice, we can just run ninja && ninja if we do not want ninja install rebuilds the stuff.
I do not think the two build is a big issue.
Dropping the support rocm < 5.0.1 is not the main issue from updating cmake for HIP.
Updating cmake for hip means we drops the nvidia support of hip. In my mind, the new cmake is not completed yet because they claim they can do that on both architectures. Also, recovering the support after deleting is harder than keeping the current one.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an issue of build time, our HIP builds (especially debug) are extremely slow, we don't want to build the binaries twice. It seems to me like the old hip_add_* approach hasn't been mentioned in their documentation in a long time, on top of all its downsides I also do not want to keep relying on it. We have full CUDA support via our CUDA backend, to me there are no technical reasons to keep this around, as HIP is just a thin layer over CUDA anyways.

- ninja test_install
- pushd test/test_install
- ninja install
Expand Down Expand Up @@ -128,7 +125,6 @@
fi
- if [ -n "${SYCL_DEVICE_TYPE}" ]; then unset SYCL_DEVICE_TYPE; fi
- if [ -n "${SYCL_DEVICE_FILTER}" ]; then unset SYCL_DEVICE_FILTER; fi
- if [ "${EXPORT_BUILD_DIR}" == "ON" ]; then ninja test_exportbuild; fi
- LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH ninja test_pkgconfig
dependencies: []

Expand All @@ -153,10 +149,12 @@
- |
(( $(ctest -N | tail -1 | sed 's/Total Tests: //') != 0 )) || exit 1
- ctest --output-on-failure --timeout 6000 ${CTEST_EXTRA_ARGS}
- ninja test_exportbuild
- ninja test_install
- pushd test/test_install
- ninja install
- popd
- LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH ninja test_pkgconfig
cache: []


Expand Down
1 change: 0 additions & 1 deletion .gitlab/variables.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,4 @@
CONFIG_LOG: "ON"
CXX_FLAGS: ""
EXTRA_CMAKE_FLAGS: ""
EXPORT_BUILD_DIR: "OFF"
CI_PROJECT_DIR_SUFFIX: ""
11 changes: 3 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ option(GINKGO_TEST_NONDEFAULT_STREAM "Uses non-default streams in CUDA and HIP t
option(GINKGO_MIXED_PRECISION "Instantiate true mixed-precision kernels (otherwise they will be conversion-based using implicit temporary storage)" OFF)
option(GINKGO_SKIP_DEPENDENCY_UPDATE
"Do not update dependencies each time the project is rebuilt" ON)
option(GINKGO_EXPORT_BUILD_DIR
"Make Ginkgo export its build directory to the CMake package registry."
OFF)
option(GINKGO_WITH_CLANG_TIDY "Make Ginkgo call `clang-tidy` to find programming issues." OFF)
option(GINKGO_WITH_IWYU "Make Ginkgo call `iwyu` (Include What You Use) to find include issues." OFF)
option(GINKGO_WITH_CCACHE "Use ccache if available to speed up C++ and CUDA rebuilds by caching compilations." ON)
Expand Down Expand Up @@ -450,6 +447,7 @@ ginkgo_modify_flags(CMAKE_CUDA_FLAGS)
ginkgo_modify_flags(CMAKE_CUDA_FLAGS_DEBUG)
ginkgo_modify_flags(CMAKE_CUDA_FLAGS_RELEASE)
ginkgo_install()
ginkgo_export_binary_dir()

set(GINKGO_TEST_INSTALL_SRC_DIR "${Ginkgo_SOURCE_DIR}/test/test_install/")
set(GINKGO_TEST_INSTALL_BIN_DIR "${Ginkgo_BINARY_DIR}/test/test_install/")
Expand Down Expand Up @@ -483,7 +481,6 @@ add_custom_target(test_install
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_PREFIX_PATH=${CMAKE_INSTALL_PREFIX}
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DCMAKE_CUDA_COMPILER=${CMAKE_CUDA_COMPILER}
-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
# `--config cfg` is ignored by single-configuration generator.
Expand All @@ -504,25 +501,23 @@ add_custom_target(test_exportbuild
-S${GINKGO_TEST_EXPORTBUILD_SRC_DIR}
-B${GINKGO_TEST_EXPORTBUILD_BIN_DIR}
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DCMAKE_CUDA_COMPILER=${CMAKE_CUDA_COMPILER}
-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
-DGinkgo_ROOT=${Ginkgo_BINARY_DIR}
# `--config cfg` is ignored by single-configuration generator.
# `$<CONFIG>` is always be the same as `CMAKE_BUILD_TYPE` in
# single-configuration generator.
COMMAND ${CMAKE_COMMAND}
--build ${GINKGO_TEST_EXPORTBUILD_BIN_DIR}
--config $<CONFIG>
COMMAND ${GINKGO_TEST_EXPORTBUILD_CMD}
COMMENT "Running a test on Ginkgo's exported build directory. "
"This requires compiling Ginkgo with `-DGINKGO_EXPORT_BUILD_DIR=ON` first.")
COMMENT "Running a test on Ginkgo's exported build directory.")

add_custom_target(test_pkgconfig
COMMAND ${CMAKE_COMMAND} -G${CMAKE_GENERATOR} ${TOOLSET}
-S${GINKGO_TEST_PKGCONFIG_SRC_DIR}
-B${GINKGO_TEST_PKGCONFIG_BIN_DIR}
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DCMAKE_CUDA_COMPILER=${CMAKE_CUDA_COMPILER}
-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
# `--config cfg` is ignored by single-configuration generator.
Expand Down
12 changes: 7 additions & 5 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ Use the standard CMake build procedure:

```sh
mkdir build; cd build
cmake -G "Unix Makefiles" [OPTIONS] .. && make
cmake [OPTIONS] .. && cmake --build .
```
Use `cmake --build .` in some systems like MinGW or Microsoft Visual Studio which do not use `make`.

For Microsoft Visual Studio, use `cmake --build . --config <build_type>` to decide the build type. The possible options are `Debug`, `Release`, `RelWithDebInfo` and `MinSizeRel`.

Expand Down Expand Up @@ -63,8 +62,6 @@ Ginkgo adds the following additional switches to control what is being built:
documentation from inline comments in the code. The default is `OFF`.
* `-DGINKGO_DOC_GENERATE_DEV={ON, OFF}` generates the developer version of
Ginkgo's documentation. The default is `OFF`.
* `-DGINKGO_EXPORT_BUILD_DIR={ON, OFF}` adds the Ginkgo build directory to the
CMake package registry. The default is `OFF`.
* `-DGINKGO_WITH_CLANG_TIDY={ON, OFF}` makes Ginkgo call `clang-tidy` to find
programming issues. The path can be manually controlled with the CMake
variable `-DGINKGO_CLANG_TIDY_PATH=<path>`. The default is `OFF`.
Expand Down Expand Up @@ -122,10 +119,15 @@ Ginkgo adds the following additional switches to control what is being built:
[`ARCHITECTURES` specification list](https://github.com/ginkgo-project/CudaArchitectureSelector/blob/master/CudaArchitectureSelector.cmake#L58)
section in the documentation of the CudaArchitectureSelector CMake module.

Additionally, the following CMake options have effect on the build process:

* `-DCMAKE_EXPORT_PACKAGE_REGISTRY={ON,OFF}` if set to `ON` the build directory will
be stored in the current user's CMake package registry.

For example, to build everything (in debug mode), use:

```cmake
cmake -G "Unix Makefiles" -H. -BDebug -DCMAKE_BUILD_TYPE=Debug -DGINKGO_DEVEL_TOOLS=ON \
cmake .. -BDebug -DCMAKE_BUILD_TYPE=Debug -DGINKGO_DEVEL_TOOLS=ON \
-DGINKGO_BUILD_TESTS=ON -DGINKGO_BUILD_REFERENCE=ON -DGINKGO_BUILD_OMP=ON \
-DGINKGO_BUILD_CUDA=ON -DGINKGO_BUILD_HIP=ON
cmake --build Debug
Expand Down
26 changes: 15 additions & 11 deletions cmake/GinkgoConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ set(GINKGO_DOC_GENERATE_PDF @GINKGO_DOC_GENERATE_PDF@)
set(GINKGO_DOC_GENERATE_DEV @GINKGO_DOC_GENERATE_DEV@)

set(GINKGO_SKIP_DEPENDENCY_UPDATE @GINKGO_SKIP_DEPENDENCY_UPDATE@)
set(GINKGO_EXPORT_BUILD_DIR @GINKGO_EXPORT_BUILD_DIR@)
set(GINKGO_VERBOSE_LEVEL @GINKGO_VERBOSE_LEVEL@)

set(GINKGO_WITH_CLANG_TIDY @GINKGO_WITH_CLANG_TIDY@)
Expand Down Expand Up @@ -98,20 +97,23 @@ set(GINKGO_CUDA_HOST_COMPILER "@CMAKE_CUDA_HOST_COMPILER@")
set(GINKGO_CUDA_HOST_COMPILER_SHORT "") # dummy value to stay consistent

# Ginkgo installation configuration
set(GINKGO_INSTALL_PREFIX "@PACKAGE_CMAKE_INSTALL_PREFIX@")
set(GINKGO_INSTALL_INCLUDE_DIR "@PACKAGE_CMAKE_INSTALL_FULL_INCLUDEDIR@")
set(GINKGO_INSTALL_LIBRARY_DIR "@PACKAGE_CMAKE_INSTALL_FULL_LIBDIR@")
set(GINKGO_INSTALL_RPATH_FOR_HIP "-Wl,-rpath,${GINKGO_INSTALL_LIBRARY_DIR}")
set(GINKGO_INSTALL_RPATH @GINKGO_INSTALL_RPATH@)
set(GINKGO_INSTALL_RPATH_USE_ORIGIN @GINKGO_INSTALL_RPATH_USE_ORIGIN@)
set(GINKGO_INSTALL_RPATH_DEPENDENCIES @GINKGO_INSTALL_RPATH_DEPENDENCIES@)
set(GINKGO_EXPORT_BINARY_DIR "@GINKGO_EXPORT_BINARY_DIR@")
if(NOT GINKGO_EXPORT_BINARY_DIR)
set_and_check(GINKGO_INSTALL_PREFIX "@PACKAGE_CMAKE_INSTALL_PREFIX@")
set_and_check(GINKGO_INSTALL_INCLUDE_DIR "@PACKAGE_CMAKE_INSTALL_FULL_INCLUDEDIR@")
set_and_check(GINKGO_INSTALL_LIBRARY_DIR "@PACKAGE_CMAKE_INSTALL_FULL_LIBDIR@")
set(GINKGO_INSTALL_RPATH_FOR_HIP "-Wl,-rpath,${GINKGO_INSTALL_LIBRARY_DIR}")
set(GINKGO_INSTALL_RPATH @GINKGO_INSTALL_RPATH@)
set(GINKGO_INSTALL_RPATH_USE_ORIGIN @GINKGO_INSTALL_RPATH_USE_ORIGIN@)
set(GINKGO_INSTALL_RPATH_DEPENDENCIES @GINKGO_INSTALL_RPATH_DEPENDENCIES@)
endif()

# Forward Ginkgo's MODULE PATH and the PREFIX PATH for HIP and more
list(APPEND CMAKE_MODULE_PATH "@PACKAGE_GINKGO_INSTALL_MODULE_DIR@")
set_and_check(GINKGO_INSTALL_MODULE_DIR "@PACKAGE_GINKGO_INSTALL_MODULE_DIR@")
list(APPEND CMAKE_MODULE_PATH "${GINKGO_INSTALL_MODULE_DIR}")
if(GINKGO_BUILD_HIP)
list(APPEND CMAKE_MODULE_PATH "@GINKGO_HIP_MODULE_PATH@")
endif()
list(APPEND CMAKE_PREFIX_PATH "${GINKGO_INSTALL_PREFIX}")

set(GINKGO_INTERFACE_LINK_LIBRARIES "@GINKGO_INTERFACE_LINK_LIBRARIES@")
set(GINKGO_INTERFACE_LINK_FLAGS "@GINKGO_INTERFACE_LINK_FLAGS@")
Expand All @@ -137,7 +139,7 @@ set(GINKGO_OPENMP_FLAGS "@OpenMP_CXX_FLAGS@")
set(GINKGO_HAVE_TAU "@GINKGO_HAVE_TAU@")
set(GINKGO_HAVE_VTUNE "@GINKGO_HAVE_VTUNE@")
set(GINKGO_HAVE_METIS "@GINKGO_HAVE_METIS@")
set(VTune_PATH "@VTune_PATH@")
set_and_check(VTune_PATH "@VTune_PATH@")

# ensure Threads settings
set(THREADS_PREFER_PTHREAD_FLAG ON)
Expand Down Expand Up @@ -218,3 +220,5 @@ if(GINKGO_BUILD_CUDA)
endif()

include(${CMAKE_CURRENT_LIST_DIR}/GinkgoTargets.cmake)

check_required_components(Ginkgo)
44 changes: 35 additions & 9 deletions cmake/install_helpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -102,21 +102,23 @@ function(ginkgo_install)
FILES_MATCHING PATTERN "*.cmake"
)

set(GINKGO_EXPORT_BINARY_DIR OFF)

# export configuration file for importing
write_basic_package_version_file(
"${Ginkgo_BINARY_DIR}/GinkgoConfigVersion.cmake"
"${Ginkgo_BINARY_DIR}/cmake/GinkgoConfigVersion.cmake"
VERSION "${PROJECT_VERSION}"
COMPATIBILITY SameMajorVersion
)
configure_package_config_file(
"${Ginkgo_SOURCE_DIR}/cmake/GinkgoConfig.cmake.in"
"${Ginkgo_BINARY_DIR}/GinkgoConfig.cmake"
"${Ginkgo_BINARY_DIR}/cmake/GinkgoConfig.cmake"
INSTALL_DESTINATION "${GINKGO_INSTALL_CONFIG_DIR}"
PATH_VARS CMAKE_INSTALL_FULL_INCLUDEDIR CMAKE_INSTALL_FULL_LIBDIR CMAKE_INSTALL_PREFIX GINKGO_INSTALL_MODULE_DIR
)
install(FILES
"${Ginkgo_BINARY_DIR}/GinkgoConfig.cmake"
"${Ginkgo_BINARY_DIR}/GinkgoConfigVersion.cmake"
"${Ginkgo_BINARY_DIR}/cmake/GinkgoConfig.cmake"
"${Ginkgo_BINARY_DIR}/cmake/GinkgoConfigVersion.cmake"
DESTINATION "${GINKGO_INSTALL_CONFIG_DIR}"
COMPONENT Ginkgo_Development)
install(EXPORT Ginkgo
Expand All @@ -125,11 +127,6 @@ function(ginkgo_install)
DESTINATION "${GINKGO_INSTALL_CONFIG_DIR}"
COMPONENT Ginkgo_Development)

# Export package for use from the build tree
if (GINKGO_EXPORT_BUILD_DIR)
export(PACKAGE Ginkgo)
endif()

if (CMAKE_SYSTEM_NAME STREQUAL "Linux" AND BUILD_SHARED_LIBS)
install(FILES
"${Ginkgo_SOURCE_DIR}/dev_tools/scripts/gdb-ginkgo.py"
Expand All @@ -138,3 +135,32 @@ function(ginkgo_install)
COMPONENT Ginkgo_Development)
endif()
endfunction()


function(ginkgo_export_binary_dir)
# export targets
export(EXPORT Ginkgo
NAMESPACE Ginkgo::
FILE "${Ginkgo_BINARY_DIR}/GinkgoTargets.cmake"
)

set(GINKGO_EXPORT_BINARY_DIR ON)
set(GINKGO_INSTALL_MODULE_DIR "${Ginkgo_SOURCE_DIR}/cmake/Modules/")

# export configuration file for importing
write_basic_package_version_file(
"${Ginkgo_BINARY_DIR}/GinkgoConfigVersion.cmake"
VERSION "${PROJECT_VERSION}"
COMPATIBILITY SameMajorVersion
)
configure_package_config_file(
"${Ginkgo_SOURCE_DIR}/cmake/GinkgoConfig.cmake.in"
"${Ginkgo_BINARY_DIR}/GinkgoConfig.cmake"
INSTALL_DESTINATION "${GINKGO_INSTALL_CONFIG_DIR}"
PATH_VARS GINKGO_INSTALL_MODULE_DIR
INSTALL_PREFIX ${Ginkgo_BINARY_DIR}
)

# Export package for use from the build tree
export(PACKAGE Ginkgo)
endfunction()
3 changes: 2 additions & 1 deletion test/test_exportbuild/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
cmake_minimum_required(VERSION 3.16)
project(GinkgoExportBuildTest LANGUAGES CXX)

find_package(Ginkgo REQUIRED)
find_package(Ginkgo REQUIRED
ONLY_CMAKE_FIND_ROOT_PATH)

# Here, we use test install without any data. We instantiate the
# interface only.
Expand Down
Loading