-
Notifications
You must be signed in to change notification settings - Fork 50
/
CMakeLists.txt
288 lines (259 loc) · 11 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
#/***************************************************************************
# *
# * @license
# * Copyright (C) Codeplay Software Limited
# * Licensed under the Apache License, Version 2.0 (the "License");
# * you may not use this file except in compliance with the License.
# * You may obtain a copy of the License at
# *
# * http://www.apache.org/licenses/LICENSE-2.0
# *
# * For your convenience, a copy of the License has been included in this
# * repository.
# *
# * Unless required by applicable law or agreed to in writing, software
# * distributed under the License is distributed on an "AS IS" BASIS,
# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# * See the License for the specific language governing permissions and
# * limitations under the License.
# *
# * portBLAS: BLAS implementation using SYCL
# *
# * @filename CMakeLists.txt
# *
# **************************************************************************/
cmake_minimum_required(VERSION 3.4.3)
project(portBLAS VERSION 0.1.0 LANGUAGES CXX)
if(POLICY CMP0074)
cmake_policy(SET CMP0074 NEW)
endif()
if(EXISTS ${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS NO_OUTPUT_DIRS)
# We copy the pkgconfig files here
list(APPEND CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR})
endif()
option(INSTALL_HEADER_ONLY "Install portBLAS as a header only library" OFF)
set(BUILD_SHARED_LIBS ON CACHE BOOL "")
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_POSITION_INDEPENDENT_CODE ${BUILD_SHARED_LIBS})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations -Wno-deprecated-copy-with-user-provided-copy")
if(DEFINED SYSTEM_BLAS_ROOT)
message(DEPRECATION
"SYSTEM_BLAS_ROOT is deprecated. Add the path to the reference BLAS to CMAKE_PREFIX_PATH instead")
list(INSERT CMAKE_PREFIX_PATH 0 ${SYSTEM_BLAS_ROOT})
endif()
list(APPEND CMAKE_MODULE_PATH
${CMAKE_CURRENT_SOURCE_DIR}/cmake/
${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules
)
# This turns the long file names that are generated into short versions using a hash
# This is required to build portBLAS on Windows and on WSL since Windows doesn't
# have good support for long file names
option(PORTBLAS_USE_SHORT_NAMES "Whether to use short names for generated files" OFF)
if (WIN32)
# On WIN32 we can force this option to be true, but when building on WSL this
# must be set in the command line
set(PORTBLAS_USE_SHORT_NAMES ON CACHE BOOL "Enable short names for generated files in Windows" FORCE)
endif()
# Setup datatypes, workgroup sizes and other options.
# NB: This has to be included before CmakeFunctionHelper as it declares various options.
if (NOT INSTALL_HEADER_ONLY)
include(ConfigurePORTBLAS)
include(SYCL)
find_package(PythonInterp 3 REQUIRED)
if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/external/py_gen/README.md" )
message(FATAL_ERROR "Repository not cloned recursively, missing submodule.\n"
"To continue please clone submodule using `git submodule update --init`")
endif()
endif()
if (MSVC)
# The device compiler needs C++14 to parse the Windows headers
set(BUILD_SHARED_LIBS FALSE CACHE BOOL
"Force portBLAS to be built as a static library on Windows"
FORCE
)
endif()
# By default, tall and skinny Gemm is enabled (for better performance)
option(GEMM_TALL_SKINNY_SUPPORT "Whether to enable tall and skinny Gemm" ON)
# By default vectorization in gemm kernels is enabled as it imrpove the performance on all Devices.
option(GEMM_VECTORIZATION_SUPPORT "Whether to enable vectorization in Gemm kernels" ON)
add_definitions(-DCL_TARGET_OPENCL_VERSION=220)
set(CBLAS_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/external/cblas/include)
set(PORTBLAS_GENERATED_SRC ${CMAKE_CURRENT_BINARY_DIR}/generated_src)
set(PORTBLAS_INCLUDE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
set(PORTBLAS_COMMON_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/common/include)
if(INSTALL_HEADER_ONLY)
set(PORTBLAS_INSTALL_SRC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src> $<INSTALL_INTERFACE:src>)
endif()
set(PORTBLAS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src)
set(PORTBLAS_SRC_GENERATOR ${CMAKE_CURRENT_SOURCE_DIR}/python_generator)
list(APPEND THIRD_PARTIES_INCLUDE ${CBLAS_INCLUDE})
option(BLAS_ENABLE_EXTENSIONS "Whether to enable portBLAS extensions" ON)
option(BLAS_ENABLE_COMPLEX "Whether to enable complex data type for GEMM" OFF)
option(BLAS_ENABLE_HALF "Whether to enable sycl::half data type for supported operators" OFF)
if (SYCL_COMPILER MATCHES "adaptivecpp")
if(BLAS_ENABLE_COMPLEX)
message(STATUS "SYCL Complex data is not supported on AdaptiveCpp/hipSYCL. Complex
data type is disabled")
set(BLAS_ENABLE_COMPLEX OFF)
endif()
if(BLAS_MEMPOOL_BENCHMARK)
message(STATUS "Memory pool feature is not supported on AdaptiveCpp/hipSYCL. Corresponding
benchmarks are disabled")
set(BLAS_MEMPOOL_BENCHMARK OFF)
endif()
endif()
# CmakeFunctionHelper has to be included after any options that it depends on are declared.
# These include:
# * TARGET
# * GEMM_TALL_SKINNY_SUPPORT
# * GEMM_VECTORIZATION_SUPPORT
# * BLAS_DATA_TYPES
# * BLAS_INDEX_TYPES
# * NAIVE_GEMM
# * BLAS_ENABLE_COMPLEX
# * BLAS_ENABLE_HALF
include(CmakeFunctionHelper)
if (INSTALL_HEADER_ONLY)
add_library(portblas INTERFACE)
set_target_properties(portblas PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${PORTBLAS_INCLUDE};${PORTBLAS_INSTALL_SRC}")
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag("-fsycl" is_dpcpp)
if(is_dpcpp)
target_compile_definitions(portblas INTERFACE "SB_ENABLE_USM")
check_cxx_compiler_flag("-mllvm=-enable-global-offset=false" support_disable_global_offset)
if (${support_disable_global_offset})
if ((${CMAKE_CXX_COMPILER_ID} STREQUAL "IntelLLVM"
AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 2024.1)
OR NOT ${CMAKE_CXX_COMPILER_ID} STREQUAL "IntelLLVM")
# Apply only for oneAPI releases >= 2024.1 OR for intel/llvm.
target_link_options(portblas INTERFACE "-mllvm=-enable-global-offset=false")
target_compile_options(portblas INTERFACE "-mllvm=-enable-global-offset=false")
message(STATUS "Adding -mllvm=-enable-global-offset=false to portblas")
endif()
endif()
endif()
if(${BLAS_ENABLE_COMPLEX})
target_compile_definitions(portblas INTERFACE "BLAS_ENABLE_COMPLEX")
endif()
target_compile_definitions(portblas INTERFACE ${TUNING_TARGET})
target_compile_options(portblas INTERFACE -Wno-deprecated-declarations)
target_compile_options(portblas INTERFACE -Wno-deprecated-copy-with-user-provided-copy)
if((${CMAKE_CXX_COMPILER_ID} STREQUAL "IntelLLVM") AND NOT
(${TUNING_TARGET} STREQUAL "INTEL_GPU") )
target_compile_options(portblas INTERFACE -fno-fast-math)
target_compile_options(portblas INTERFACE -mllvm=-loopopt=0)
target_link_options(portblas INTERFACE -mllvm=-loopopt=0)
message(STATUS "Adding -fno-fast-math -mllvm=-loopopt=0 to portblas")
endif()
else()
add_subdirectory(src)
build_library(portblas ${BLAS_ENABLE_EXTENSIONS})
if (WIN32)
# On Windows, all symbols must be resolved at link time for DLLs.
# The portblas target is just a collection of other objects so
# the linked libraries are not going to be propagated to this target.
# This requires manual linking against SYCL on Windows.
if(is_dpcpp)
target_link_libraries(portblas PUBLIC DPCPP::DPCPP)
elseif(is_adaptivecpp)
target_link_libraries(portblas PUBLIC AdaptiveCpp::acpp-rt)
endif()
endif()
if(is_dpcpp)
set(sycl_impl DPCPP::DPCPP)
add_sycl_to_target(TARGET portblas SOURCES)
elseif(is_adaptivecpp)
set(sycl_impl AdaptiveCpp::acpp-rt)
add_sycl_to_target(TARGET portblas SOURCES)
endif()
set_target_properties(portblas PROPERTIES
INTERFACE_LINK_LIBRARIES ${sycl_impl}
INTERFACE_INCLUDE_DIRECTORIES "${PORTBLAS_INCLUDE}"
)
set_target_properties(portblas PROPERTIES
VERSION ${PROJECT_VERSION}
)
endif()
include(CMakePackageConfigHelpers)
set(version_file "${CMAKE_CURRENT_BINARY_DIR}/cmake/portblas-version.cmake")
write_basic_package_version_file(${version_file}
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)
include(GNUInstallDirs)
install(TARGETS portblas
EXPORT portblas
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
install(DIRECTORY ${PORTBLAS_INCLUDE}
DESTINATION ${CMAKE_INSTALL_PREFIX}
COMPONENT portblas
FILES_MATCHING PATTERN "*.h"
)
if (INSTALL_HEADER_ONLY)
install(DIRECTORY ${PORTBLAS_INSTALL_SRC}
DESTINATION ${CMAKE_INSTALL_PREFIX}
COMPONENT portblas
FILES_MATCHING PATTERN "*.hpp"
)
endif()
install(FILES ${version_file} DESTINATION ${CMAKE_INSTALL_PREFIX})
install(EXPORT portblas
DESTINATION ${CMAKE_INSTALL_PREFIX}
NAMESPACE PORTBLAS::
FILE portblas-config.cmake
)
export(EXPORT portblas
NAMESPACE PORTBLAS::
FILE portblas-config.cmake
)
option(BLAS_ENABLE_TESTING "Whether to enable testing" ON)
option(ENABLE_EXPRESSION_TESTS "Whether to build expression tree fusion tests" OFF)
option(ENABLE_JOINTMATRIX_TESTS "Whether to build joint_matrix GEMM tests" OFF)
if (INSTALL_HEADER_ONLY AND BLAS_ENABLE_TESTING)
message(STATUS "Tests are disabled when installing portBLAS in header only mode")
set(BLAS_ENABLE_TESTING OFF)
endif()
if(${BLAS_ENABLE_TESTING})
enable_testing()
add_subdirectory(test)
endif()
option(BLAS_ENABLE_CONST_INPUT "Whether to enable kernel instantiation with const input buffer" ON)
option(BLAS_ENABLE_BENCHMARK "Whether to enable benchmarking" ON)
option(BLAS_VERIFY_BENCHMARK "Whether to verify the results of benchmarks" ON)
option(BLAS_MEMPOOL_BENCHMARK "Whether to use the memory pool in benchmarks" OFF)
option(BUILD_CLBLAST_BENCHMARKS "Whether to build clBLAST benchmarks" OFF)
option(BUILD_CLBLAS_BENCHMARKS "Whether to build clBLAS benchmarks" OFF)
option(BUILD_CUBLAS_BENCHMARKS "Whether to build cuBLAS benchmarks" OFF)
option(BUILD_ROCBLAS_BENCHMARKS "Whether to build rocBLAS benchmarks" OFF)
option(BUILD_ACL_BENCHMARKS "Whether to build ARM Compute Library benchmarks" OFF)
option(BLAS_BUILD_SAMPLES "Whether to build portBLAS samples" ON)
if (INSTALL_HEADER_ONLY AND BLAS_ENABLE_BENCHMARK)
message(STATUS "Benchmarks are disabled when installing portBLAS in header only mode")
set(BLAS_ENABLE_BENCHMARK OFF)
endif()
if (INSTALL_HEADER_ONLY AND BLAS_BUILD_SAMPLES)
message(STATUS "Samples are disabled when installing portBLAS in header only mode")
set(BLAS_BUILD_SAMPLES OFF)
endif()
if(${BLAS_ENABLE_BENCHMARK})
add_subdirectory(benchmark)
endif()
if (BLAS_BUILD_SAMPLES)
add_subdirectory(samples)
endif()
option(BLAS_ENABLE_AUTO_TUNERS "Whether to enable building GEMM auto tuners" OFF)
option(BLAS_ENABLE_AUTO_TUNER_MEMPOOL "Whether to enable memory pool for GEMM auto tuners" OFF)
if(${BLAS_ENABLE_AUTO_TUNERS})
# Note that the auto tuners are very slow to compile, so we avoid adding
# them to the ALL target.
add_subdirectory(tools/auto_tuner EXCLUDE_FROM_ALL)
endif()