Skip to content

Commit 5ce36f9

Browse files
cmake cleanup (#145)
* Change the default FetchContent behavior to search first * fix compilation with openblas * use a tagged version of costa in FetchContent * fix build cosma ~scalapack * remove language C * fix name in CI * update tiled-mm tag
1 parent 3e06ce2 commit 5ce36f9

File tree

5 files changed

+113
-116
lines changed

5 files changed

+113
-116
lines changed

CMakeLists.txt

Lines changed: 79 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
cmake_minimum_required(VERSION 3.17 FATAL_ERROR)
1+
cmake_minimum_required(VERSION 3.24 FATAL_ERROR)
22

33
project(cosma
44
DESCRIPTION "Communication Optimal Matrix Multiplication"
55
HOMEPAGE_URL "https://github.com/eth-cscs/COSMA"
66
VERSION 2.6.6
77
LANGUAGES CXX)
88

9+
include(FetchContent)
910

1011
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
1112
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
1213
include(cmake/build_type.cmake)
1314
include(cmake/adjust_mpiexec_flags.cmake)
14-
include(GitSubmodule)
1515
set(CMAKE_EXPORT_COMPILE_COMMANDS "YES") # always write compile_commands.json
1616

1717
# Options
@@ -41,31 +41,37 @@ set_property(CACHE COSMA_BLAS PROPERTY STRINGS ${COSMA_BLAS_LIST})
4141
# implementation. We have to sort out what we should find for the FindBLAS and
4242
# GPU supports since they are treated as separate components
4343

44+
if(COSMA_BLAS STREQUAL "OFF")
45+
message(FATAL_ERROR "A Blas implementation is needed when running on CPU only: choices are : auto, MKL, OPENBLAS, CRAY_LIBSCI, NVPL, CUSTOM, BLIS, ATLAS, FLEXIBLAS, ARMPL, GenericBLAS, CUDA or ROCM")
46+
endif()
47+
4448
if (COSMA_BLAS MATCHES "CUDA|ROCM")
4549
set(COSMA_GPU_BACKEND ${COSMA_BLAS})
4650
else()
47-
if(COSMA_BLAS STREQUAL "OFF")
48-
message(FATAL_ERROR "A Blas implementation is needed when running on CPU only: choices are : auto, MKL, OPENBLAS, CRAY_LIBSCI, NVPL, CUSTOM, BLIS, ATLAS, FLEXIBLAS, ARMPL, GenericBLAS")
49-
else()
50-
set(COSMA_BLAS_VENDOR ${COSMA_BLAS})
51-
endif()
51+
set(COSMA_BLAS_VENDOR ${COSMA_BLAS})
5252
endif()
5353

54-
if (COSMA_WITH_NCCL AND NOT COSMA_GPU_BACKEND IN_LIST COSMA_GPU_BACKENDS_LIST)
55-
message(FATAL_ERROR "NCCL can only be used with the GPU backend.")
54+
if ((COSMA_WITH_NCCL OR COSMA_WITH_RCCL) AND NOT COSMA_GPU_BACKEND IN_LIST COSMA_GPU_BACKENDS_LIST)
55+
message(FATAL_ERROR "NCCL (RCCL) can only be used with the GPU backend set to CUDA (ROCM).")
5656
endif()
5757

5858
if (COSMA_WITH_GPU_AWARE_MPI AND NOT COSMA_GPU_BACKEND IN_LIST COSMA_GPU_BACKENDS_LIST)
59-
message(FATAL_ERROR "GPU-aware MPI can only be used with the GPU backend.")
59+
message(FATAL_ERROR "GPU-aware MPI can only be used with the GPU backend set to CUDA or ROCM.")
6060
endif()
6161

6262
if(NOT CMAKE_BUILD_TYPE)
6363
set(CMAKE_BUILD_TYPE "Release")
6464
endif()
6565

66+
# Dependencies
67+
# MPI
68+
set(MPI_DETERMINE_LIBRARY_VERSION TRUE)
69+
find_package(MPI COMPONENTS CXX REQUIRED)
70+
adjust_mpiexec_flags()
6671

6772
# check if scalapack backend is valid
6873
message(STATUS "Selected SCALAPACK backend for COSMA: ${COSMA_SCALAPACK}")
74+
6975
if(NOT COSMA_SCALAPACK IN_LIST COSMA_SCALAPACK_LIST)
7076
message(FATAL_ERROR "Invalid value for COSMA_SCALAPACK!")
7177
endif()
@@ -79,53 +85,42 @@ if (NOT COSMA_SCALAPACK MATCHES "OFF")
7985
endif()
8086
endif()
8187

82-
if (NOT COSMA_BLAS_VENDOR MATCHES "OFF")
83-
find_package(Blas REQUIRED)
84-
endif()
8588

86-
# preserve rpaths when installing and make the install folder relocatable
87-
# use `CMAKE_SKIP_INSTALL_RPATH` to skip this
88-
# https://spack.readthedocs.io/en/latest/workflows.html#write-the-cmake-build
89-
list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES
90-
"${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}" isSystemDir)
91-
# skip RPATH if COSMA is installed to system directories
92-
if(isSystemDir STREQUAL "-1")
93-
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
94-
if(APPLE)
95-
set(basePoint @loader_path)
96-
else()
97-
set(basePoint $ORIGIN)
98-
endif()
99-
file(RELATIVE_PATH relDir ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}
100-
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
101-
set(CMAKE_INSTALL_RPATH ${basePoint} ${basePoint}/${relDir})
89+
if (NOT COSMA_BLAS_VENDOR MATCHES "OFF|CUDA|ROCM")
90+
find_package(Blas REQUIRED)
10291
endif()
10392

104-
# Dependencies
105-
# MPI
106-
set(MPI_DETERMINE_LIBRARY_VERSION TRUE)
107-
find_package(MPI COMPONENTS CXX REQUIRED)
108-
adjust_mpiexec_flags()
109-
11093
if (NOT COSMA_SCALAPACK MATCHES "OFF")
11194
find_package(SCALAPACK REQUIRED)
112-
endif()
95+
endif ()
11396

114-
if (COSMA_WITH_PROFILING)
115-
find_package(semiprof REQUIRED)
97+
set(COSTA_WITH_PROFILING ${COSMA_WITH_PROFILING} CACHE INTERNAL "")
98+
set(COSTA_SCALAPACK ${COSMA_SCALAPACK} CACHE INTERNAL "")
99+
100+
FetchContent_Declare(
101+
costa
102+
GIT_REPOSITORY https://github.com/eth-cscs/costa.git
103+
GIT_TAG 03847e66f05ad4a1eb371b85be628e218ce46f11 # v2.2.3
104+
FIND_PACKAGE_ARGS NAMES costa
105+
)
106+
# the joy of fetch_content. if we build costa and cosma together
107+
# fetch_content will pick up the FindSCALAPACK from cosma NOT costa.
108+
if (NOT TARGET costa::scalapack::scalapack AND NOT COSMA_SCALAPACK MATCHES "OFF")
109+
add_library(costa::scalapack::scalapack ALIAS cosma::scalapack::scalapack)
116110
endif ()
117111

118-
if (COSMA_WITH_TESTS OR COSMA_WITH_APPS)
119-
add_git_submodule_or_find_external(cxxopts libs/cxxopts)
120-
endif()
112+
FetchContent_MakeAvailable(costa)
121113

122114
# these are only GPU-backends
123115
if (COSMA_GPU_BACKEND MATCHES "CUDA|ROCM")
124-
set(TILEDMM_GPU_BACKEND ${COSMA_GPU_BACKEND} CACHE STRING "GPU backend" FORCE)
125-
add_git_submodule_or_find_external(Tiled-MM libs/Tiled-MM)
126-
if (NOT TARGET Tiled-MM::Tiled-MM AND TARGET Tiled-MM)
127-
add_library(Tiled-MM::Tiled-MM ALIAS Tiled-MM)
128-
endif()
116+
set(TILEDMM_GPU_BACKEND ${COSMA_GPU_BACKEND} CACHE INTERNAL "")
117+
FetchContent_Declare(
118+
Tiled-MM
119+
GIT_REPOSITORY https://github.com/eth-cscs/Tiled-MM.git
120+
GIT_TAG 0eb75179e670a04c649b50ae5e91bb71b43e4d06 # v2.3.2
121+
FIND_PACKAGE_ARGS NAMES tiled-MM
122+
)
123+
FetchContent_MakeAvailable(Tiled-MM)
129124

130125
if (COSMA_WITH_NCCL)
131126
find_package(CUDAToolkit REQUIRED)
@@ -134,26 +129,51 @@ if (COSMA_GPU_BACKEND MATCHES "CUDA|ROCM")
134129
find_package(hip REQUIRED)
135130
find_package(rccl REQUIRED)
136131
endif()
137-
endif()
138132

139-
set(COSTA_WITH_PROFILING ${COSMA_WITH_PROFILING} CACHE STRING "" FORCE)
140-
set(COSTA_SCALAPACK ${COSMA_SCALAPACK} CACHE STRING "" FORCE)
133+
if (NOT TARGET Tiled-MM::Tiled-MM)
134+
message("Tiled-mm target not found")
135+
endif ()
141136

142-
if (TARGET cosma::scalapack::scalapack AND NOT COSMA_SCALAPACK MATCHES "OFF")
143-
add_library(costa::scalapack::scalapack ALIAS cosma::scalapack::scalapack)
144137
endif()
145138

146-
add_git_submodule_or_find_external(costa libs/COSTA)
147-
148-
# alias targets for add_subdirectory dependency
139+
if (COSMA_WITH_PROFILING)
140+
FetchContent_Declare(
141+
semiprof
142+
GIT_REPOSITORY https://github.com/bcumming/semiprof.git
143+
GIT_TAG f132142ff2215dfa073e416fa7911d8877d62752
144+
FIND_PACKAGE_ARGS NAMES semiprof)
145+
FetchContent_MakeAvailable(semiprof)
146+
endif ()
149147

150-
if (NOT TARGET costa::costa)
151-
add_library(costa::costa ALIAS costa)
148+
if (COSMA_WITH_TESTS OR COSMA_WITH_APPS)
149+
FetchContent_Declare(
150+
cxxopts
151+
GIT_REPOSITORY https://github.com/jarro2783/cxxopts.git
152+
GIT_TAG 4bf61f08697b110d9e3991864650a405b3dd515d # v3.2.1
153+
FIND_PACKAGE_ARGS NAMES cxxopts
154+
)
155+
FetchContent_MakeAvailable(cxxopts)
152156
endif()
153157

154-
if (TARGET costa_prefixed_scalapack AND (NOT TARGET costa::costa_prefixed_scalapack))
155-
add_library(costa::costa_prefixed_scalapack ALIAS costa_prefixed_scalapack)
156-
add_library(costa::costa_scalapack ALIAS costa_scalapack)
158+
if (NOT TARGET Tiled-MM::Tiled-MM)
159+
message("Tiled-mm target not found")
160+
endif ()
161+
# preserve rpaths when installing and make the install folder relocatable
162+
# use `CMAKE_SKIP_INSTALL_RPATH` to skip this
163+
# https://spack.readthedocs.io/en/latest/workflows.html#write-the-cmake-build
164+
list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES
165+
"${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}" isSystemDir)
166+
# skip RPATH if COSMA is installed to system directories
167+
if(isSystemDir STREQUAL "-1")
168+
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
169+
if(APPLE)
170+
set(basePoint @loader_path)
171+
else()
172+
set(basePoint $ORIGIN)
173+
endif()
174+
file(RELATIVE_PATH relDir ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}
175+
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
176+
set(CMAKE_INSTALL_RPATH ${basePoint} ${basePoint}/${relDir})
157177
endif()
158178

159179
# COSMA

ci/cscs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ build base image:
1515
WATCH_FILECHANGES: ci/baseimage.cuda.Dockerfile
1616
PERSIST_IMAGE_NAME: $CSCS_REGISTRY_PATH/base/cosma-ci
1717

18-
build tiled-mm:
18+
build cosma:
1919
extends: .container-builder-cscs-gh200
2020
needs: ["build base image"]
2121
stage: build
@@ -27,7 +27,7 @@ build tiled-mm:
2727

2828
.run_tests:
2929
extends: [.container-runner-daint-gh200]
30-
needs: ["build tiled-mm"]
30+
needs: ["build cosma"]
3131
stage: test
3232
image: $CSCS_REGISTRY_PATH/cosma/cosma-ci:$CI_COMMIT_SHA
3333
variables:

miniapp/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ set(executables "layout_miniapp" "cosma_miniapp" "cosma_statistics")
66
foreach(exec ${executables})
77
add_executable(${exec} "${exec}.cpp")
88
target_link_libraries(${exec} PRIVATE cosma cxxopts::cxxopts)
9-
target_include_directories(${exec} PUBLIC "${cosma_SOURCE_DIR}/libs/cxxopts/include/")
109
install(TARGETS ${exec} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}/bin")
1110
endforeach()
1211

@@ -15,7 +14,6 @@ if(NOT COSMA_SCALAPACK MATCHES "OFF")
1514
foreach(exec ${scalapack_executables})
1615
add_executable(${exec} "${exec}.cpp")
1716
target_link_libraries(${exec} PRIVATE cosma_pxgemm_cpp cxxopts::cxxopts)
18-
target_include_directories(${exec} PUBLIC "${cosma_SOURCE_DIR}/libs/cxxopts/include/")
1917
install(TARGETS ${exec} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}/bin")
2018
if (COSMA_WITH_PROFILING)
2119
target_link_libraries(${exec} PRIVATE semiprof::semiprof)

src/cosma/CMakeLists.txt

Lines changed: 31 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -39,84 +39,62 @@ target_link_libraries(cosma PUBLIC
3939
MPI::MPI_CXX
4040
costa::costa
4141
$<TARGET_NAME_IF_EXISTS:roc::rccl>
42-
$<TARGET_NAME_IF_EXISTS:cosma::nccl>)
43-
44-
if (NOT COSMA_BLAS_VENDOR MATCHES "OFF")
45-
target_link_libraries(cosma PUBLIC cosma::BLAS::blas)
46-
endif()
47-
48-
if (COSMA_GPU_BACKEND STREQUAL "OFF")
49-
if ((NOT COSMA_BLAS_VENDOR MATCHES "MKL") AND (NOT COSMA_BLAS_VENDOR MATCHES "BLIS"))
50-
target_compile_definitions(cosma PUBLIC COSMA_WITH_BLAS)
51-
endif()
52-
53-
if (COSMA_GPU_BACKEND STREQUAL "OFF")
54-
target_compile_definitions(cosma PUBLIC
55-
$<$<STREQUAL:${COSMA_BLAS_VENDOR},MKL>:COSMA_WITH_MKL_BLAS>
56-
$<$<STREQUAL:${COSMA_BLAS_VENDOR},BLIS>:COSMA_WITH_BLIS_BLAS>)
57-
endif()
58-
else()
59-
target_compile_definitions(cosma PUBLIC COSMA_HAVE_GPU)
60-
target_link_libraries(cosma PUBLIC Tiled-MM::Tiled-MM)
61-
endif()
42+
$<TARGET_NAME_IF_EXISTS:cosma::nccl>
43+
$<$<NOT:$<STREQUAL:${COSMA_BLAS_VENDOR},"OFF">>:cosma::BLAS::blas>
44+
$<TARGET_NAME_IF_EXISTS:Tiled-MM::Tiled-MM>
45+
$<$<STREQUAL:${COSMA_GPU_BACKEND},CUDA>:Tiled-MM::Tiled-MM>
46+
$<$<STREQUAL:${COSMA_GPU_BACKEND},ROCM>:Tiled-MM::Tiled-MM>
47+
$<$<BOOL:${COSMA_WITH_PROFILING}>:semiprof::semiprof>
48+
$<$<BOOL:${COSMA_SCALAPACK}>:cosma::scalapack::scalapack>)
6249

6350
target_compile_definitions(cosma PUBLIC
64-
$<$<BOOL:${COSMA_WITH_NCCL}>:COSMA_WITH_NCCL>
65-
$<$<STREQUAL:${COSMA_GPU_BACKEND},"ROCM">:__HIP_PLATFORM_HCC__>
66-
$<$<BOOL:${COSMA_WITH_GPU_AWARE_MPI}>:COSMA_WITH_GPU_AWARE_MPI>)
67-
68-
target_compile_definitions(cosma PUBLIC
69-
$<$<BOOL:${COSMA_WITH_NCCL}>:COSMA_WITH_NCCL>
70-
$<$<BOOL:${COSMA_WITH_RCCL}>:COSMA_WITH_NCCL>
71-
)
72-
73-
target_compile_definitions(cosma PRIVATE $<$<BOOL:${COSMA_WITH_PROFILING}>:COSMA_WITH_PROFILING>)
74-
75-
if(COSMA_WITH_PROFILING)
76-
target_link_libraries(cosma PRIVATE semiprof::semiprof)
77-
endif()
51+
$<$<BOOL:${COSMA_WITH_NCCL}>:COSMA_WITH_NCCL>
52+
$<$<STREQUAL:${COSMA_GPU_BACKEND},"ROCM">:__HIP_PLATFORM_HCC__>
53+
$<$<BOOL:${COSMA_WITH_GPU_AWARE_MPI}>:COSMA_WITH_GPU_AWARE_MPI>
54+
$<$<BOOL:${COSMA_WITH_NCCL}>:COSMA_WITH_NCCL>
55+
$<$<BOOL:${COSMA_WITH_RCCL}>:COSMA_WITH_NCCL>
56+
$<$<STREQUAL:${COSMA_BLAS_VENDOR},MKL>:COSMA_WITH_MKL_BLAS>
57+
$<$<STREQUAL:${COSMA_BLAS_VENDOR},BLIS>:COSMA_WITH_BLIS_BLAS>
58+
$<$<NOT:$<IN_LIST:${COSMA_BLAS_VENDOR},"MKL;BLIS">>:COSMA_WITH_BLAS>
59+
$<$<STREQUAL:${COSMA_GPU_BACKEND},CUDA>:COSMA_HAVE_GPU>
60+
$<$<STREQUAL:${COSMA_GPU_BACKEND},ROCM>:COSMA_HAVE_GPU>
61+
PRIVATE
62+
$<$<BOOL:${COSMA_WITH_PROFILING}>:COSMA_WITH_PROFILING>)
7863

7964
list(APPEND INSTALLED_TARGETS_LIST "cosma")
8065

8166
# if SCALAPACK is found and cosma_pxgemm library is not already created
8267
# then create it here and link it to the profiler if needed
8368
# build as a shared library is necessary here because of the function interposing
8469
if(COSMA_SCALAPACK)
85-
target_link_libraries(cosma PUBLIC cosma::scalapack::scalapack)
8670
if (NOT TARGET cosma_pxgemm AND BUILD_SHARED_LIBS)
8771
add_library(cosma_pxgemm scalapack.cpp
8872
pxgemm_params.hpp
8973
cosma_pxgemm.cpp
9074
pxgemm.cpp
9175
)
9276

93-
target_link_libraries(cosma_pxgemm PUBLIC cosma)
77+
target_link_libraries(cosma_pxgemm PUBLIC cosma
78+
$<$<BOOL:${COSMA_WITH_PROFILING}>:semiprof::semiprof>)
9479

95-
if(COSMA_WITH_PROFILING)
96-
target_link_libraries(cosma_pxgemm PRIVATE semiprof::semiprof)
97-
target_compile_definitions(cosma_pxgemm PRIVATE COSMA_WITH_PROFILING)
98-
endif()
80+
target_compile_definitions(cosma_pxgemm PRIVATE $<$<BOOL:${COSMA_WITH_PROFILING}>:COSMA_WITH_PROFILING>)
9981
list(APPEND INSTALLED_TARGETS_LIST "cosma_pxgemm")
10082
endif()
10183

10284
# this is a library exposing the prefixed scalapack API (with cosma/COSMA prefix)
10385
# it is aimed for users who don't want to overwrite the available scalapack API with cosma.
10486
# if SCALAPACK is found and cosma_prefixed_pxgemm library is not already created
10587
# then create it here and link it to the profiler if needed
106-
if(NOT TARGET cosma_prefixed_pxgemm)
10788
add_library(cosma_prefixed_pxgemm scalapack.cpp
10889
pxgemm_params.hpp
10990
prefixed_pxgemm.cpp
11091
cosma_pxgemm.cpp
11192
)
112-
target_link_libraries(cosma_prefixed_pxgemm PUBLIC cosma)
113-
114-
if(COSMA_WITH_PROFILING)
115-
target_link_libraries(cosma_prefixed_pxgemm PRIVATE semiprof::semiprof)
116-
target_compile_definitions(cosma_prefixed_pxgemm PRIVATE COSMA_WITH_PROFILING)
117-
endif()
93+
target_link_libraries(cosma_prefixed_pxgemm
94+
PUBLIC cosma
95+
PRIVATE $<$<BOOL:${COSMA_WITH_PROFILING}>:semiprof::semiprof>)
96+
target_compile_definitions(cosma_prefixed_pxgemm PRIVATE $<$<BOOL:${COSMA_WITH_PROFILING}>:COSMA_WITH_PROFILING>)
11897
list(APPEND INSTALLED_TARGETS_LIST "cosma_prefixed_pxgemm")
119-
endif()
12098

12199
# the following library is aimed only for testing purposes
122100
# it provides templated cosma::pxgemm call without
@@ -127,12 +105,12 @@ if(COSMA_SCALAPACK)
127105
pxgemm_params.hpp
128106
cosma_pxgemm.cpp
129107
)
130-
target_link_libraries(cosma_pxgemm_cpp PUBLIC cosma)
108+
target_link_libraries(cosma_pxgemm_cpp
109+
PUBLIC cosma
110+
PRIVATE $<$<BOOL:${COSMA_WITH_PROFILING}>:semiprof::semiprof>)
131111

132-
if(COSMA_WITH_PROFILING)
133-
target_link_libraries(cosma_pxgemm_cpp PRIVATE semiprof::semiprof)
134-
target_compile_definitions(cosma_pxgemm_cpp PRIVATE COSMA_WITH_PROFILING)
135-
endif()
112+
target_compile_definitions(cosma_pxgemm_cpp
113+
PRIVATE $<$<BOOL:${COSMA_WITH_PROFILING}>:COSMA_WITH_PROFILING>)
136114
list(APPEND INSTALLED_TARGETS_LIST "cosma_pxgemm_cpp")
137115
endif()
138116
endif()

src/cosma/pinned_buffers.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <complex>
12
#include <cosma/pinned_buffers.hpp>
23

34
// container of pinned buffers

0 commit comments

Comments
 (0)