-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
192 lines (174 loc) · 6.49 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
cmake_minimum_required(VERSION 3.22)
if (${CMAKE_VERSION} VERSION_GREATER "3.24")
# Set new FetchContent_Declare option DOWNLOAD_EXTRACT_TIMESTAMP to false
cmake_policy(SET CMP0135 NEW)
endif ()
project(aieblas CXX)
message(STATUS
"Using compiler ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}")
#####################
# Load dependencies #
#####################
include(FetchContent)
# JSON library from https://github.com/nlohmann/json
FetchContent_Declare(json URL
https://github.com/nlohmann/json/releases/download/v3.11.3/json.tar.xz
URL_HASH
SHA256=d6c65aca6b1ed68e7a182f4757257b107ae403032760ed6ef121c9d55e81757d
)
FetchContent_MakeAvailable(json)
# CLI options parser from https://github.com/jarro2783/cxxopts
FetchContent_Declare(cxxopts URL
GIT_REPOSITORY https://github.com/jarro2783/cxxopts.git
GIT_TAG 4bf61f08697b110d9e3991864650a405b3dd515d # v3.2.1
)
FetchContent_MakeAvailable(cxxopts)
################
# Common files #
################
set(AIEBLAS_SRC "${CMAKE_CURRENT_LIST_DIR}/src")
set(AIEBLAS_HDR "${CMAKE_CURRENT_LIST_DIR}/include")
set(AIEBLAS_INT_HDR "${AIEBLAS_HDR}/aieblas/detail")
set(AIEBLAS_COMMON_HEADERS
"${AIEBLAS_INT_HDR}/util.hpp"
"${AIEBLAS_INT_HDR}/util/cxx_compat.hpp"
"${AIEBLAS_INT_HDR}/util/logging.hpp"
)
set(AIEBLAS_COMMON_SRC
"${AIEBLAS_SRC}/util/logging.cpp"
)
set(AIEBLAS_CODEGEN_HEADERS
"${AIEBLAS_HDR}/aieblas/codegen.hpp"
"${AIEBLAS_INT_HDR}/codegen/datastructures.hpp"
"${AIEBLAS_INT_HDR}/codegen/generator.hpp"
"${AIEBLAS_INT_HDR}/codegen/json_parser.hpp"
"${AIEBLAS_INT_HDR}/codegen/json_parser/get_kernel_options.hpp"
"${AIEBLAS_INT_HDR}/codegen/kernels.hpp"
"${AIEBLAS_INT_HDR}/codegen/kernels/asum.hpp"
"${AIEBLAS_INT_HDR}/codegen/kernels/axpy.hpp"
"${AIEBLAS_INT_HDR}/codegen/kernels/dot.hpp"
"${AIEBLAS_INT_HDR}/codegen/kernels/gemv.hpp"
"${AIEBLAS_INT_HDR}/codegen/kernels/iamax.hpp"
"${AIEBLAS_INT_HDR}/codegen/kernels/nrm2.hpp"
"${AIEBLAS_INT_HDR}/codegen/kernels/rot.hpp"
"${AIEBLAS_INT_HDR}/codegen/kernels/scal.hpp"
"${AIEBLAS_INT_HDR}/codegen/kernels/parsers/asum.hpp"
"${AIEBLAS_INT_HDR}/codegen/kernels/parsers/axpy.hpp"
"${AIEBLAS_INT_HDR}/codegen/kernels/parsers/dot.hpp"
"${AIEBLAS_INT_HDR}/codegen/kernels/parsers/gemv.hpp"
"${AIEBLAS_INT_HDR}/codegen/kernels/parsers/iamax.hpp"
"${AIEBLAS_INT_HDR}/codegen/kernels/parsers/nrm2.hpp"
"${AIEBLAS_INT_HDR}/codegen/kernels/parsers/rot.hpp"
"${AIEBLAS_INT_HDR}/codegen/kernels/parsers/scal.hpp"
)
##################
# Define targets #
##################
add_library(codegen STATIC
"${AIEBLAS_SRC}/codegen/codegen.cpp"
"${AIEBLAS_SRC}/codegen/generator.cpp"
"${AIEBLAS_SRC}/codegen/cmake/generate_cmake.cpp"
"${AIEBLAS_SRC}/codegen/config/generate_config.cpp"
"${AIEBLAS_SRC}/codegen/graph/generate_graph.cpp"
"${AIEBLAS_SRC}/codegen/json_parser/get_kernel_options.cpp"
"${AIEBLAS_SRC}/codegen/json_parser/json_parser.cpp"
"${AIEBLAS_SRC}/codegen/kernels/generate_kernels.cpp"
"${AIEBLAS_SRC}/codegen/kernels/get_kernel_generator.cpp"
"${AIEBLAS_SRC}/codegen/kernels/impl/asum.cpp"
"${AIEBLAS_SRC}/codegen/kernels/impl/axpy.cpp"
"${AIEBLAS_SRC}/codegen/kernels/impl/dot.cpp"
"${AIEBLAS_SRC}/codegen/kernels/impl/gemv.cpp"
"${AIEBLAS_SRC}/codegen/kernels/impl/iamax.cpp"
"${AIEBLAS_SRC}/codegen/kernels/impl/nrm2.cpp"
"${AIEBLAS_SRC}/codegen/kernels/impl/rot.cpp"
"${AIEBLAS_SRC}/codegen/kernels/impl/scal.cpp"
"${AIEBLAS_SRC}/codegen/pl_kernels/generate_pl_kernels.cpp"
${AIEBLAS_COMMON_SRC}
${AIEBLAS_COMMON_HEADERS}
${AIEBLAS_CODEGEN_HEADERS}
)
add_executable(codegen_standalone
"${AIEBLAS_SRC}/codegen/standalone.cpp"
)
set_property(TARGET codegen_standalone PROPERTY OUTPUT_NAME codegen)
target_link_libraries(codegen PRIVATE
nlohmann_json::nlohmann_json
)
target_link_libraries(codegen_standalone PRIVATE
codegen
cxxopts::cxxopts
)
target_include_directories(codegen PUBLIC ${AIEBLAS_HDR})
###########################
# Set debug/warning flags #
###########################
target_compile_options(codegen PRIVATE
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:
-Wall
-Wextra
-pedantic
-Wno-unused-function
-Wno-unused-parameter
$<$<CONFIG:Debug>:-g3 -ggdb>
>
)
target_compile_options(codegen_standalone PRIVATE
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:
-Wall
-Wextra
-pedantic
-Wno-unused-function
-Wno-unused-parameter
$<$<CONFIG:Debug>:-g3 -ggdb>
>
)
######################################
# Set latest C++ versions to utilize #
# new features #
######################################
if (cxx_std_23 IN_LIST CMAKE_CXX_COMPILE_FEATURES)
message(STATUS "Using C++ 23 standard")
target_compile_features(codegen PUBLIC cxx_std_23)
set(DETECTED_CXX_STD "c++23")
elseif (cxx_std_20 IN_LIST CMAKE_CXX_COMPILE_FEATURES)
message(STATUS "Using C++ 20 standard")
target_compile_features(codegen PUBLIC cxx_std_20)
set(DETECTED_CXX_STD "c++20")
else ()
message(STATUS "Using C++ 17 standard")
target_compile_features(codegen PUBLIC cxx_std_17)
set(DETECTED_CXX_STD "c++17")
endif ()
######################################
# Check whether std::source_location #
# is supported #
######################################
include(cmake/check_source_code.cmake)
if (NOT CXX_HAS_SOURCE_LOCATION)
message(FATAL_ERROR
"AIE-BLAS requires a compiler with support for C++20 std::source_location")
endif ()
#####################################
# Fall back to {fmt} if std::format #
# is not available #
#####################################
include(cmake/check_format.cmake)
if (NOT CXX_HAS_FORMAT)
message(STATUS "Falling back to {fmt} library")
# std::format alternative from https://github.com/fmtlib/fmt
FetchContent_Declare(fmt URL
https://github.com/fmtlib/fmt/releases/download/10.2.1/fmt-10.2.1.zip
URL_HASH
SHA256=312151a2d13c8327f5c9c586ac6cf7cddc1658e8f53edae0ec56509c8fa516c9
)
FetchContent_GetProperties(fmt)
if (NOT fmt_POPULATED)
FetchContent_Populate(fmt)
endif ()
add_library(fmt_core OBJECT EXCLUDE_FROM_ALL
${fmt_SOURCE_DIR}/src/format.cc)
target_include_directories(fmt_core PUBLIC ${fmt_SOURCE_DIR}/include)
target_compile_features(fmt_core PUBLIC cxx_std_17)
target_link_libraries(codegen PRIVATE fmt_core)
target_link_libraries(codegen_standalone PRIVATE fmt_core)
endif ()