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

Improve cmake #47

Merged
merged 3 commits into from
Feb 12, 2024
Merged

Improve cmake #47

merged 3 commits into from
Feb 12, 2024

Conversation

yasahi-hpc
Copy link
Collaborator

Resolves #32

In this PR, we add the version check of Kokkos when building against a pre-installed Kokkos library.
Following functionalities are added.

  1. Kokkos version check
  2. KokkosFFT git version check
  3. verbose git version in benchmark
  4. verbose KokkosFFT in CMake build

@yasahi-hpc
Copy link
Collaborator Author

@cedricchevalier19 Hello, could you please review this PR?

CMakeLists.txt Outdated
KokkosFFT
VERSION 0.0.0.0
LANGUAGES CXX
)

# Add cmake helpers for FFTW
list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can simply:

list(PREPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

CMakeLists.txt Outdated
if (NOT KokkosFFT_INTERNAL_Kokkos)
# First check, Kokkos is added as subdirectory or not
if(NOT TARGET Kokkos::kokkos)
find_package(Kokkos REQUIRED)
# Kokkos version check
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Kokkos_Version_Check.cmake)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since you update CMAKE_CURRENT_SOURCE_DIR, you don't need to specify the absolute path anymore and can simply do:

include(Kokkos_Version_Check)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Do they work in both KokkosFFT as library and KokkosFFT as subdirectory cases?

Copy link
Collaborator

@pzehner pzehner Feb 12, 2024

Choose a reason for hiding this comment

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

This file is not included in the installation of Kokkos FFT, or is it?

Moreover, if you need a specific version of Kokkos, you should pass it as REQUIRED in find_package (if this is possible, see @cedricchevalier19 comment).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

For build based on pre-installed Kokkos, this is included.

Moreover, if you need a specific version of Kokkos, you should pass it as REQUIRED in find_package (if this is possible, see @cedricchevalier19 comment).

As commented, I would like custom error messages.

CMakeLists.txt Outdated
if (NOT KokkosFFT_INTERNAL_Kokkos)
# First check, Kokkos is added as subdirectory or not
if(NOT TARGET Kokkos::kokkos)
find_package(Kokkos REQUIRED)
# Kokkos version check
Copy link
Collaborator

@pzehner pzehner Feb 12, 2024

Choose a reason for hiding this comment

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

Maybe the Kokkos version check should be done unconditionally. I know it's unlikely that the embedded version comes outdated, but I think it doesn't hurt to have a straightforward approach.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Is there a way to access internal CMake variables in Kokkos CMake?

Copy link
Member

Choose a reason for hiding this comment

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

find_package can check for version directly no ?

Copy link
Collaborator Author

@yasahi-hpc yasahi-hpc Feb 12, 2024

Choose a reason for hiding this comment

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

If we rely on a pre-installed Kokkos yes. I am not sure how can I retrieve information from Kokkos added as a subdirectory. I added a specific function for finer error messages

Copy link
Collaborator

Choose a reason for hiding this comment

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

I tested it with the sub-directory way and could access Kokkos_VERSION.

Copy link
Collaborator Author

@yasahi-hpc yasahi-hpc Feb 12, 2024

Choose a reason for hiding this comment

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

So, it would work except for using Kokkos as subdirectory of this KokkosFFT?

CMakeLists.txt Outdated
@@ -44,6 +51,7 @@ endif()
if(KokkosFFT_ENABLE_BENCHMARK)
option(BENCHMARK_ENABLE_TESTING "Enable testing of the benchmark library." OFF)
add_subdirectory(tpls/benchmark)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/KokkosFFT_Git_Hash.cmake)
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can do:

include(KokkosFFT_Git_Hash)

CMakeLists.txt Outdated
@@ -60,6 +68,11 @@ set(
KokkosFFT_Version_Info.hpp
)

# Set tpls
set(KOKKOSFFT_TPL_LIST)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/KokkosFFT_tpls.cmake)
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can do:

include(KokkosFFT_tpls)

Copy link
Member

@cedricchevalier19 cedricchevalier19 left a comment

Choose a reason for hiding this comment

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

Just a quick review.

CMakeLists.txt Outdated
Comment on lines 23 to 25
math(EXPR KOKKOSFFT_VERSION_MAJOR "${KOKKOSFFT_VERSION} / 10000")
math(EXPR KOKKOSFFT_VERSION_MINOR "${KOKKOSFFT_VERSION} / 100 % 100")
math(EXPR KOKKOSFFT_VERSION_PATCH "${KOKKOSFFT_VERSION} % 100")
Copy link
Member

Choose a reason for hiding this comment

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

Please remove this, just alias to PROJECT_VERSION_* if it is not already done by CMake.

Copy link
Collaborator Author

@yasahi-hpc yasahi-hpc Feb 12, 2024

Choose a reason for hiding this comment

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

The question is that Kokkos versioning has numbers like "4.2.00" which seems to me PROJECT_VERSION_MAJOR. PROJECT_VERSION_MINOR.PROJECT_VERSION_PATCH.PROJECT_VERSION_TWEAK.

At the same time, it is reduced into "4.2.0" for version comparison. If we simply control PROJECT_VERSION_MAJOR. PROJECT_VERSION_MINOR.PROJECT_VERSION_PATCH, we can just alias version variables to these

CMakeLists.txt Outdated
if (NOT KokkosFFT_INTERNAL_Kokkos)
# First check, Kokkos is added as subdirectory or not
if(NOT TARGET Kokkos::kokkos)
find_package(Kokkos REQUIRED)
# Kokkos version check
Copy link
Member

Choose a reason for hiding this comment

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

find_package can check for version directly no ?

Copy link
Member

Choose a reason for hiding this comment

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

Is this really useful? It is quite a lot of code for something that does not bring any feature.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It gives the git version in benchmark which should be important.

CMakeLists.txt Outdated
Comment on lines 100 to 102
message("")
message("-- KokkosFFT version: ${KOKKOSFFT_VERSION_MAJOR}.${KOKKOSFFT_VERSION_MINOR}.${KOKKOSFFT_VERSION_PATCH}")
message("-- KokkosFFT TPLs")
Copy link
Collaborator

@pzehner pzehner Feb 12, 2024

Choose a reason for hiding this comment

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

The -- prefix is rendered by using the STATUS mode (see message documentation):

message(STATUS "KokkosFFT version: ${KOKKOSFFT_VERSION_MAJOR}.${KOKKOSFFT_VERSION_MINOR}.${KOKKOSFFT_VERSION_PATCH}")
message(STATUS "KokkosFFT TPLs")

@@ -0,0 +1,27 @@
function(get_tpls_list tpls_list)
Copy link
Collaborator

Choose a reason for hiding this comment

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

You should add a documentation in the header to describe what this function does.

@@ -0,0 +1,11 @@
function(check_minimum_required_kokkos kokkos_required_version)
Copy link
Collaborator

Choose a reason for hiding this comment

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

You should add a documentation in the header to describe what this function does.

CMakeLists.txt Outdated
Comment on lines 22 to 25
math(EXPR KOKKOSFFT_VERSION "${PROJECT_VERSION_MAJOR} * 10000 + ${PROJECT_VERSION_MINOR} * 100 + ${PROJECT_VERSION_PATCH} * 10 + ${PROJECT_VERSION_TWEAK}")
math(EXPR KOKKOSFFT_VERSION_MAJOR "${KOKKOSFFT_VERSION} / 10000")
math(EXPR KOKKOSFFT_VERSION_MINOR "${KOKKOSFFT_VERSION} / 100 % 100")
math(EXPR KOKKOSFFT_VERSION_PATCH "${KOKKOSFFT_VERSION} % 100")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do you really need to do that? You can use advantage of the standard version variables:

set(KOKKOSFFT_VERSION "${PROJECT_VERSION}")
set(KOKKOSFFT_VERSION_MAJOR "${PROJECT_VERSION_MAJOR}")
set(KOKKOSFFT_VERSION_MINOR "${PROJECT_VERSION_MINOR}")
set(KOKKOSFFT_VERSION_PATCH "${PROJECT_VERSION_PATCH}")

Also, you specified a semver with tweak version (as of 0.0.0.0), and don't use it here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have never used tweak version, but Kokkos version seems to have that. #47 (comment)

The easiest solution is removing the tweak version.

CMakeLists.txt Outdated
# CMake Summary
# ==================================================================

message("")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Empty lines in CMake output is not common, in my experience.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is to distinguish the summaries from Kokkos and KokkosFFT as shown.

-- Setting default Kokkos CXX standard to 17
-- Kokkos version: 4.2.0
-- The project name is: Kokkos
-- Using internal gtest for testing
-- Configured git information in /home/i18048/jh220031a/github/benchmark/github/kokkos-fft/build/generated/Kokkos_Version_Info.cpp
-- Using -std=gnu++17 for C++17 extensions as feature
-- Built-in Execution Spaces:
--     Device Parallel: NoTypeDefined
--     Host Parallel: Kokkos::OpenMP
--       Host Serial: NONE
-- 
-- Architectures:
--  SKX
-- Using internal desul_atomics copy
-- Kokkos Devices: OPENMP, Kokkos Backends: OPENMP

-- KokkosFFT version: 0.0.0
-- KokkosFFT TPLs
   FFTW_OPENMP

CMakeLists.txt Outdated
else()
message(" (None)")
endif()
message("")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Empty lines in CMake output is not common, in my experience.

CMakeLists.txt Outdated
if(KOKKOSFFT_TPL_LIST)
foreach(TPL ${KOKKOSFFT_TPL_LIST})
# [TO DO] show more information about the library (like location)
message(" ${TPL}")
Copy link
Collaborator

Choose a reason for hiding this comment

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

message(STATUS "   ${TPL}")

CMakeLists.txt Outdated
message(" ${TPL}")
endforeach()
else()
message(" (None)")
Copy link
Collaborator

Choose a reason for hiding this comment

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

message(STATUS "   (None)")

@yasahi-hpc
Copy link
Collaborator Author

@cedricchevalier19 @pzehner

Thank you for the reviews. I have fixed based on your reviews. I will merge this PR if you are fine.

@yasahi-hpc yasahi-hpc merged commit caf52c1 into main Feb 12, 2024
16 checks passed
@yasahi-hpc yasahi-hpc deleted the improve-cmake branch February 12, 2024 13:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Kokkos version check
3 participants