-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathFindOrFetchBTAS.cmake
More file actions
94 lines (84 loc) · 3.97 KB
/
Copy pathFindOrFetchBTAS.cmake
File metadata and controls
94 lines (84 loc) · 3.97 KB
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
# try find_package
if (NOT TARGET BTAS::BTAS)
include (FindPackageRegimport)
find_package_regimport(BTAS 1.0.0 QUIET CONFIG)
if (TARGET BTAS::BTAS)
message(STATUS "Found BTAS CONFIG at ${BTAS_CONFIG}")
endif (TARGET BTAS::BTAS)
endif (NOT TARGET BTAS::BTAS)
# if not found, build via FetchContent
if (NOT TARGET BTAS::BTAS)
# BTAS will load BLAS++/LAPACK++ ... if those use CMake's FindBLAS/FindLAPACK (as indicated by defined BLA_VENDOR)
# will need to specify Fortran linkage convention ... manually for now, switching to NWX's linear algebra discovery
# is necessary to handle all the corner cases for automatic discovery
if (DEFINED BLA_VENDOR)
set(_linalgpp_use_standard_linalg_kits TRUE)
endif(DEFINED BLA_VENDOR)
if (TILEDARRAY_HAS_CUDA)
# tell BLAS++/LAPACK++ to also look for CUDA
set(gpu_backend cuda CACHE STRING "The device backend to use for Linalg++")
elseif (TILEDARRAY_HAS_HIP)
# tell BLAS++/LAPACK++ to also look for HIP
set(gpu_backend hip CACHE STRING "The device backend to use for Linalg++")
else ()
# tell BLAS++/LAPACK++ to not look for device backends
set(gpu_backend none CACHE STRING "The device backend to use for Linalg++")
endif()
include(FetchContent)
FetchContent_Declare(
BTAS
GIT_REPOSITORY https://github.com/BTAS/btas.git
GIT_TAG ${TA_TRACKED_BTAS_TAG}
)
FetchContent_MakeAvailable(BTAS)
FetchContent_GetProperties(BTAS
SOURCE_DIR BTAS_SOURCE_DIR
BINARY_DIR BTAS_BINARY_DIR
)
# use subproject targets as if they were in exported namespace ...
if (TARGET BTAS AND NOT TARGET BTAS::BTAS)
add_library(BTAS::BTAS ALIAS BTAS)
endif(TARGET BTAS AND NOT TARGET BTAS::BTAS)
# set BTAS_CONFIG to the install location so that we know where to find it
set(BTAS_CONFIG ${CMAKE_INSTALL_PREFIX}/${BTAS_INSTALL_CMAKEDIR}/btas-config.cmake)
# define macros specifying Fortran mangling convention, if necessary
if (_linalgpp_use_standard_linalg_kits)
if (NOT TARGET blaspp AND NOT TARGET lapackpp)
message(FATAL_ERROR "blaspp or lapackpp targets missing")
endif(NOT TARGET blaspp AND NOT TARGET lapackpp)
if (LINALG_MANGLING STREQUAL lower)
target_compile_definitions(blaspp PUBLIC -DBLAS_FORTRAN_LOWER=1)
target_compile_definitions(lapackpp PUBLIC -DLAPACK_FORTRAN_LOWER=1)
elseif(LINALG_MANGLING STREQUAL UPPER OR LINALG_MANGLING STREQUAL upper)
target_compile_definitions(blaspp PUBLIC -DBLAS_FORTRAN_UPPER=1)
target_compile_definitions(lapackpp PUBLIC -DLAPACK_FORTRAN_UPPER=1)
else()
if (NOT LINALG_MANGLING STREQUAL lower_)
message(WARNING "Linear algebra libraries' mangling convention not specified; specify -DLINALG_MANGLING={lower,lower_,UPPER}, if needed; BLASPP will try to autodetect")
endif(NOT LINALG_MANGLING STREQUAL lower_)
# these were needed for some configs at some point in the past? But in most cases they just produce compile noise
# target_compile_definitions(blaspp PUBLIC -DBLAS_FORTRAN_ADD_=1)
# target_compile_definitions(lapackpp PUBLIC -DLAPACK_FORTRAN_ADD_=1)
endif()
endif (_linalgpp_use_standard_linalg_kits)
endif(NOT TARGET BTAS::BTAS)
# postcond check
if (NOT TARGET BTAS::BTAS)
message(FATAL_ERROR "FindOrFetchBTAS could not make BTAS::BTAS target available")
endif(NOT TARGET BTAS::BTAS)
# Treat BTAS headers as system: header-only library, no include-order
# risk against TA's headers, and BTAS upstream trips warnings TA itself
# can't fix (e.g. btas/generic/converge_class.h -Wreturn-type on gcc).
# Carved out specifically here despite the top-level
# CMAKE_NO_SYSTEM_FROM_IMPORTED=TRUE.
get_target_property(_btas_aliased BTAS::BTAS ALIASED_TARGET)
if (NOT _btas_aliased)
set(_btas_aliased BTAS::BTAS)
endif()
get_target_property(_btas_inc ${_btas_aliased} INTERFACE_INCLUDE_DIRECTORIES)
if (_btas_inc)
set_target_properties(${_btas_aliased} PROPERTIES
INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "${_btas_inc}")
endif()
unset(_btas_inc)
unset(_btas_aliased)