-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathCMakeLists.txt
195 lines (165 loc) · 6.09 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
cmake_minimum_required (VERSION 3.12)
project(KokkosRemoteSpaces
LANGUAGES CXX
VERSION 0.1.0)
set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)
set(CMAKE_DISABLE_SOURCE_CHANGES ON)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/modules)
find_package(Kokkos REQUIRED)
option(KRS_ENABLE_NVSHMEMSPACE "Whether to build with NVSHMEM space" OFF)
option(KRS_ENABLE_ROCSHMEMSPACE "Whether to build with ROCSHMEM space" OFF)
option(KRS_ENABLE_SHMEMSPACE "Whether to build with SHMEMS space" OFF)
option(KRS_ENABLE_MPISPACE "Whether to build with MPI space" OFF)
option(KRS_ENABLE_DEBUG "Whether to enable debugging output" OFF)
option(KRS_ENABLE_BENCHMARKS "Whether to build benchmarks" OFF)
option(KRS_ENABLE_APPLICATIONS "Whether to build applications" OFF)
option(KRS_ENABLE_TESTS "Whether to build tests" OFF)
set(SOURCE_DIRS)
set(PUBLIC_DEPS)
set(PRIVATE_DEPS)
set(BACKENDS)
# Append public headers DIR to SOURCE_DIRS
list(APPEND SOURCE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/src/core)
set(PREFIX_BACKEND_SRC_PATH "src/impl")
set(NVSHMEMSPACE_PATH "${PREFIX_BACKEND_SRC_PATH}/nvshmemspace")
set(ROCSHMEMSPACE_PATH "${PREFIX_BACKEND_SRC_PATH}/rocshmemspace")
set(SHMEMSPACE_PATH "${PREFIX_BACKEND_SRC_PATH}/shmemspace")
set(MPISPACE_PATH "${PREFIX_BACKEND_SRC_PATH}/mpispace")
find_package(MPI REQUIRED)
add_library(MPI INTERFACE)
list(APPEND MPI_CXX_LINK_FLAGS ${MPI_CXX_LIBRARIES})
set_target_properties(MPI PROPERTIES
INTERFACE_COMPILE_OPTIONS "${MPI_CXX_COMPILE_FLAGS}"
INTERFACE_INCLUDE_DIRECTORIES "${MPI_CXX_INCLUDE_PATH}"
INTERFACE_LINK_LIBRARIES "${MPI_CXX_LINK_FLAGS}"
)
list(APPEND PUBLIC_DEPS MPI)
if (KRS_ENABLE_NVSHMEMSPACE)
# Requiere Kokkos with RDC and Lambda support
kokkos_check(
OPTIONS CUDA_LAMBDA CUDA_RELOCATABLE_DEVICE_CODE
DEVICES CUDA)
find_package(NVSHMEM REQUIRED)
set(BACKEND_NAME NVSHMEMSPACE)
list(APPEND SOURCE_DIRS ${NVSHMEMSPACE_PATH})
list(APPEND PUBLIC_DEPS ${BACKEND_NAME})
list(APPEND BACKENDS ${BACKEND_NAME})
endif()
if (KRS_ENABLE_ROCSHMEMSPACE)
# Require Kokkos with RDC
kokkos_check(
OPTIONS HIP_RELOCATABLE_DEVICE_CODE
DEVICES HIP)
find_package(ROCSHMEM REQUIRED)
set(BACKEND_NAME ROCSHMEMSPACE)
list(APPEND SOURCE_DIRS ${ROCSHMEMSPACE_PATH})
list(APPEND PUBLIC_DEPS ${BACKEND_NAME})
list(APPEND BACKENDS ${BACKEND_NAME})
endif()
if (KRS_ENABLE_SHMEMSPACE)
find_package(SHMEM REQUIRED)
set(BACKEND_NAME SHMEMSPACE)
list(APPEND SOURCE_DIRS ${SHMEMSPACE_PATH})
list(APPEND PUBLIC_DEPS ${BACKEND_NAME})
list(APPEND BACKENDS ${BACKEND_NAME})
endif()
if (KRS_ENABLE_MPISPACE)
add_library(MPISPACE INTERFACE)
set(BACKEND_NAME MPISPACE)
list(APPEND SOURCE_DIRS ${MPISPACE_PATH})
list(APPEND PUBLIC_DEPS ${BACKEND_NAME})
list(APPEND BACKENDS ${BACKEND_NAME})
endif()
if (KRS_ENABLE_RACERLIB)
find_package(IBVERBS REQUIRED)
list(APPEND PUBLIC_DEPS IBVERBS)
endif()
message(STATUS "Enabled remote spaces: ${BACKENDS}")
list(LENGTH BACKENDS N_BACKENDS)
if (NOT ${N_BACKENDS} EQUAL "1")
message(FATAL_ERROR "Must give a single valid backend. ${N_BACKENDS} given.")
endif()
set(SOURCES)
set(HEADERS)
foreach(DIR ${SOURCE_DIRS})
file(GLOB DIR_SRCS ${DIR}/*.cpp)
file(GLOB DIR_HDRS ${DIR}/*.hpp)
list(APPEND SOURCES ${DIR_SRCS})
list(APPEND HEADERS ${DIR_HDRS})
endforeach()
if (KRS_ENABLE_RACERLIB)
file(GLOB DIR_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/src/features/racerlib/*.cpp)
file(GLOB DIR_HDRS ${CMAKE_CURRENT_SOURCE_DIR}/src/features/racerlib/*.hpp)
list(APPEND SOURCES ${DIR_SRCS})
list(APPEND HEADERS ${DIR_HDRS})
endif()
add_library(kokkosremotespaces ${SOURCES} ${HEADERS})
add_library(Kokkos::kokkosremotespaces ALIAS kokkosremotespaces)
target_link_libraries(kokkosremotespaces PUBLIC Kokkos::kokkos)
foreach(DIR ${SOURCE_DIRS})
target_include_directories(kokkosremotespaces PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/${DIR}>)
foreach(BACKEND_NAME ${PUBLIC_DEPS})
target_compile_definitions(kokkosremotespaces PUBLIC KRS_ENABLE_${BACKEND_NAME})
endforeach()
endforeach()
if (KRS_ENABLE_RACERLIB)
target_include_directories(kokkosremotespaces PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/features/racerlib>)
target_compile_definitions(kokkosremotespaces PUBLIC KRS_ENABLE_RACERLIB)
endif()
target_include_directories(kokkosremotespaces PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/core>)
target_include_directories(kokkosremotespaces PUBLIC $<INSTALL_INTERFACE:include>)
if(KRS_ENABLE_DEBUG OR CMAKE_BUILD_TYPE STREQUAL "Debug")
target_compile_definitions(kokkosremotespaces PUBLIC KOKKOS_REMOTE_SPACES_ENABLE_DEBUG)
message(STATUS "Enabled build mode: debug")
endif()
if (PRIVATE_DEPS)
target_link_libraries(kokkosremotespaces PRIVATE ${PRIVATE_DEPS})
endif()
if (PUBLIC_DEPS)
target_link_libraries(kokkosremotespaces PUBLIC ${PUBLIC_DEPS})
endif()
if (KRS_ENABLE_NVSHMEMSPACE)
target_link_libraries(kokkosremotespaces PRIVATE "-lnvidia-ml")
endif()
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
configure_package_config_file(
KokkosRemoteSpacesConfig.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/KokkosRemoteSpacesConfig.cmake"
INSTALL_DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}/cmake
)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/KokkosRemoteSpacesConfigVersion.cmake"
VERSION "${KokkosRemote_VERSION}"
COMPATIBILITY AnyNewerVersion
)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/KokkosRemoteSpacesConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/KokkosRemoteSpacesConfigVersion.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/KokkosRemoteSpaces)
install(FILES
${HEADERS}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(
TARGETS kokkosremotespaces ${PUBLIC_DEPS}
EXPORT KokkosRemoteSpacesTargets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
install(EXPORT
KokkosRemoteSpacesTargets
NAMESPACE Kokkos::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/KokkosRemoteSpaces
)
IF (KRS_ENABLE_BENCHMARKS)
add_subdirectory(benchmarks)
ENDIF()
IF (KRS_ENABLE_APPLICATIONS)
add_subdirectory(applications)
ENDIF()
IF (KRS_ENABLE_TESTS)
enable_testing()
add_subdirectory(unit_tests)
ENDIF()