forked from ROCm/rocSOLVER
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
330 lines (285 loc) · 11.9 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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
# ##########################################################################
# Copyright (C) 2019-2024 Advanced Micro Devices, Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
# ##########################################################################
cmake_minimum_required(VERSION 3.13)
# This has to be initialized before the project() command appears
# Set the default build type to Release
if(NOT DEFINED CMAKE_CONFIGURATION_TYPES AND NOT DEFINED CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING
"Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel.")
endif()
if(NOT DEFINED CMAKE_Fortran_COMPILER AND NOT DEFINED ENV{FC})
set(CMAKE_Fortran_COMPILER "gfortran")
endif()
# ROCM_BUILD_ID is added to the package name by rocm-cmake. Unsetting it prevents that.
unset(ENV{ROCM_BUILD_ID})
# Disable ROCMClang detection to make CMake v3.21 work the same as CMake v3.20 and earlier.
# https://gitlab.kitware.com/cmake/cmake/-/merge_requests/6533
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.21.0 AND CMAKE_VERSION VERSION_LESS 3.21.3)
set(__skip_rocmclang ON)
endif()
message(STATUS "Using CMake ${CMAKE_VERSION}")
project(rocsolver LANGUAGES CXX C)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
option(ROCSOLVER_EMBED_FMT "Hide libfmt symbols" ON)
option(OPTIMAL "Build specialized kernels for small matrix sizes" ON)
option(ROCSOLVER_FIND_PACKAGE_LAPACK_CONFIG "Skip module mode search for LAPACK" ON)
option(ROCSOLVER_USE_INTERNAL_BLAS "Use internal implementation of GEMM and TRSM for debugging." OFF)
# Add our CMake helper files to the lookup path
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
find_package(fmt REQUIRED)
# ########################################################################
# Main
# ########################################################################
# Get rocm-cmake
include(get-rocm-cmake)
# Include the rocm-cmake components we use
include(ROCMSetupVersion)
include(ROCMCreatePackage)
include(ROCMInstallTargets)
include(ROCMPackageConfigHelpers)
include(ROCMInstallSymlinks)
include(ROCMCheckTargetIds)
include(ROCMClients)
include(ROCMHeaderWrapper)
include(os-detection)
get_os_id(OS_ID)
message(STATUS "OS detected is ${OS_ID}")
# Versioning via rocm-cmake
set(VERSION_STRING "3.28.0")
rocm_setup_version(VERSION ${VERSION_STRING})
# Workaround until llvm and hip CMake modules fix symlink logic in their config files
list(APPEND CMAKE_PREFIX_PATH
${ROCM_PATH}
${ROCM_PATH}/llvm
${ROCM_PATH}/hip
/opt/rocm
/opt/rocm/llvm
/opt/rocm/hip
)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(DEFAULT_ARMOR_LEVEL 1)
else()
set(DEFAULT_ARMOR_LEVEL 0)
endif()
set(ARMOR_LEVEL "${DEFAULT_ARMOR_LEVEL}" CACHE STRING "Enables increasingly expensive runtime correctness checks")
include(armor-config)
# This option only works for make, nmake and ninja, but no reason it shouldn't be on all the time
# It creates a compile_commands.json file for use with clang tooling or vim
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# BUILD_SHARED_LIBS is a cmake built-in
# Make it an explicit option such that it shows in cmake-gui
option(BUILD_SHARED_LIBS "Build rocSOLVER as a shared library" ON)
# Include helper functions and wrapper functions
include(util)
include(CMakeDependentOption)
option(BUILD_TESTING "Build rocSOLVER tests" OFF)
if(BUILD_TESTING)
enable_testing()
endif()
if(BUILD_SHARED_LIBS)
set(BUILD_WITH_SPARSE_DEFAULT OFF)
else()
set(BUILD_WITH_SPARSE_DEFAULT ON)
endif()
option(BUILD_LIBRARY "Build rocSOLVER library" ON)
option_opposite(BUILD_LIBRARY SKIP_LIBRARY)
option(BUILD_WITH_SPARSE "Build with rocsparse available at build time" "${BUILD_WITH_SPARSE_DEFAULT}")
option(BUILD_CLIENTS_TESTS "Build rocSOLVER test client" "${BUILD_TESTING}")
option(BUILD_CLIENTS_BENCHMARKS "Build rocSOLVER benchmark client" OFF)
option(BUILD_CLIENTS_SAMPLES "Build rocSOLVER samples" OFF)
cmake_dependent_option(BUILD_CLIENTS_EXTRA_TESTS "Build extra tests" OFF BUILD_TESTING OFF)
option(BUILD_ADDRESS_SANITIZER "Build with address sanitizer enabled" OFF)
option(BUILD_CODE_COVERAGE "Build rocSOLVER with code coverage enabled" OFF)
option(WERROR "Treat warnings as errors" OFF)
option(BUILD_COMPRESSED_DBG "Enable compressed debug symbols" ON)
cmake_dependent_option(BUILD_FILE_REORG_BACKWARD_COMPATIBILITY
"Build with file/folder reorg backward compatibility enabled" OFF "NOT WIN32" OFF)
if(BUILD_FILE_REORG_BACKWARD_COMPATIBILITY)
rocm_wrap_header_dir(
${CMAKE_SOURCE_DIR}/library/include/rocsolver
PATTERNS "*.h"
GUARDS SYMLINK WRAPPER
WRAPPER_LOCATIONS ${CMAKE_INSTALL_INCLUDEDIR}
)
endif()
message(STATUS "Tests: ${BUILD_CLIENTS_TESTS}")
message(STATUS "Benchmarks: ${BUILD_CLIENTS_BENCHMARKS}")
message(STATUS "Samples: ${BUILD_CLIENTS_SAMPLES}")
if(NOT DEFINED AMDGPU_TARGETS)
# Query for compiler support of GPU archs
rocm_check_target_ids(OPTIONAL_AMDGPU_TARGETS
TARGETS
gfx90a:xnack-
gfx90a:xnack+
gfx940
gfx941
gfx942
gfx1100
gfx1101
gfx1102
gfx1151
gfx1200
gfx1201
)
set(AMDGPU_TARGETS_INIT
gfx900
gfx906:xnack-
gfx908:xnack-
gfx1010
gfx1030
${OPTIONAL_AMDGPU_TARGETS}
)
endif()
# Set this before finding hip so that hip::device has the required arch flags
# added as usage requirements on its interface
set(AMDGPU_TARGETS "${AMDGPU_TARGETS_INIT}"
CACHE STRING "List of specific machine types for library to target")
# Find HIP dependencies
find_package(hip REQUIRED CONFIG PATHS ${ROCM_PATH} /opt/rocm)
find_package(rocblas REQUIRED CONFIG PATHS ${ROCM_PATH})
get_imported_target_location(location roc::rocblas)
message(STATUS "Found rocBLAS: ${location}")
set(rocblas_minimum 4.1)
rocm_package_add_dependencies(SHARED_DEPENDS "rocblas >= ${rocblas_minimum}")
rocm_package_add_rpm_dependencies(STATIC_DEPENDS "rocblas-static-devel >= ${rocblas_minimum}")
rocm_package_add_deb_dependencies(STATIC_DEPENDS "rocblas-static-dev >= ${rocblas_minimum}")
if(BUILD_WITH_SPARSE)
find_package(rocsparse REQUIRED CONFIG PATHS ${ROCM_PATH})
get_imported_target_location(location roc::rocsparse)
message(STATUS "Found rocSPARSE: ${location}")
set(rocsparse_minimum 2.2)
rocm_package_add_dependencies(SHARED_DEPENDS "rocsparse >= ${rocsparse_minimum}")
rocm_package_add_rpm_dependencies(STATIC_DEPENDS "rocsparse-static-devel >= ${rocsparse_minimum}")
rocm_package_add_deb_dependencies(STATIC_DEPENDS "rocsparse-static-dev >= ${rocsparse_minimum}")
else()
list(APPEND CPACK_DEBIAN_RUNTIME_PACKAGE_RECOMMENDS "rocsparse")
list(APPEND CPACK_RPM_RUNTIME_PACKAGE_SUGGESTS "rocsparse")
endif()
find_package(rocprim REQUIRED CONFIG PATHS ${ROCM_PATH})
rocm_package_add_rpm_dependencies(STATIC_DEPENDS "rocprim-static-devel")
rocm_package_add_deb_dependencies(STATIC_DEPENDS "rocprim-static-dev")
add_subdirectory(common)
if(BUILD_LIBRARY)
add_subdirectory(library)
endif()
if(BUILD_CLIENTS_TESTS OR BUILD_CLIENTS_BENCHMARKS OR BUILD_CLIENTS_SAMPLES)
if(NOT CLIENTS_OS)
rocm_set_os_id(CLIENTS_OS)
string(TOLOWER "${CLIENTS_OS}" CLIENTS_OS)
rocm_read_os_release(CLIENTS_OS_VERSION VERSION_ID)
endif()
set(GFORTRAN_RPM "libgfortran4")
set(GFORTRAN_DEB "libgfortran4")
if(CLIENTS_OS STREQUAL "centos" OR CLIENTS_OS STREQUAL "rhel")
if(CLIENTS_OS_VERSION VERSION_GREATER_EQUAL "8")
set(GFORTRAN_RPM "libgfortran")
endif()
elseif(CLIENTS_OS STREQUAL "ubuntu" AND CLIENTS_OS_VERSION VERSION_GREATER_EQUAL "20.04")
set(GFORTRAN_DEB "libgfortran5")
elseif(CLIENTS_OS STREQUAL "mariner" OR CLIENTS_OS STREQUAL "azurelinux")
set(GFORTRAN_RPM "gfortran")
endif()
rocm_package_setup_component(clients)
if(BUILD_CLIENTS_TESTS)
rocm_package_setup_client_component(tests DEPENDS DEB "${GFORTRAN_DEB}" RPM "${GFORTRAN_RPM}")
endif()
if(BUILD_CLIENTS_BENCHMARKS)
rocm_package_setup_client_component(benchmarks DEPENDS DEB "${GFORTRAN_DEB}" RPM "${GFORTRAN_RPM}")
endif()
add_subdirectory(clients)
endif()
if(OS_ID_sles)
rocm_package_add_rpm_dependencies("libLLVM >= 7.0.1")
endif()
set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE.md")
set(CPACK_RPM_PACKAGE_LICENSE "BSD")
if(WIN32)
set(CPACK_SOURCE_GENERATOR "ZIP")
set(CPACK_GENERATOR "ZIP")
set(CMAKE_INSTALL_PREFIX "C:/hipSDK" CACHE PATH "Install path" FORCE)
set(INSTALL_PREFIX "C:/hipSDK")
set(CPACK_SET_DESTDIR OFF)
set(CPACK_PACKAGE_INSTALL_DIRECTORY "C:/hipSDK")
set(CPACK_PACKAGING_INSTALL_PREFIX "")
set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY OFF)
else()
if(NOT CPACK_PACKAGING_INSTALL_PREFIX)
set(CPACK_PACKAGING_INSTALL_PREFIX "${ROCM_PATH}")
endif()
endif()
set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION
"\${CPACK_PACKAGING_INSTALL_PREFIX}"
)
set(ROCSOLVER_CONFIG_DIR "\${CPACK_PACKAGING_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}"
CACHE PATH "Path placed into ldconfig file")
rocm_create_package(
NAME rocsolver
DESCRIPTION "AMD ROCm SOLVER library"
MAINTAINER "RocSOLVER maintainer <rocsolver-maintainer@amd.com>"
LDCONFIG
LDCONFIG_DIR ${ROCSOLVER_CONFIG_DIR}
)
# Code Coverage Build Commands:
# make coverage_cleanup (clean coverage related files)
# make coverage GTEST_FILTER=<>
# make coverage_analysis GTEST_FILTER=<> (analyze tests)
# make coverage_output (generate html documentation)
if(BUILD_CODE_COVERAGE)
# Run coverage analysis
add_custom_target(coverage_analysis
COMMAND echo Coverage GTEST_FILTER=\${GTEST_FILTER}
COMMAND ./clients/staging/rocsolver-test --gtest_filter=\"\${GTEST_FILTER}\"
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
add_dependencies(coverage_analysis rocsolver)
# Generate gcov-tool script
# This little script is generated because the option '--gcov-tool <program name>' of lcov cannot take arguments.
add_custom_target(coverage_output
DEPENDS coverage_analysis
COMMAND mkdir -p lcoverage
COMMAND echo "\\#!/bin/bash" > llvm-gcov.sh
COMMAND echo "\\# THIS FILE HAS BEEN GENERATED" >> llvm-gcov.sh
COMMAND printf "exec /opt/rocm/llvm/bin/llvm-cov gcov $$\\@" >> llvm-gcov.sh
COMMAND chmod +x llvm-gcov.sh
)
# Generate code coverage report
add_custom_command(TARGET coverage_output
COMMAND lcov --directory . --base-directory . --gcov-tool ${CMAKE_BINARY_DIR}/llvm-gcov.sh --capture -o lcoverage/raw_main_coverage.info
COMMAND lcov --remove lcoverage/raw_main_coverage.info "'/opt/*'" "'/usr/*'" -o lcoverage/main_coverage.info
COMMAND genhtml --ignore-errors source lcoverage/main_coverage.info --output-directory lcoverage
)
add_custom_target(coverage DEPENDS coverage_output)
# Delete gcov data files
add_custom_target(coverage_cleanup
COMMAND find ${CMAKE_BINARY_DIR} -name *.gcda -delete
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
endif()