forked from codeplaysoftware/portDNN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
272 lines (247 loc) · 9.29 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
# Copyright Codeplay Software Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use these files except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# 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.
#
cmake_minimum_required(VERSION 3.10.2)
project(sycldnn LANGUAGES C CXX VERSION 0.6.0)
# Configuration options controlling automatic downloading of dependencies.
option(SNN_DOWNLOAD_GTEST
"Download and build google test, rather than use the system version" ON)
option(SNN_DOWNLOAD_BENCHMARK
"Download and build google benchmark, rather than use the system version" ON)
option(SNN_DOWNLOAD_EIGEN "Download Eigen headers" ON)
option(SNN_DOWNLOAD_SYCLBLAS "Download SYCL-BLAS repository" ON)
option(SNN_DOWNLOAD_MISSING_DEPS
"Download any dependencies which cannot be found" ON)
# Configuration options controlling which SYCL-DNN components are built.
option(SNN_BUILD_TESTS "Whether or not to build unit tests" ON)
option(SNN_BUILD_BENCHMARKS "Whether or not to build benchmarks" ON)
option(SNN_BUILD_INTERNAL_BENCHMARKS
"Whether or not to build internal benchmarks" OFF)
option(SNN_BUILD_EXTENDED_BENCHMARKS
"Whether or not to build a more comprehensive (but extremely time consuming) set of benchmarks" OFF)
option(SNN_BUILD_LARGE_BATCH_BENCHMARKS
"Whether or not to build benchmarks that use a batch sizes larger than 4" OFF)
option(SNN_BUILD_SAMPLES "Whether or not to build samples" ON)
option(SNN_BUILD_DOCUMENTATION "Whether or not to build documentation" ON)
# Configuration options controlling the installation of test and benchmark
# executables.
option(SNN_INSTALL_TESTS
"Whether or not to include unit tests when installing" OFF)
option(SNN_INSTALL_BENCHMARKS
"Whether or not to include benchmarks when installing" OFF)
option(SNN_INSTALL_SAMPLES
"Whether or not to include samples when installing" OFF)
option(SNN_FASTBUILD
"Disable setting the cmake build type if no flag specified" OFF)
# Testing configuration options
option(SNN_TEST_EIGEN "Test Eigen backend" OFF)
option(SNN_TEST_SYCLBLAS "Test SYCL-BLAS backend" OFF)
option(SNN_TEST_CLBLAST "Test CLBlast backend" OFF)
option(SNN_TEST_EIGEN_MATMULS
"Enable testing using Eigen matmul in addition to internal matmul" OFF)
option(SNN_TEST_SYCLBLAS_MATMULS
"Enable testing using SYCL-BLAS matmul in addition to internal matmul" OFF)
option(SNN_TEST_CLBLAST_MATMULS
"Enable testing using CLBlast matmul in addition to internal matmul" OFF)
# Eigen configuration options.
option(SNN_EIGEN_LOCAL_MEM
"Only compile the local memory versions of Eigen kernels" ON)
option(SNN_EIGEN_NO_LOCAL_MEM
"Only compile the no local memory versions of Eigen kernels" OFF)
option(SNN_EIGEN_COMPRESS_NAMES
"Compress Eigen SYCL kernel names" OFF)
option(SNN_EIGEN_NO_BARRIER
"Use Eigen matmul which does not use barriers (implies NO_LOCAL_MEM)" OFF)
# Benchmark configuration options
option(SNN_BENCH_EIGEN "Benchmark SYCL-DNN using Eigen" OFF)
option(SNN_BENCH_SYCLBLAS "Benchmark SYCL-DNN using SYCL-BLAS" ON)
option(SNN_BENCH_CLBLAST "Benchmark SYCL-DNN using CLBlast" OFF)
option(SNN_BENCH_SNN "Benchmark SYCL-DNN's own matmul" OFF)
option(SNN_BENCH_MKLDNN "Whether or not to build MKL-DNN benchmarks" OFF)
option(SNN_BENCH_ARM_COMPUTE
"Whether or not to build ARM compute library benchmarks" OFF)
set(SNN_DATA_TYPES float)
set(SNN_DATA_INT_TYPES uint8_t uint16_t uint32_t uint64_t)
set(SNN_INDEX_TYPES int32_t)
set(SNN_LAYOUTS NHWC)
option(SNN_ENABLE_DOUBLE "Enable double support for kernels and tests" OFF)
if(SNN_ENABLE_DOUBLE)
list(APPEND SNN_DATA_TYPES double)
add_definitions(-DSNN_USE_DOUBLE=1)
endif()
option(SNN_ENABLE_HALF "Enable half support for kernels and tests" OFF)
if(SNN_ENABLE_HALF)
list(APPEND SNN_DATA_TYPES cl::sycl::half)
add_definitions(-DSNN_USE_HALF=1)
endif()
option(SNN_ENABLE_NCHW "Enable NCHW support for kernels and tests" ON)
if (SNN_ENABLE_NCHW)
list(APPEND SNN_LAYOUTS NCHW)
add_definitions(-DSNN_ENABLE_NCHW=1)
endif()
option(SNN_ENABLE_64BIT_INDICES
"Enable using 64 bit indices for very large tensors" OFF)
if(SNN_ENABLE_64BIT_INDICES)
list(APPEND SNN_INDEX_TYPES int64_t)
add_definitions(-DSNN_USE_INT64=1)
endif()
option(SNN_CONV2D_DIRECT_STATIC_KERNELS
"Enable compiling static sizes of direct conv2d kernels" OFF)
if(SNN_CONV2D_DIRECT_STATIC_KERNELS)
add_definitions(-DSNN_CONV2D_STATIC_DIRECT=1)
endif()
option(SNN_REGISTER_TILE_SPECIALISATIONS
"Add specialisations to register tiles to help hoist to registers" OFF)
if(SNN_REGISTER_TILE_SPECIALISATIONS)
add_definitions(-DSNN_REGISTER_TILE_SPECIALISATIONS=1)
endif()
option(SNN_VISIBILITY_HIDDEN
"Set default visibility to hidden, reducing the number of exported symbols" ON)
if(SNN_VISIBILITY_HIDDEN)
set(CMAKE_CXX_VISIBILITY_PRESET "hidden")
set(CMAKE_VISIBILITY_INLINES_HIDDEN ON)
endif()
set(SNN_HIGH_MEM_JOB_LIMIT 8 CACHE STRING
"Number of concurrent build jobs for high memory targets (Ninja only)")
set_property(GLOBAL PROPERTY JOB_POOLS high_mem=${SNN_HIGH_MEM_JOB_LIMIT})
set(CMAKE_CXX_STANDARD 14)
set(CXX_STANDARD_REQUIRED ON)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules/")
if(NOT SNN_FASTBUILD)
include(DefaultBuildType)
endif()
find_package(ComputeCpp QUIET)
find_package(DPCPP QUIET)
if(ComputeCpp_FOUND AND DPCPP_FOUND)
message(FATAL_ERROR "Please choose one and only one SYCL implementation to use")
endif()
if(NOT ComputeCpp_FOUND AND NOT DPCPP_FOUND)
# Display warnings
find_package(ComputeCpp)
find_package(DPCPP)
message(FATAL_ERROR "No SYCL implementation found")
endif()
if(ComputeCpp_FOUND)
option(SNN_COMPUTECPP_USE_SERIAL_MEMOP
"Replace memory operations (eg memset) in kernels with serial operations." OFF)
if(NOT SNN_COMPUTECPP_USE_SERIAL_MEMOP)
list(APPEND COMPUTECPP_USER_FLAGS -no-serial-memop)
endif()
list(APPEND COMPUTECPP_USER_FLAGS -Xclang -cl-mad-enable)
list(APPEND COMPUTECPP_USER_FLAGS -Xclang -cl-no-signed-zeros)
elseif(DPCPP_FOUND)
if(${SNN_TEST_EIGEN} OR ${SNN_BENCH_EIGEN} OR
${SNN_TEST_EIGEN_MATMULS} OR ${SNN_DOWNLOAD_EIGEN})
message(WARNING "Eigen is not supported with DPC++ at the moment")
endif()
set(SNN_DOWNLOAD_EIGEN OFF)
set(SNN_BENCH_EIGEN OFF)
set(SNN_TEST_EIGEN OFF)
set(SNN_TEST_EIGEN_MATMULS OFF)
add_definitions(-DSNN_DISABLE_SYCL_PROGRAM)
endif()
set(CMAKE_DEBUG_POSTFIX "-debug")
set(include_dest "include")
set(library_dest "lib")
set(cmake_config_dest "${library_dest}/sycldnn/cmake")
set(runtime_dest "bin")
add_subdirectory(src)
if(SNN_BUILD_TESTS)
enable_testing()
add_subdirectory(test)
endif()
if(SNN_BUILD_BENCHMARKS)
enable_testing()
add_subdirectory(bench)
endif()
add_library(sycl_dnn SHARED
$<TARGET_OBJECTS:direct_conv2d>
$<TARGET_OBJECTS:tiled_conv2d>
$<TARGET_OBJECTS:im2col_conv2d>
$<TARGET_OBJECTS:winograd_conv2d>
$<TARGET_OBJECTS:depthwise_conv2d>
$<TARGET_OBJECTS:selector_conv2d>
$<TARGET_OBJECTS:pooling>
$<TARGET_OBJECTS:binaryop>
$<TARGET_OBJECTS:pointwise>
$<TARGET_OBJECTS:matmul>
$<TARGET_OBJECTS:transpose>
$<TARGET_OBJECTS:roi_align>
$<TARGET_OBJECTS:reduce>
$<TARGET_OBJECTS:scatter_nd>
$<TARGET_OBJECTS:gather>
)
snn_target(TARGET sycl_dnn WITH_SYCL)
set_target_properties(sycl_dnn PROPERTIES
OUTPUT_NAME "sycldnn"
VERSION ${sycldnn_VERSION}
SOVERSION ${sycldnn_VERSION}
)
add_library(sycl_dnn_static STATIC
$<TARGET_OBJECTS:direct_conv2d>
$<TARGET_OBJECTS:tiled_conv2d>
$<TARGET_OBJECTS:im2col_conv2d>
$<TARGET_OBJECTS:winograd_conv2d>
$<TARGET_OBJECTS:depthwise_conv2d>
$<TARGET_OBJECTS:selector_conv2d>
$<TARGET_OBJECTS:pooling>
$<TARGET_OBJECTS:binaryop>
$<TARGET_OBJECTS:pointwise>
$<TARGET_OBJECTS:matmul>
$<TARGET_OBJECTS:transpose>
$<TARGET_OBJECTS:roi_align>
$<TARGET_OBJECTS:reduce>
$<TARGET_OBJECTS:scatter_nd>
$<TARGET_OBJECTS:gather>
)
snn_target(TARGET sycl_dnn_static WITH_SYCL)
set_target_properties(sycl_dnn_static PROPERTIES
OUTPUT_NAME "sycldnn_static"
VERSION ${sycldnn_VERSION}
)
include(GenerateExportHeader)
generate_export_header(sycl_dnn
BASE_NAME "SNN"
EXPORT_FILE_NAME "sycldnn/export.h"
)
include(CMakePackageConfigHelpers)
set(version_file "${CMAKE_CURRENT_BINARY_DIR}/cmake/sycldnn-version.cmake")
write_basic_package_version_file(${version_file}
VERSION ${sycldnn_VERSION}
COMPATIBILITY AnyNewerVersion
)
install(TARGETS sycl_dnn sycl_dnn_static
EXPORT sycldnn
LIBRARY DESTINATION ${library_dest}
ARCHIVE DESTINATION ${library_dest}
PUBLIC_HEADER DESTINATION ${include_dest}
INCLUDES DESTINATION ${include_dest}
)
install(DIRECTORY include/sycldnn DESTINATION ${include_dest})
install(FILES ${version_file} DESTINATION ${cmake_config_dest})
install(FILES ${sycldnn_BINARY_DIR}/sycldnn/export.h DESTINATION ${include_dest}/sycldnn)
install(EXPORT sycldnn
DESTINATION ${cmake_config_dest}
NAMESPACE SYCLDNN::
FILE sycldnn-config.cmake
)
# Optionally build the samples.
if(SNN_BUILD_SAMPLES)
add_subdirectory(samples)
endif()
# Optionally build the documentation.
if(SNN_BUILD_DOCUMENTATION)
add_subdirectory(docs)
endif()