From 9823f6d3cc35cdff636c7d62a7df7b4c600d851e Mon Sep 17 00:00:00 2001 From: Georgiana Mania <mania@dkrz.de> Date: Mon, 24 Feb 2025 12:03:13 +0100 Subject: [PATCH 1/3] configure compilation for kokkos + nvidia --- CMakeLists.txt | 15 +++++++++++++++ src/horizontal/CMakeLists.txt | 3 ++- src/interpolation/CMakeLists.txt | 3 ++- src/support/CMakeLists.txt | 1 + 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7cf92be..8cbff2c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,6 +29,7 @@ option(IM_USE_CPP_BINDINGS "Use C++ bindings" OFF) option(IM_ENABLE_DIM_SWAP "Enable dimension swap" OFF) option(IM_ENABLE_OPENACC "Enable OpenACC support" OFF) option(IM_ENABLE_OPENMP "Enable OpenMP support" OFF) +set(IM_ENABLE_GPU OFF CACHE STRING "Enable Kokkos GPU support for arch. Valid values: OFF, nvidia-sm80") # GNUInstallDirs issues a warning if CMAKE_SIZEOF_VOID_P is not defined, which # is the case with NAG. One way to circumvent that is to enable C language for @@ -124,6 +125,20 @@ set(Kokkos_ENABLE_IMPL_MDSPAN OFF CACHE BOOL "Experimental mdspan support") set(Kokkos_ENABLE_SERIAL ON CACHE BOOL "Kokkos Serial backend") set(Kokkos_ARCH_NATIVE ON CACHE BOOL "Kokkos native architecture optimisations") +if ("${IM_ENABLE_GPU}" STREQUAL "nvidia-sm80") + # NVIDIA A100 + set(Kokkos_ENABLE_CUDA ON CACHE BOOL "Kokkos CUDA backend") + set(Kokkos_ARCH_AMPERE80 ON CACHE BOOL "CUDA architecture: Ampere cc80") +else() + message( + FATAL_ERROR + "Kokkos GPU support not enabled for architecture: ${IM_ENABLE_GPU}") +endif() + +if (${IM_ENABLE_OPENMP}) + set(Kokkos_ENABLE_OPENMP ON CACHE BOOL "Kokkos OpenMP backend") +endif() + FetchContent_MakeAvailable(kokkos) add_subdirectory(src) diff --git a/src/horizontal/CMakeLists.txt b/src/horizontal/CMakeLists.txt index 6cebed9..d2abe7d 100644 --- a/src/horizontal/CMakeLists.txt +++ b/src/horizontal/CMakeLists.txt @@ -66,7 +66,8 @@ target_include_directories( target_link_libraries(iconmath-horizontal PUBLIC fortran-support::fortran-support) target_link_libraries(iconmath-horizontal PUBLIC iconmath-support) target_link_libraries(iconmath-horizontal PUBLIC iconmath-interpolation) -target_link_libraries(iconmath-interpolation PRIVATE Kokkos::kokkos) +target_link_libraries(iconmath-horizontal PRIVATE Kokkos::kokkos) +set_target_properties(iconmath-horizontal PROPERTIES LINKER_LANGUAGE Fortran) install(TARGETS iconmath-horizontal EXPORT "${PROJECT_NAME}-targets") diff --git a/src/interpolation/CMakeLists.txt b/src/interpolation/CMakeLists.txt index 9455f9e..a3e6426 100644 --- a/src/interpolation/CMakeLists.txt +++ b/src/interpolation/CMakeLists.txt @@ -69,7 +69,8 @@ target_include_directories( target_link_libraries(iconmath-interpolation PUBLIC fortran-support::fortran-support) target_link_libraries(iconmath-interpolation PUBLIC iconmath-support) -target_link_libraries(iconmath-interpolation PRIVATE Kokkos::kokkos) +target_link_libraries(iconmath-interpolation PRIVATE Kokkos::kokkos) +set_target_properties(iconmath-interpolation PROPERTIES LINKER_LANGUAGE Fortran) install(TARGETS iconmath-interpolation EXPORT "${PROJECT_NAME}-targets") diff --git a/src/support/CMakeLists.txt b/src/support/CMakeLists.txt index 9f56017..ed6a4d3 100644 --- a/src/support/CMakeLists.txt +++ b/src/support/CMakeLists.txt @@ -80,6 +80,7 @@ target_link_libraries(iconmath-support PRIVATE Kokkos::kokkos ) +set_target_properties(iconmath-support PROPERTIES LINKER_LANGUAGE Fortran) install(TARGETS iconmath-support EXPORT "${PROJECT_NAME}-targets") -- GitLab From c30654e895c59a72e5de1dcf473f2f5ce87b0840 Mon Sep 17 00:00:00 2001 From: Georgiana Mania <mania@dkrz.de> Date: Mon, 24 Feb 2025 13:12:01 +0100 Subject: [PATCH 2/3] fix cmake format --- CMakeLists.txt | 10 +++++----- src/interpolation/CMakeLists.txt | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8cbff2c..5e14b8b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -126,17 +126,17 @@ set(Kokkos_ENABLE_SERIAL ON CACHE BOOL "Kokkos Serial backend") set(Kokkos_ARCH_NATIVE ON CACHE BOOL "Kokkos native architecture optimisations") if ("${IM_ENABLE_GPU}" STREQUAL "nvidia-sm80") - # NVIDIA A100 - set(Kokkos_ENABLE_CUDA ON CACHE BOOL "Kokkos CUDA backend") - set(Kokkos_ARCH_AMPERE80 ON CACHE BOOL "CUDA architecture: Ampere cc80") + # NVIDIA A100 + set(Kokkos_ENABLE_CUDA ON CACHE BOOL "Kokkos CUDA backend") + set(Kokkos_ARCH_AMPERE80 ON CACHE BOOL "CUDA architecture: Ampere cc80") else() - message( + message( FATAL_ERROR "Kokkos GPU support not enabled for architecture: ${IM_ENABLE_GPU}") endif() if (${IM_ENABLE_OPENMP}) - set(Kokkos_ENABLE_OPENMP ON CACHE BOOL "Kokkos OpenMP backend") + set(Kokkos_ENABLE_OPENMP ON CACHE BOOL "Kokkos OpenMP backend") endif() FetchContent_MakeAvailable(kokkos) diff --git a/src/interpolation/CMakeLists.txt b/src/interpolation/CMakeLists.txt index a3e6426..346aaaa 100644 --- a/src/interpolation/CMakeLists.txt +++ b/src/interpolation/CMakeLists.txt @@ -69,7 +69,7 @@ target_include_directories( target_link_libraries(iconmath-interpolation PUBLIC fortran-support::fortran-support) target_link_libraries(iconmath-interpolation PUBLIC iconmath-support) -target_link_libraries(iconmath-interpolation PRIVATE Kokkos::kokkos) +target_link_libraries(iconmath-interpolation PRIVATE Kokkos::kokkos) set_target_properties(iconmath-interpolation PROPERTIES LINKER_LANGUAGE Fortran) install(TARGETS iconmath-interpolation EXPORT "${PROJECT_NAME}-targets") -- GitLab From 3efb963c4f98b629d09868423397d97f656f0fbd Mon Sep 17 00:00:00 2001 From: Georgiana Mania <mania@dkrz.de> Date: Mon, 24 Feb 2025 13:15:12 +0100 Subject: [PATCH 3/3] remove cmake message --- CMakeLists.txt | 4 ---- 1 file changed, 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5e14b8b..affedaa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -129,10 +129,6 @@ if ("${IM_ENABLE_GPU}" STREQUAL "nvidia-sm80") # NVIDIA A100 set(Kokkos_ENABLE_CUDA ON CACHE BOOL "Kokkos CUDA backend") set(Kokkos_ARCH_AMPERE80 ON CACHE BOOL "CUDA architecture: Ampere cc80") -else() - message( - FATAL_ERROR - "Kokkos GPU support not enabled for architecture: ${IM_ENABLE_GPU}") endif() if (${IM_ENABLE_OPENMP}) -- GitLab