pytorch

Форк
0
/
Dependencies.cmake 
1695 строк · 62.7 Кб
1
# RPATH stuff
2
# see https://cmake.org/Wiki/CMake_RPATH_handling
3
if(APPLE)
4
  set(CMAKE_MACOSX_RPATH ON)
5
  set(_rpath_portable_origin "@loader_path")
6
else()
7
  set(_rpath_portable_origin $ORIGIN)
8
endif(APPLE)
9
# Use separate rpaths during build and install phases
10
set(CMAKE_SKIP_BUILD_RPATH  FALSE)
11
# Don't use the install-rpath during the build phase
12
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
13
set(CMAKE_INSTALL_RPATH "${_rpath_portable_origin}")
14
# Automatically add all linked folders that are NOT in the build directory to
15
# the rpath (per library?)
16
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
17

18
 # UBSAN triggers when compiling protobuf, so we need to disable it.
19
set(UBSAN_FLAG "-fsanitize=undefined")
20

21
macro(disable_ubsan)
22
  if(CMAKE_C_FLAGS MATCHES ${UBSAN_FLAG} OR CMAKE_CXX_FLAGS MATCHES ${UBSAN_FLAG})
23
    set(CAFFE2_UBSAN_ENABLED ON)
24
    string(REPLACE ${UBSAN_FLAG} "" CMAKE_C_FLAGS ${CMAKE_C_FLAGS})
25
    string(REPLACE ${UBSAN_FLAG} "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
26
  endif()
27
endmacro()
28

29
macro(enable_ubsan)
30
  if(CAFFE2_UBSAN_ENABLED)
31
    set(CMAKE_C_FLAGS "${UBSAN_FLAG} ${CMAKE_C_FLAGS}")
32
    set(CMAKE_CXX_FLAGS "${UBSAN_FLAG} ${CMAKE_CXX_FLAGS}")
33
  endif()
34
endmacro()
35

36
# ---[ CUDA
37
if(USE_CUDA)
38
  # public/*.cmake uses CAFFE2_USE_*
39
  set(CAFFE2_USE_CUDA ${USE_CUDA})
40
  set(CAFFE2_USE_CUDNN ${USE_CUDNN})
41
  set(CAFFE2_USE_CUSPARSELT ${USE_CUSPARSELT})
42
  set(CAFFE2_USE_CUFILE ${USE_CUFILE})
43
  set(CAFFE2_USE_NVRTC ${USE_NVRTC})
44
  include(${CMAKE_CURRENT_LIST_DIR}/public/cuda.cmake)
45
  if(CAFFE2_USE_CUDA)
46
    # A helper variable recording the list of Caffe2 dependent libraries
47
    # torch::cudart is dealt with separately, due to CUDA_ADD_LIBRARY
48
    # design reason (it adds CUDA_LIBRARIES itself).
49
    set(Caffe2_PUBLIC_CUDA_DEPENDENCY_LIBS )
50
    if(NOT CAFFE2_USE_NVRTC)
51
      caffe2_update_option(USE_NVRTC OFF)
52
    endif()
53
    list(APPEND Caffe2_CUDA_DEPENDENCY_LIBS caffe2::curand caffe2::cufft caffe2::cublas)
54
    if(CAFFE2_USE_CUDNN)
55
      list(APPEND Caffe2_CUDA_DEPENDENCY_LIBS torch::cudnn)
56
    else()
57
      caffe2_update_option(USE_CUDNN OFF)
58
    endif()
59
    if(CAFFE2_USE_CUSPARSELT)
60
      list(APPEND Caffe2_CUDA_DEPENDENCY_LIBS torch::cusparselt)
61
    else()
62
      caffe2_update_option(USE_CUSPARSELT OFF)
63
    endif()
64
    if(CAFFE2_USE_CUFILE)
65
      list(APPEND Caffe2_CUDA_DEPENDENCY_LIBS torch::cufile)
66
    endif()
67
    find_program(SCCACHE_EXECUTABLE sccache)
68
    if(SCCACHE_EXECUTABLE)
69
      # Using RSP/--options-file renders output noncacheable by sccache
70
      # as they fall under `multiple input files` non-cacheable rule
71
      set(CMAKE_CUDA_USE_RESPONSE_FILE_FOR_INCLUDES 0)
72
      set(CMAKE_CUDA_USE_RESPONSE_FILE_FOR_LIBRARIES 0)
73
      set(CMAKE_CUDA_USE_RESPONSE_FILE_FOR_OBJECTS 0)
74
    endif()
75
  else()
76
    message(WARNING
77
      "Not compiling with CUDA. Suppress this warning with "
78
      "-DUSE_CUDA=OFF.")
79
    caffe2_update_option(USE_CUDA OFF)
80
    caffe2_update_option(USE_CUDNN OFF)
81
    caffe2_update_option(USE_CUSPARSELT OFF)
82
    caffe2_update_option(USE_NVRTC OFF)
83
    set(CAFFE2_USE_CUDA OFF)
84
    set(CAFFE2_USE_CUDNN OFF)
85
    set(CAFFE2_USE_CUSPARSELT OFF)
86
    set(CAFFE2_USE_CUFILE OFF)
87
    set(CAFFE2_USE_NVRTC OFF)
88
  endif()
89
endif()
90

91
# ---[ XPU
92
if(USE_XPU)
93
  include(${CMAKE_CURRENT_LIST_DIR}/public/xpu.cmake)
94
  if(NOT PYTORCH_FOUND_XPU)
95
    message(WARNING "Not compiling with XPU. Could NOT find SYCL."
96
    "Suppress this warning with -DUSE_XPU=OFF.")
97
    caffe2_update_option(USE_XPU OFF)
98
  else()
99
    if(LINUX)
100
      string(APPEND CMAKE_CXX_FLAGS " -D__INTEL_PREVIEW_BREAKING_CHANGES")
101
    endif()
102
  endif()
103
endif()
104

105
# ---[ Custom Protobuf
106
if(CAFFE2_CMAKE_BUILDING_WITH_MAIN_REPO AND NOT INTERN_BUILD_MOBILE)
107
  disable_ubsan()
108
  include(${CMAKE_CURRENT_LIST_DIR}/ProtoBuf.cmake)
109
  enable_ubsan()
110
endif()
111

112
if(USE_ASAN OR USE_TSAN)
113
  find_package(Sanitizer REQUIRED)
114
  if(USE_ASAN)
115
    if(TARGET Sanitizer::address)
116
      list(APPEND Caffe2_DEPENDENCY_LIBS Sanitizer::address)
117
    else()
118
      message(WARNING "Not ASAN found. Suppress this warning with -DUSE_ASAN=OFF.")
119
      caffe2_update_option(USE_ASAN OFF)
120
    endif()
121
    if(TARGET Sanitizer::undefined)
122
      list(APPEND Caffe2_DEPENDENCY_LIBS Sanitizer::undefined)
123
    endif()
124
  endif()
125
  if(USE_TSAN)
126
    if(TARGET Sanitizer::thread)
127
      list(APPEND Caffe2_DEPENDENCY_LIBS Sanitizer::thread)
128
    else()
129
      message(WARNING "Not TSAN found. Suppress this warning with -DUSE_TSAN=OFF.")
130
      caffe2_update_option(USE_TSAN OFF)
131
    endif()
132
  endif()
133
endif()
134

135
# ---[ Threads
136
find_package(Threads REQUIRED)
137
if(TARGET Threads::Threads)
138
  list(APPEND Caffe2_DEPENDENCY_LIBS Threads::Threads)
139
else()
140
  message(FATAL_ERROR
141
      "Cannot find threading library. PyTorch requires Threads to compile.")
142
endif()
143

144
# ---[ protobuf
145
if(CAFFE2_CMAKE_BUILDING_WITH_MAIN_REPO)
146
  if(USE_LITE_PROTO)
147
    set(CAFFE2_USE_LITE_PROTO 1)
148
  endif()
149
endif()
150

151
# ---[ BLAS
152

153
set(AT_MKLDNN_ACL_ENABLED 0)
154
set(AT_MKLDNN_ENABLED 0)
155
set(AT_MKL_ENABLED 0)
156
# setting default preferred BLAS options if not already present.
157
if(NOT INTERN_BUILD_MOBILE)
158
  set(BLAS "MKL" CACHE STRING "Selected BLAS library")
159
else()
160
  set(BLAS "Eigen" CACHE STRING "Selected BLAS library")
161
  set(AT_MKLDNN_ENABLED 0)
162
  set(AT_MKL_ENABLED 0)
163
endif()
164
set_property(CACHE BLAS PROPERTY STRINGS "ATLAS;BLIS;Eigen;FLAME;Generic;MKL;OpenBLAS;vecLib")
165
message(STATUS "Trying to find preferred BLAS backend of choice: " ${BLAS})
166

167
if(BLAS STREQUAL "Eigen")
168
  # Eigen is header-only and we do not have any dependent libraries
169
  set(CAFFE2_USE_EIGEN_FOR_BLAS ON)
170
elseif(BLAS STREQUAL "ATLAS")
171
  find_package(Atlas REQUIRED)
172
  include_directories(SYSTEM ${ATLAS_INCLUDE_DIRS})
173
  list(APPEND Caffe2_DEPENDENCY_LIBS ${ATLAS_LIBRARIES})
174
  list(APPEND Caffe2_DEPENDENCY_LIBS cblas)
175
  set(BLAS_INFO "atlas")
176
  set(BLAS_FOUND 1)
177
  set(BLAS_LIBRARIES ${ATLAS_LIBRARIES} cblas)
178
elseif(BLAS STREQUAL "OpenBLAS")
179
  find_package(OpenBLAS REQUIRED)
180
  include_directories(SYSTEM ${OpenBLAS_INCLUDE_DIR})
181
  list(APPEND Caffe2_DEPENDENCY_LIBS ${OpenBLAS_LIB})
182
  set(BLAS_INFO "open")
183
  set(BLAS_FOUND 1)
184
  set(BLAS_LIBRARIES ${OpenBLAS_LIB})
185
elseif(BLAS STREQUAL "BLIS")
186
  find_package(BLIS REQUIRED)
187
  include_directories(SYSTEM ${BLIS_INCLUDE_DIR})
188
  list(APPEND Caffe2_DEPENDENCY_LIBS ${BLIS_LIB})
189
elseif(BLAS STREQUAL "MKL")
190
  if(BLAS_SET_BY_USER)
191
    find_package(MKL REQUIRED)
192
  else()
193
    find_package(MKL QUIET)
194
  endif()
195
  include(${CMAKE_CURRENT_LIST_DIR}/public/mkl.cmake)
196
  if(MKL_FOUND)
197
    message(STATUS "MKL libraries: ${MKL_LIBRARIES}")
198
    message(STATUS "MKL include directory: ${MKL_INCLUDE_DIR}")
199
    message(STATUS "MKL OpenMP type: ${MKL_OPENMP_TYPE}")
200
    message(STATUS "MKL OpenMP library: ${MKL_OPENMP_LIBRARY}")
201
    include_directories(AFTER SYSTEM ${MKL_INCLUDE_DIR})
202
    list(APPEND Caffe2_PUBLIC_DEPENDENCY_LIBS caffe2::mkl)
203
    set(CAFFE2_USE_MKL ON)
204
    set(BLAS_INFO "mkl")
205
    set(BLAS_FOUND 1)
206
    set(BLAS_LIBRARIES ${MKL_LIBRARIES})
207
  else()
208
    message(WARNING "MKL could not be found. Defaulting to Eigen")
209
    set(CAFFE2_USE_EIGEN_FOR_BLAS ON)
210
    set(CAFFE2_USE_MKL OFF)
211
  endif()
212
elseif(BLAS STREQUAL "NVPL")
213
  find_package(NVPL_BLAS REQUIRED)
214
  list(APPEND Caffe2_DEPENDENCY_LIBS nvpl::blas_lp64_omp)
215
  set(BLAS_INFO "nvpl")
216
  set(BLAS_FOUND 1)
217
  set(BLAS_USE_CBLAS_DOT TRUE)
218
elseif(BLAS STREQUAL "vecLib")
219
  find_package(vecLib REQUIRED)
220
  include_directories(SYSTEM ${vecLib_INCLUDE_DIR})
221
  list(APPEND Caffe2_DEPENDENCY_LIBS ${vecLib_LINKER_LIBS})
222
  set(BLAS_INFO "veclib")
223
  set(BLAS_FOUND 1)
224
  set(BLAS_LIBRARIES ${vecLib_LINKER_LIBS})
225
elseif(BLAS STREQUAL "FlexiBLAS")
226
  find_package(FlexiBLAS REQUIRED)
227
  include_directories(SYSTEM ${FlexiBLAS_INCLUDE_DIR})
228
  list(APPEND Caffe2_DEPENDENCY_LIBS ${FlexiBLAS_LIB})
229
elseif(BLAS STREQUAL "Generic")
230
  # On Debian family, the CBLAS ABIs have been merged into libblas.so
231
  if(ENV{GENERIC_BLAS_LIBRARIES} STREQUAL "")
232
    set(GENERIC_BLAS "blas")
233
  else()
234
    set(GENERIC_BLAS $ENV{GENERIC_BLAS_LIBRARIES})
235
  endif()
236
  find_library(BLAS_LIBRARIES NAMES ${GENERIC_BLAS})
237
  message("-- Using BLAS: ${BLAS_LIBRARIES}")
238
  list(APPEND Caffe2_DEPENDENCY_LIBS ${BLAS_LIBRARIES})
239
  set(GENERIC_BLAS_FOUND TRUE)
240
  set(BLAS_INFO "generic")
241
  set(BLAS_FOUND 1)
242
else()
243
  message(FATAL_ERROR "Unrecognized BLAS option: " ${BLAS})
244
endif()
245

246
if(NOT INTERN_BUILD_MOBILE)
247
  set(AT_MKL_SEQUENTIAL 0)
248
  set(USE_BLAS 1)
249
  if(NOT (ATLAS_FOUND OR BLIS_FOUND OR GENERIC_BLAS_FOUND OR MKL_FOUND OR OpenBLAS_FOUND OR VECLIB_FOUND OR FlexiBLAS_FOUND OR NVPL_BLAS_FOUND))
250
    message(WARNING "Preferred BLAS (" ${BLAS} ") cannot be found, now searching for a general BLAS library")
251
    find_package(BLAS)
252
    if(NOT BLAS_FOUND)
253
      set(USE_BLAS 0)
254
    endif()
255
  endif()
256

257
  if(MKL_FOUND)
258
    if("${MKL_THREADING}" STREQUAL "SEQ")
259
      set(AT_MKL_SEQUENTIAL 1)
260
    endif()
261
    set(AT_MKL_ENABLED 1)
262
  endif()
263
elseif(INTERN_USE_EIGEN_BLAS)
264
  # Eigen BLAS for Mobile
265
  set(USE_BLAS 1)
266
  include(${CMAKE_CURRENT_LIST_DIR}/External/EigenBLAS.cmake)
267
  list(APPEND Caffe2_DEPENDENCY_LIBS eigen_blas)
268
endif()
269

270
# --- [ PocketFFT
271
set(AT_POCKETFFT_ENABLED 0)
272
if(NOT AT_MKL_ENABLED)
273
  set(POCKETFFT_INCLUDE_DIR "${Torch_SOURCE_DIR}/third_party/pocketfft/")
274
  if(NOT EXISTS "${POCKETFFT_INCLUDE_DIR}")
275
    message(FATAL_ERROR "pocketfft directory not found, expected ${POCKETFFT_INCLUDE_DIR}")
276
  elif(NOT EXISTS "${POCKETFFT_INCLUDE_DIR}/pocketfft_hdronly.h")
277
    message(FATAL_ERROR "pocketfft headers not found in ${POCKETFFT_INCLUDE_DIR}")
278
  endif()
279

280
  set(AT_POCKETFFT_ENABLED 1)
281
  message(STATUS "Using pocketfft in directory: ${POCKETFFT_INCLUDE_DIR}")
282
endif()
283

284
# ---[ Dependencies
285
# NNPACK and family (QNNPACK, PYTORCH_QNNPACK, and XNNPACK) can download and
286
# compile their dependencies in isolation as part of their build.  These dependencies
287
# are then linked statically with PyTorch.  To avoid the possibility of a version
288
# mismatch between these shared dependencies, explicitly declare our intent to these
289
# libraries that we are interested in using the exact same source dependencies for all.
290

291
if(USE_NNPACK OR USE_PYTORCH_QNNPACK OR USE_XNNPACK)
292
  set(DISABLE_NNPACK_AND_FAMILY OFF)
293

294
  # Sanity checks - Can we actually build NNPACK and family given the configuration provided?
295
  # Disable them and warn the user if not.
296

297
  if(IOS)
298
    list(LENGTH IOS_ARCH IOS_ARCH_COUNT)
299
    if(IOS_ARCH_COUNT GREATER 1)
300
      message(WARNING
301
        "Multi-architecture (${IOS_ARCH}) builds are not supported in {Q/X}NNPACK. "
302
        "Specify a single architecture in IOS_ARCH and re-configure, or "
303
        "turn this warning off by USE_{Q/X}NNPACK=OFF.")
304
      set(DISABLE_NNPACK_AND_FAMILY ON)
305
    endif()
306
    if(NOT IOS_ARCH MATCHES "^(i386|x86_64|armv7.*|arm64.*)$")
307
      message(WARNING
308
        "Target architecture \"${IOS_ARCH}\" is not supported in {Q/X}NNPACK. "
309
        "Supported architectures are x86, x86-64, ARM, and ARM64. "
310
        "Turn this warning off by USE_{Q/X}NNPACK=OFF.")
311
      set(DISABLE_NNPACK_AND_FAMILY ON)
312
    endif()
313
  else()
314
    if(NOT IOS AND NOT (CMAKE_SYSTEM_NAME MATCHES "^(Android|Linux|Darwin|Windows)$"))
315
      message(WARNING
316
        "Target platform \"${CMAKE_SYSTEM_NAME}\" is not supported in {Q/X}NNPACK. "
317
        "Supported platforms are Android, iOS, Linux, and macOS. "
318
        "Turn this warning off by USE_{Q/X}NNPACK=OFF.")
319
      set(DISABLE_NNPACK_AND_FAMILY ON)
320
    endif()
321
    if(NOT IOS AND NOT (CMAKE_SYSTEM_PROCESSOR MATCHES "^(i686|AMD64|x86_64|armv[0-9].*|arm64|aarch64)$"))
322
      message(WARNING
323
        "Target architecture \"${CMAKE_SYSTEM_PROCESSOR}\" is not supported in {Q/X}NNPACK. "
324
        "Supported architectures are x86, x86-64, ARM, and ARM64. "
325
        "Turn this warning off by USE_{Q/X}NNPACK=OFF.")
326
      set(DISABLE_NNPACK_AND_FAMILY ON)
327
    endif()
328
  endif()
329

330
  if(DISABLE_NNPACK_AND_FAMILY)
331
    caffe2_update_option(USE_NNPACK OFF)
332
    caffe2_update_option(USE_PYTORCH_QNNPACK OFF)
333
    caffe2_update_option(USE_XNNPACK OFF)
334
  else()
335
    # Disable unsupported NNPack combinations with MSVC
336
    if(MSVC)
337
      caffe2_update_option(USE_NNPACK OFF)
338
      caffe2_update_option(USE_PYTORCH_QNNPACK OFF)
339
    endif()
340

341
    set(CAFFE2_THIRD_PARTY_ROOT "${PROJECT_SOURCE_DIR}/third_party")
342

343
    if(NOT DEFINED CPUINFO_SOURCE_DIR)
344
      set(CPUINFO_SOURCE_DIR "${CAFFE2_THIRD_PARTY_ROOT}/cpuinfo" CACHE STRING "cpuinfo source directory")
345
    endif()
346
    if(NOT DEFINED FP16_SOURCE_DIR)
347
      set(FP16_SOURCE_DIR "${CAFFE2_THIRD_PARTY_ROOT}/FP16" CACHE STRING "FP16 source directory")
348
    endif()
349
    if(NOT DEFINED FXDIV_SOURCE_DIR)
350
      set(FXDIV_SOURCE_DIR "${CAFFE2_THIRD_PARTY_ROOT}/FXdiv" CACHE STRING "FXdiv source directory")
351
    endif()
352
    if(NOT DEFINED PSIMD_SOURCE_DIR)
353
      set(PSIMD_SOURCE_DIR "${CAFFE2_THIRD_PARTY_ROOT}/psimd" CACHE STRING "PSimd source directory")
354
    endif()
355
    if(NOT DEFINED PTHREADPOOL_SOURCE_DIR)
356
      set(PTHREADPOOL_SOURCE_DIR "${CAFFE2_THIRD_PARTY_ROOT}/pthreadpool" CACHE STRING "pthreadpool source directory")
357
    endif()
358
  endif()
359
else()
360
  set(DISABLE_NNPACK_AND_FAMILY ON)
361
endif()
362

363
set(CONFU_DEPENDENCIES_SOURCE_DIR ${PROJECT_BINARY_DIR}/confu-srcs
364
  CACHE PATH "Confu-style dependencies source directory")
365
set(CONFU_DEPENDENCIES_BINARY_DIR ${PROJECT_BINARY_DIR}/confu-deps
366
  CACHE PATH "Confu-style dependencies binary directory")
367

368
# ---[ pthreadpool
369
# Only add a dependency on pthreadpool if we are on a mobile build
370
# or are building any of the libraries in the {Q/X}NNPACK family.
371
if(INTERN_BUILD_MOBILE OR NOT DISABLE_NNPACK_AND_FAMILY)
372
  set(USE_PTHREADPOOL ON CACHE BOOL "" FORCE)
373
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_PTHREADPOOL")
374

375
  # Always use third_party/pthreadpool.
376
  set(USE_INTERNAL_PTHREADPOOL_IMPL OFF CACHE BOOL "" FORCE)
377

378
  if(NOT TARGET pthreadpool)
379
    if(USE_SYSTEM_PTHREADPOOL)
380
      add_library(pthreadpool SHARED IMPORTED)
381
      find_library(PTHREADPOOL_LIBRARY pthreadpool)
382
      set_property(TARGET pthreadpool PROPERTY IMPORTED_LOCATION "${PTHREADPOOL_LIBRARY}")
383
      if(NOT PTHREADPOOL_LIBRARY)
384
        message(FATAL_ERROR "Cannot find pthreadpool")
385
      endif()
386
      message("-- Found pthreadpool: ${PTHREADPOOL_LIBRARY}")
387
    elseif(NOT USE_INTERNAL_PTHREADPOOL_IMPL)
388
      if(NOT DEFINED PTHREADPOOL_SOURCE_DIR)
389
        set(CAFFE2_THIRD_PARTY_ROOT "${PROJECT_SOURCE_DIR}/third_party")
390
        set(PTHREADPOOL_SOURCE_DIR "${CAFFE2_THIRD_PARTY_ROOT}/pthreadpool" CACHE STRING "pthreadpool source directory")
391
      endif()
392

393
      set(PTHREADPOOL_BUILD_TESTS OFF CACHE BOOL "")
394
      set(PTHREADPOOL_BUILD_BENCHMARKS OFF CACHE BOOL "")
395
      set(PTHREADPOOL_LIBRARY_TYPE "static" CACHE STRING "")
396
      set(PTHREADPOOL_ALLOW_DEPRECATED_API ON CACHE BOOL "")
397
      add_subdirectory(
398
        "${PTHREADPOOL_SOURCE_DIR}"
399
        "${CONFU_DEPENDENCIES_BINARY_DIR}/pthreadpool")
400
      set_property(TARGET pthreadpool PROPERTY POSITION_INDEPENDENT_CODE ON)
401
    endif()
402

403
    if(USE_INTERNAL_PTHREADPOOL_IMPL)
404
      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_INTERNAL_PTHREADPOOL_IMPL")
405
    else()
406
      list(APPEND Caffe2_DEPENDENCY_LIBS pthreadpool)
407
    endif()
408
  endif()
409
else()
410
  set(USE_PTHREADPOOL OFF CACHE BOOL "" FORCE)
411
endif()
412

413
if(NOT CMAKE_SYSTEM_PROCESSOR MATCHES "^(s390x|ppc64le)$")
414
  # ---[ Caffe2 uses cpuinfo library in the thread pool
415
  # ---[ But it doesn't support s390x/powerpc and thus not used on s390x/powerpc
416
  if(NOT TARGET cpuinfo AND USE_SYSTEM_CPUINFO)
417
    add_library(cpuinfo SHARED IMPORTED)
418
    find_library(CPUINFO_LIBRARY cpuinfo)
419
    if(NOT CPUINFO_LIBRARY)
420
      message(FATAL_ERROR "Cannot find cpuinfo")
421
    endif()
422
    message("Found cpuinfo: ${CPUINFO_LIBRARY}")
423
    set_target_properties(cpuinfo PROPERTIES IMPORTED_LOCATION "${CPUINFO_LIBRARY}")
424
  elseif(NOT TARGET cpuinfo)
425
    if(NOT DEFINED CPUINFO_SOURCE_DIR)
426
      set(CPUINFO_SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/../third_party/cpuinfo" CACHE STRING "cpuinfo source directory")
427
    endif()
428

429
    set(CPUINFO_BUILD_TOOLS OFF CACHE BOOL "")
430
    set(CPUINFO_BUILD_UNIT_TESTS OFF CACHE BOOL "")
431
    set(CPUINFO_BUILD_MOCK_TESTS OFF CACHE BOOL "")
432
    set(CPUINFO_BUILD_BENCHMARKS OFF CACHE BOOL "")
433
    set(CPUINFO_LIBRARY_TYPE "static" CACHE STRING "")
434
    set(CPUINFO_LOG_LEVEL "error" CACHE STRING "")
435
    if(MSVC)
436
      if(CAFFE2_USE_MSVC_STATIC_RUNTIME)
437
        set(CPUINFO_RUNTIME_TYPE "static" CACHE STRING "")
438
      else()
439
        set(CPUINFO_RUNTIME_TYPE "shared" CACHE STRING "")
440
      endif()
441
    endif()
442
    add_subdirectory(
443
      "${CPUINFO_SOURCE_DIR}"
444
      "${CONFU_DEPENDENCIES_BINARY_DIR}/cpuinfo")
445
    # We build static version of cpuinfo but link
446
    # them into a shared library for Caffe2, so they need PIC.
447
    set_property(TARGET cpuinfo PROPERTY POSITION_INDEPENDENT_CODE ON)
448
  endif()
449
  list(APPEND Caffe2_DEPENDENCY_LIBS cpuinfo)
450
endif()
451

452

453
# ---[ PYTORCH_QNNPACK
454
set(CAFFE2_THIRD_PARTY_ROOT "${PROJECT_SOURCE_DIR}/third_party")
455
if(USE_PYTORCH_QNNPACK)
456
    if(NOT DEFINED PYTORCH_QNNPACK_SOURCE_DIR)
457
      set(PYTORCH_QNNPACK_SOURCE_DIR "${PROJECT_SOURCE_DIR}/aten/src/ATen/native/quantized/cpu/qnnpack" CACHE STRING "QNNPACK source directory")
458
    endif()
459

460
    if(NOT TARGET pytorch_qnnpack)
461
      if(NOT USE_SYSTEM_PTHREADPOOL AND USE_INTERNAL_PTHREADPOOL_IMPL)
462
        set(PYTORCH_QNNPACK_CUSTOM_THREADPOOL ON CACHE BOOL "")
463
      endif()
464

465
      set(PYTORCH_QNNPACK_BUILD_TESTS OFF CACHE BOOL "")
466
      set(PYTORCH_QNNPACK_BUILD_BENCHMARKS OFF CACHE BOOL "")
467
      set(PYTORCH_QNNPACK_LIBRARY_TYPE "static" CACHE STRING "")
468
      add_subdirectory(
469
        "${PYTORCH_QNNPACK_SOURCE_DIR}"
470
        "${CONFU_DEPENDENCIES_BINARY_DIR}/pytorch_qnnpack")
471
      # We build static versions of QNNPACK and pthreadpool but link
472
      # them into a shared library for Caffe2, so they need PIC.
473
      set_property(TARGET pytorch_qnnpack PROPERTY POSITION_INDEPENDENT_CODE ON)
474
      set_property(TARGET cpuinfo PROPERTY POSITION_INDEPENDENT_CODE ON)
475
      # QNNPACK depends on gemmlowp headers
476
      target_include_directories(pytorch_qnnpack PRIVATE "${CAFFE2_THIRD_PARTY_ROOT}/gemmlowp")
477

478
      if(PYTORCH_QNNPACK_CUSTOM_THREADPOOL)
479
        target_compile_definitions(
480
          pytorch_qnnpack PRIVATE
481
          pthreadpool_t=legacy_pthreadpool_t
482
          pthreadpool_function_1d_t=legacy_pthreadpool_function_1d_t
483
          pthreadpool_function_1d_tiled_t=legacy_pthreadpool_function_1d_tiled_t
484
          pthreadpool_function_2d_t=legacy_pthreadpool_function_2d_t
485
          pthreadpool_function_2d_tiled_t=legacy_pthreadpool_function_2d_tiled_t
486
          pthreadpool_function_3d_tiled_t=legacy_pthreadpool_function_3d_tiled_t
487
          pthreadpool_function_4d_tiled_t=legacy_pthreadpool_function_4d_tiled_t
488
          pthreadpool_create=legacy_pthreadpool_create
489
          pthreadpool_destroy=legacy_pthreadpool_destroy
490
          pthreadpool_get_threads_count=legacy_pthreadpool_get_threads_count
491
          pthreadpool_compute_1d=legacy_pthreadpool_compute_1d
492
          pthreadpool_parallelize_1d=legacy_pthreadpool_parallelize_1d
493
          pthreadpool_compute_1d_tiled=legacy_pthreadpool_compute_1d_tiled
494
          pthreadpool_compute_2d=legacy_pthreadpool_compute_2d
495
          pthreadpool_compute_2d_tiled=legacy_pthreadpool_compute_2d_tiled
496
          pthreadpool_compute_3d_tiled=legacy_pthreadpool_compute_3d_tiled
497
          pthreadpool_compute_4d_tiled=legacy_pthreadpool_compute_4d_tiled)
498
      endif()
499
    endif()
500

501
    list(APPEND Caffe2_DEPENDENCY_LIBS pytorch_qnnpack)
502
endif()
503

504
# ---[ NNPACK
505
if(USE_NNPACK)
506
  include(${CMAKE_CURRENT_LIST_DIR}/External/nnpack.cmake)
507
  if(NNPACK_FOUND)
508
    if(TARGET nnpack)
509
      # ---[ NNPACK is being built together with Caffe2: explicitly specify dependency
510
      list(APPEND Caffe2_DEPENDENCY_LIBS nnpack)
511
    else()
512
      include_directories(SYSTEM ${NNPACK_INCLUDE_DIRS})
513
      list(APPEND Caffe2_DEPENDENCY_LIBS ${NNPACK_LIBRARIES})
514
    endif()
515
  else()
516
    message(WARNING "Not compiling with NNPACK. Suppress this warning with -DUSE_NNPACK=OFF")
517
    caffe2_update_option(USE_NNPACK OFF)
518
  endif()
519
endif()
520

521
# ---[ XNNPACK
522
if(USE_XNNPACK AND NOT USE_SYSTEM_XNNPACK)
523
  if(NOT DEFINED XNNPACK_SOURCE_DIR)
524
    set(XNNPACK_SOURCE_DIR "${CAFFE2_THIRD_PARTY_ROOT}/XNNPACK" CACHE STRING "XNNPACK source directory")
525
  endif()
526

527
  if(NOT DEFINED XNNPACK_INCLUDE_DIR)
528
    set(XNNPACK_INCLUDE_DIR "${XNNPACK_SOURCE_DIR}/include" CACHE STRING "XNNPACK include directory")
529
  endif()
530

531
  if(NOT TARGET XNNPACK)
532
    set(XNNPACK_LIBRARY_TYPE "static" CACHE STRING "")
533
    set(XNNPACK_BUILD_BENCHMARKS OFF CACHE BOOL "")
534
    set(XNNPACK_BUILD_TESTS OFF CACHE BOOL "")
535

536
    # Disable ARM BF16 and FP16 vector for now; unused and causes build failures because
537
    # these new ISA features may not be supported on older compilers
538
    set(XNNPACK_ENABLE_ARM_BF16 OFF CACHE BOOL "")
539

540
    # Disable AVXVNNI for now, older clang versions seem not to support it
541
    # (clang 12 is where avx-vnni support is added)
542
    set(XNNPACK_ENABLE_AVXVNNI OFF CACHE BOOL "")
543

544
    # Disable I8MM For CI since clang 9 does not support neon i8mm.
545
    set(XNNPACK_ENABLE_ARM_I8MM OFF CACHE BOOL "")
546

547
    # Older MSVC versions don't support AVX512FP. TODO Minimum version support?
548
    IF(CMAKE_C_COMPILER_ID STREQUAL "MSVC")
549
      set(XNNPACK_ENABLE_AVX512FP16  OFF CACHE BOOL "")
550
    ENDIF()
551

552
    # Conditionally disable AVX512AMX, as it requires Clang 11 or later. Note that
553
    # XNNPACK does conditionally compile this based on GCC version. Once it also does
554
    # so based on Clang version, this logic can be removed.
555
    IF(CMAKE_C_COMPILER_ID STREQUAL "Clang")
556
      IF(CMAKE_C_COMPILER_VERSION VERSION_LESS "11")
557
        set(XNNPACK_ENABLE_AVX512AMX OFF CACHE BOOL "")
558
      ENDIF()
559
    ENDIF()
560

561
    # Setting this global PIC flag for all XNNPACK targets.
562
    # This is needed for Object libraries within XNNPACK which must
563
    # be PIC to successfully link this static libXNNPACK with pytorch
564
    set(__caffe2_CMAKE_POSITION_INDEPENDENT_CODE_FLAG ${CMAKE_POSITION_INDEPENDENT_CODE})
565
    set(CMAKE_POSITION_INDEPENDENT_CODE ON)
566

567
    add_subdirectory(
568
      "${XNNPACK_SOURCE_DIR}"
569
      "${CONFU_DEPENDENCIES_BINARY_DIR}/XNNPACK")
570

571
    # Revert to whatever it was before
572
    set(CMAKE_POSITION_INDEPENDENT_CODE ${__caffe2_CMAKE_POSITION_INDEPENDENT_CODE_FLAG})
573
  endif()
574

575
  include_directories(SYSTEM ${XNNPACK_INCLUDE_DIR})
576
  list(APPEND Caffe2_DEPENDENCY_LIBS XNNPACK)
577
elseif(NOT TARGET XNNPACK AND USE_SYSTEM_XNNPACK)
578
  add_library(XNNPACK SHARED IMPORTED)
579
  find_library(XNNPACK_LIBRARY XNNPACK)
580
  set_property(TARGET XNNPACK PROPERTY IMPORTED_LOCATION "${XNNPACK_LIBRARY}")
581
  if(NOT XNNPACK_LIBRARY)
582
    message(FATAL_ERROR "Cannot find XNNPACK")
583
  endif()
584
  message("-- Found XNNPACK: ${XNNPACK_LIBRARY}")
585
  list(APPEND Caffe2_DEPENDENCY_LIBS XNNPACK)
586
endif()
587

588
# ---[ Vulkan deps
589
if(USE_VULKAN)
590
  set(Vulkan_DEFINES)
591
  set(Vulkan_INCLUDES)
592
  set(Vulkan_LIBS)
593
  include(${CMAKE_CURRENT_LIST_DIR}/VulkanDependencies.cmake)
594
  string(APPEND CMAKE_CXX_FLAGS ${Vulkan_DEFINES})
595
  include_directories(SYSTEM ${Vulkan_INCLUDES})
596
  list(APPEND Caffe2_DEPENDENCY_LIBS ${Vulkan_LIBS})
597
endif()
598

599
# ---[ gflags
600
if(USE_GFLAGS)
601
  include(${CMAKE_CURRENT_LIST_DIR}/public/gflags.cmake)
602
  if(NOT TARGET gflags)
603
    message(WARNING
604
        "gflags is not found. Caffe2 will build without gflags support but "
605
        "it is strongly recommended that you install gflags. Suppress this "
606
        "warning with -DUSE_GFLAGS=OFF")
607
    caffe2_update_option(USE_GFLAGS OFF)
608
  endif()
609
endif()
610

611
# ---[ Google-glog
612
if(USE_GLOG)
613
  include(${CMAKE_CURRENT_LIST_DIR}/public/glog.cmake)
614
  if(TARGET glog::glog)
615
    set(CAFFE2_USE_GOOGLE_GLOG 1)
616
  else()
617
    message(WARNING
618
        "glog is not found. Caffe2 will build without glog support but it is "
619
        "strongly recommended that you install glog. Suppress this warning "
620
        "with -DUSE_GLOG=OFF")
621
    caffe2_update_option(USE_GLOG OFF)
622
  endif()
623
endif()
624

625

626
# ---[ Googletest and benchmark
627
if(BUILD_TEST OR BUILD_MOBILE_BENCHMARK OR BUILD_MOBILE_TEST)
628
  # Preserve build options.
629
  set(TEMP_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS})
630

631
  # We will build gtest as static libs and embed it directly into the binary.
632
  set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared libs" FORCE)
633

634
  # For gtest, we will simply embed it into our test binaries, so we won't
635
  # need to install it.
636
  set(INSTALL_GTEST OFF CACHE BOOL "Install gtest." FORCE)
637
  set(BUILD_GMOCK ON CACHE BOOL "Build gmock." FORCE)
638
  # For Windows, we will check the runtime used is correctly passed in.
639
  if(NOT CAFFE2_USE_MSVC_STATIC_RUNTIME)
640
      set(gtest_force_shared_crt ON CACHE BOOL "force shared crt on gtest" FORCE)
641
  endif()
642
  # We need to replace googletest cmake scripts too.
643
  # Otherwise, it will sometimes break the build.
644
  # To make the git clean after the build, we make a backup first.
645
  if((MSVC AND MSVC_Z7_OVERRIDE) OR USE_CUDA)
646
    execute_process(
647
      COMMAND ${CMAKE_COMMAND}
648
              "-DFILENAME=${CMAKE_CURRENT_LIST_DIR}/../third_party/googletest/googletest/cmake/internal_utils.cmake"
649
              "-DBACKUP=${CMAKE_CURRENT_LIST_DIR}/../third_party/googletest/googletest/cmake/internal_utils.cmake.bak"
650
              "-DREVERT=0"
651
              "-P"
652
              "${CMAKE_CURRENT_LIST_DIR}/GoogleTestPatch.cmake"
653
      RESULT_VARIABLE _exitcode)
654
    if(NOT _exitcode EQUAL 0)
655
      message(WARNING "Patching failed for Google Test. The build may fail.")
656
    endif()
657
  endif()
658

659
  # Add googletest subdirectory but make sure our INCLUDE_DIRECTORIES
660
  # don't bleed into it. This is because libraries installed into the root conda
661
  # env (e.g. MKL) add a global /opt/conda/include directory, and if there's
662
  # gtest installed in conda, the third_party/googletest/**.cc source files
663
  # would try to include headers from /opt/conda/include/gtest/**.h instead of
664
  # its own. Once we have proper target-based include directories,
665
  # this shouldn't be necessary anymore.
666
  get_property(INC_DIR_temp DIRECTORY PROPERTY INCLUDE_DIRECTORIES)
667
  set_property(DIRECTORY PROPERTY INCLUDE_DIRECTORIES "")
668
  add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../third_party/googletest)
669
  set_property(DIRECTORY PROPERTY INCLUDE_DIRECTORIES ${INC_DIR_temp})
670

671
  include_directories(BEFORE SYSTEM ${CMAKE_CURRENT_LIST_DIR}/../third_party/googletest/googletest/include)
672
  include_directories(BEFORE SYSTEM ${CMAKE_CURRENT_LIST_DIR}/../third_party/googletest/googlemock/include)
673

674
  # We will not need to test benchmark lib itself.
675
  set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "Disable benchmark testing as we don't need it.")
676
  # We will not need to install benchmark since we link it statically.
677
  set(BENCHMARK_ENABLE_INSTALL OFF CACHE BOOL "Disable benchmark install to avoid overwriting vendor install.")
678
  if(NOT USE_SYSTEM_BENCHMARK)
679
    add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../third_party/benchmark)
680
  else()
681
    add_library(benchmark SHARED IMPORTED)
682
    find_library(BENCHMARK_LIBRARY benchmark)
683
    if(NOT BENCHMARK_LIBRARY)
684
      message(FATAL_ERROR "Cannot find google benchmark library")
685
    endif()
686
    message("-- Found benchmark: ${BENCHMARK_LIBRARY}")
687
    set_property(TARGET benchmark PROPERTY IMPORTED_LOCATION ${BENCHMARK_LIBRARY})
688
  endif()
689
  include_directories(${CMAKE_CURRENT_LIST_DIR}/../third_party/benchmark/include)
690

691
  # Recover build options.
692
  set(BUILD_SHARED_LIBS ${TEMP_BUILD_SHARED_LIBS} CACHE BOOL "Build shared libs" FORCE)
693

694
  # To make the git clean after the build, we revert the changes here.
695
  if(MSVC AND MSVC_Z7_OVERRIDE)
696
    execute_process(
697
      COMMAND ${CMAKE_COMMAND}
698
              "-DFILENAME=${CMAKE_CURRENT_LIST_DIR}/../third_party/googletest/googletest/cmake/internal_utils.cmake"
699
              "-DBACKUP=${CMAKE_CURRENT_LIST_DIR}/../third_party/googletest/googletest/cmake/internal_utils.cmake.bak"
700
              "-DREVERT=1"
701
              "-P"
702
              "${CMAKE_CURRENT_LIST_DIR}/GoogleTestPatch.cmake"
703
      RESULT_VARIABLE _exitcode)
704
    if(NOT _exitcode EQUAL 0)
705
      message(WARNING "Reverting changes failed for Google Test. The build may fail.")
706
    endif()
707
  endif()
708

709
  # Cacheing variables to enable incremental build.
710
  # Without this is cross compiling we end up having to blow build directory
711
  # and rebuild from scratch.
712
  if(CMAKE_CROSSCOMPILING)
713
    if(COMPILE_HAVE_STD_REGEX)
714
      set(RUN_HAVE_STD_REGEX 0 CACHE INTERNAL "Cache RUN_HAVE_STD_REGEX output for cross-compile.")
715
    endif()
716
  endif()
717
endif()
718

719
# ---[ FBGEMM
720
if(USE_FBGEMM)
721
  set(CAFFE2_THIRD_PARTY_ROOT "${PROJECT_SOURCE_DIR}/third_party")
722
  if(NOT DEFINED FBGEMM_SOURCE_DIR)
723
    set(FBGEMM_SOURCE_DIR "${CAFFE2_THIRD_PARTY_ROOT}/fbgemm" CACHE STRING "FBGEMM source directory")
724
  endif()
725
  if(NOT CAFFE2_COMPILER_SUPPORTS_AVX512_EXTENSIONS)
726
    message(WARNING
727
      "A compiler with AVX512 support is required for FBGEMM. "
728
      "Not compiling with FBGEMM. "
729
      "Turn this warning off by USE_FBGEMM=OFF.")
730
    set(USE_FBGEMM OFF)
731
  endif()
732
  if(NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
733
    message(WARNING
734
      "x64 operating system is required for FBGEMM. "
735
      "Not compiling with FBGEMM. "
736
      "Turn this warning off by USE_FBGEMM=OFF.")
737
    set(USE_FBGEMM OFF)
738
  endif()
739
  if(USE_FBGEMM AND NOT TARGET fbgemm)
740
    set(FBGEMM_BUILD_TESTS OFF CACHE BOOL "")
741
    set(FBGEMM_BUILD_BENCHMARKS OFF CACHE BOOL "")
742
    if(MSVC AND BUILD_SHARED_LIBS)
743
      set(FBGEMM_LIBRARY_TYPE "shared" CACHE STRING "")
744
    else()
745
      set(FBGEMM_LIBRARY_TYPE "static" CACHE STRING "")
746
    endif()
747
    if(USE_ASAN)
748
      set(USE_SANITIZER "address,undefined" CACHE STRING "-fsanitize options for FBGEMM")
749
    endif()
750
    add_subdirectory("${FBGEMM_SOURCE_DIR}")
751
    set_property(TARGET fbgemm_generic PROPERTY POSITION_INDEPENDENT_CODE ON)
752
    set_property(TARGET fbgemm_avx2 PROPERTY POSITION_INDEPENDENT_CODE ON)
753
    set_property(TARGET fbgemm_avx512 PROPERTY POSITION_INDEPENDENT_CODE ON)
754
    set_property(TARGET fbgemm PROPERTY POSITION_INDEPENDENT_CODE ON)
755
    if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 13.0.0)
756
      # See https://github.com/pytorch/pytorch/issues/74352
757
      target_compile_options_if_supported(asmjit -Wno-deprecated-copy)
758
      target_compile_options_if_supported(asmjit -Wno-unused-but-set-variable)
759
    endif()
760
  endif()
761

762
  if(USE_FBGEMM)
763
    list(APPEND Caffe2_DEPENDENCY_LIBS fbgemm)
764
  endif()
765
endif()
766

767
if(USE_FBGEMM)
768
  caffe2_update_option(USE_FBGEMM ON)
769
else()
770
  caffe2_update_option(USE_FBGEMM OFF)
771
  message(WARNING
772
    "Turning USE_FAKELOWP off as it depends on USE_FBGEMM.")
773
  caffe2_update_option(USE_FAKELOWP OFF)
774
endif()
775

776
if(USE_OPENCL)
777
  message(INFO "USING OPENCL")
778
  find_package(OpenCL REQUIRED)
779
  include_directories(SYSTEM ${OpenCL_INCLUDE_DIRS})
780
  list(APPEND Caffe2_DEPENDENCY_LIBS ${OpenCL_LIBRARIES})
781
endif()
782

783
# ---[ NUMA
784
if(USE_NUMA)
785
  if(LINUX)
786
    find_package(Numa)
787
    if(NOT NUMA_FOUND)
788
      message(WARNING "Not compiling with NUMA. Suppress this warning with -DUSE_NUMA=OFF")
789
      caffe2_update_option(USE_NUMA OFF)
790
    endif()
791
  else()
792
    message(WARNING "NUMA is currently only supported under Linux.")
793
    caffe2_update_option(USE_NUMA OFF)
794
  endif()
795
endif()
796

797
if(USE_ITT)
798
  find_package(ITT)
799
  if(ITT_FOUND)
800
    include_directories(SYSTEM ${ITT_INCLUDE_DIR})
801
    list(APPEND Caffe2_DEPENDENCY_LIBS ${ITT_LIBRARIES})
802
    list(APPEND TORCH_PYTHON_LINK_LIBRARIES ${ITT_LIBRARIES})
803
  else()
804
    message(WARNING "Not compiling with ITT. Suppress this warning with -DUSE_ITT=OFF")
805
    set(USE_ITT OFF CACHE BOOL "" FORCE)
806
    caffe2_update_option(USE_ITT OFF)
807
  endif()
808
endif()
809

810
# ---[ Caffe2 depends on FP16 library for half-precision conversions
811
if(NOT TARGET fp16 AND NOT USE_SYSTEM_FP16)
812
  set(CAFFE2_THIRD_PARTY_ROOT "${PROJECT_SOURCE_DIR}/third_party")
813
  # PSIMD is required by FP16
814
  if(NOT DEFINED PSIMD_SOURCE_DIR)
815
    set(PSIMD_SOURCE_DIR "${CAFFE2_THIRD_PARTY_ROOT}/psimd" CACHE STRING "PSimd source directory")
816
  endif()
817
  if(NOT DEFINED FP16_SOURCE_DIR)
818
    set(FP16_SOURCE_DIR "${CAFFE2_THIRD_PARTY_ROOT}/FP16" CACHE STRING "FP16 source directory")
819
  endif()
820

821
  set(FP16_BUILD_TESTS OFF CACHE BOOL "")
822
  set(FP16_BUILD_BENCHMARKS OFF CACHE BOOL "")
823
  add_subdirectory(
824
    "${FP16_SOURCE_DIR}"
825
    "${CONFU_DEPENDENCIES_BINARY_DIR}/FP16")
826
elseif(NOT TARGET fp16 AND USE_SYSTEM_FP16)
827
  add_library(fp16 STATIC "/usr/include/fp16.h")
828
  set_target_properties(fp16 PROPERTIES LINKER_LANGUAGE C)
829
endif()
830
list(APPEND Caffe2_DEPENDENCY_LIBS fp16)
831

832
# ---[ EIGEN
833
# Due to license considerations, we will only use the MPL2 parts of Eigen.
834
set(EIGEN_MPL2_ONLY 1)
835
if(USE_SYSTEM_EIGEN_INSTALL)
836
  find_package(Eigen3)
837
  if(EIGEN3_FOUND)
838
    message(STATUS "Found system Eigen at " ${EIGEN3_INCLUDE_DIR})
839
  else()
840
    message(STATUS "Did not find system Eigen. Using third party subdirectory.")
841
    set(EIGEN3_INCLUDE_DIR ${CMAKE_CURRENT_LIST_DIR}/../third_party/eigen)
842
    caffe2_update_option(USE_SYSTEM_EIGEN_INSTALL OFF)
843
  endif()
844
else()
845
  message(STATUS "Using third party subdirectory Eigen.")
846
  set(EIGEN3_INCLUDE_DIR ${CMAKE_CURRENT_LIST_DIR}/../third_party/eigen)
847
endif()
848
include_directories(SYSTEM ${EIGEN3_INCLUDE_DIR})
849

850

851
# ---[ Python Interpreter
852
# If not given a Python installation, then use the current active Python
853
if(NOT Python_EXECUTABLE)
854
  execute_process(
855
    COMMAND "which" "python3" RESULT_VARIABLE _exitcode OUTPUT_VARIABLE _py_exe)
856
  if(${_exitcode} EQUAL 0)
857
    if(NOT MSVC)
858
      string(STRIP ${_py_exe} Python_EXECUTABLE)
859
    endif()
860
    message(STATUS "Setting Python to ${Python_EXECUTABLE}")
861
  endif()
862
endif()
863

864
if(BUILD_PYTHON)
865
  set(PYTHON_COMPONENTS Development.Module)
866
  if(USE_NUMPY)
867
    list(APPEND PYTHON_COMPONENTS NumPy)
868
  endif()
869
  find_package(Python COMPONENTS Interpreter OPTIONAL_COMPONENTS ${PYTHON_COMPONENTS})
870
else()
871
  find_package(Python COMPONENTS Interpreter)
872
endif()
873

874
if(NOT Python_Interpreter_FOUND)
875
  message(FATAL_ERROR "Python3 could not be found.")
876
endif()
877

878
if(${Python_VERSION} VERSION_LESS 3.8)
879
  message(FATAL_ERROR
880
    "Found Python libraries version ${Python_VERSION}. Python < 3.8 is no longer supported by PyTorch.")
881
endif()
882

883
# ---[ Python + Numpy
884
if(BUILD_PYTHON)
885
  if(Python_Development.Module_FOUND)
886
    if(USE_NUMPY)
887
      if(NOT Python_NumPy_FOUND)
888
        message(WARNING "NumPy could not be found. Not building with NumPy. Suppress this warning with -DUSE_NUMPY=OFF")
889
        caffe2_update_option(USE_NUMPY OFF)
890
      else()
891
        caffe2_update_option(USE_NUMPY ON)
892
      endif()
893
    endif()
894
    # Observers are required in the python build
895
    caffe2_update_option(USE_OBSERVERS ON)
896
  else()
897
    message(WARNING "Python dependencies not met. Not compiling with python. Suppress this warning with -DBUILD_PYTHON=OFF")
898
    caffe2_update_option(BUILD_PYTHON OFF)
899
  endif()
900
endif()
901

902
# ---[ pybind11
903
if(USE_SYSTEM_PYBIND11)
904
  find_package(pybind11 CONFIG)
905
  if(NOT pybind11_FOUND)
906
    find_package(pybind11)
907
  endif()
908
  if(NOT pybind11_FOUND)
909
    message(FATAL "Cannot find system pybind11")
910
  endif()
911
else()
912
    message(STATUS "Using third_party/pybind11.")
913
    set(pybind11_INCLUDE_DIRS ${CMAKE_CURRENT_LIST_DIR}/../third_party/pybind11/include)
914
    install(DIRECTORY ${pybind11_INCLUDE_DIRS}
915
            DESTINATION ${CMAKE_INSTALL_PREFIX}
916
            FILES_MATCHING PATTERN "*.h")
917
endif()
918
message(STATUS "pybind11 include dirs: " "${pybind11_INCLUDE_DIRS}")
919
add_library(pybind::pybind11 INTERFACE IMPORTED)
920
target_include_directories(pybind::pybind11 SYSTEM INTERFACE ${pybind11_INCLUDE_DIRS})
921
target_link_libraries(pybind::pybind11 INTERFACE Python::Module)
922

923
# ---[ OpenTelemetry API headers
924
find_package(OpenTelemetryApi)
925
if(NOT OpenTelemetryApi_FOUND)
926
  message(STATUS "Using third_party/opentelemetry-cpp.")
927
  set(OpenTelemetryApi_INCLUDE_DIRS ${CMAKE_CURRENT_LIST_DIR}/../third_party/opentelemetry-cpp/api/include)
928
endif()
929
message(STATUS "opentelemetry api include dirs: " "${OpenTelemetryApi_INCLUDE_DIRS}")
930
add_library(opentelemetry::api INTERFACE IMPORTED)
931
target_include_directories(opentelemetry::api SYSTEM INTERFACE ${OpenTelemetryApi_INCLUDE_DIRS})
932

933
# ---[ MPI
934
if(USE_MPI)
935
  find_package(MPI)
936
  if(MPI_CXX_FOUND)
937
    message(STATUS "MPI support found")
938
    message(STATUS "MPI compile flags: " ${MPI_CXX_COMPILE_FLAGS})
939
    message(STATUS "MPI include path: " ${MPI_CXX_INCLUDE_PATH})
940
    message(STATUS "MPI LINK flags path: " ${MPI_CXX_LINK_FLAGS})
941
    message(STATUS "MPI libraries: " ${MPI_CXX_LIBRARIES})
942
    find_program(OMPI_INFO
943
      NAMES ompi_info
944
      HINTS ${MPI_CXX_LIBRARIES}/../bin)
945
    if(OMPI_INFO)
946
      execute_process(COMMAND ${OMPI_INFO}
947
                      OUTPUT_VARIABLE _output)
948
      if(_output MATCHES "smcuda")
949
        message(STATUS "Found OpenMPI with CUDA support built.")
950
      else()
951
        message(WARNING "OpenMPI found, but it is not built with CUDA support.")
952
        set(CAFFE2_FORCE_FALLBACK_CUDA_MPI 1)
953
      endif()
954
    endif()
955
  else()
956
    message(WARNING "Not compiling with MPI. Suppress this warning with -DUSE_MPI=OFF")
957
    caffe2_update_option(USE_MPI OFF)
958
  endif()
959
endif()
960

961
# ---[ OpenMP
962
if(USE_OPENMP AND NOT TARGET caffe2::openmp)
963
  include(${CMAKE_CURRENT_LIST_DIR}/Modules/FindOpenMP.cmake)
964
  if(OPENMP_FOUND)
965
    message(STATUS "Adding OpenMP CXX_FLAGS: " ${OpenMP_CXX_FLAGS})
966
    if(APPLE AND USE_MPS)
967
      string(APPEND CMAKE_OBJCXX_FLAGS " ${OpenMP_CXX_FLAGS}")
968
    endif()
969
    if(OpenMP_CXX_LIBRARIES)
970
      message(STATUS "Will link against OpenMP libraries: ${OpenMP_CXX_LIBRARIES}")
971
    endif()
972
    add_library(caffe2::openmp INTERFACE IMPORTED)
973
    target_link_libraries(caffe2::openmp INTERFACE OpenMP::OpenMP_CXX)
974
    list(APPEND Caffe2_DEPENDENCY_LIBS caffe2::openmp)
975
    if(MSVC AND OpenMP_CXX_LIBRARIES MATCHES ".*libiomp5md\\.lib.*")
976
      target_compile_definitions(caffe2::openmp INTERFACE _OPENMP_NOFORCE_MANIFEST)
977
      target_link_options(caffe2::openmp INTERFACE "/NODEFAULTLIB:vcomp")
978
    endif()
979
  else()
980
    message(WARNING "Not compiling with OpenMP. Suppress this warning with -DUSE_OPENMP=OFF")
981
    caffe2_update_option(USE_OPENMP OFF)
982
  endif()
983
endif()
984

985

986

987
# ---[ Android specific ones
988
if(ANDROID)
989
  list(APPEND Caffe2_DEPENDENCY_LIBS log)
990
endif()
991

992
# ---[ LLVM
993
if(USE_LLVM)
994
  message(STATUS "Looking for LLVM in ${USE_LLVM}")
995
  find_package(LLVM PATHS ${USE_LLVM} NO_DEFAULT_PATH)
996

997
  if(LLVM_FOUND)
998
    message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
999
    message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
1000

1001
    include_directories(${LLVM_INCLUDE_DIRS})
1002
    add_definitions(-DTORCH_ENABLE_LLVM)
1003
  endif(LLVM_FOUND)
1004
endif(USE_LLVM)
1005

1006
# ---[ cuDNN
1007
if(USE_CUDNN)
1008
  if(CUDNN_VERSION VERSION_LESS 8.5)
1009
    message(FATAL_ERROR "PyTorch needs CuDNN-8.5 or above, but found ${CUDNN_VERSION}. Builds are still possible with `USE_CUDNN=0`")
1010
  endif()
1011
  set(CUDNN_FRONTEND_INCLUDE_DIR ${CMAKE_CURRENT_LIST_DIR}/../third_party/cudnn_frontend/include)
1012
  target_include_directories(torch::cudnn INTERFACE ${CUDNN_FRONTEND_INCLUDE_DIR})
1013
endif()
1014

1015
# ---[ HIP
1016
if(USE_ROCM)
1017
  # This prevents linking in the libtinfo from /opt/conda/lib which conflicts with ROCm libtinfo.
1018
  # Currently only active for Ubuntu 20.04 and greater versions.
1019
  if(UNIX AND EXISTS "/etc/os-release")
1020
    file(STRINGS /etc/os-release OS_RELEASE)
1021
    set(DISTRO_NAME "")
1022
    set(DISTRO_VERSION "")
1023
    foreach(line ${OS_RELEASE})
1024
      string(REGEX MATCH "^NAME=" DISTRO_NAME_MATCH ${line})
1025
      if(NOT DISTRO_NAME_MATCH STREQUAL "")
1026
        string(REGEX REPLACE "^NAME=\"(.*)\"" "\\1" DISTRO_NAME ${line})
1027
      endif()
1028
      string(REGEX MATCH "^VERSION_ID=" DISTRO_VERSION_MATCH ${line})
1029
      if(NOT DISTRO_VERSION_MATCH STREQUAL "")
1030
        string(REGEX REPLACE "^VERSION_ID=\"(.*)\"" "\\1" DISTRO_VERSION ${line})
1031
      endif()
1032
    endforeach()
1033
    if(DISTRO_NAME STREQUAL "Ubuntu" AND DISTRO_VERSION VERSION_GREATER_EQUAL "20.04")
1034
      find_library(LIBTINFO_LOC tinfo NO_CMAKE_PATH NO_CMAKE_ENVIRONMENT_PATH)
1035
      if(LIBTINFO_LOC)
1036
        get_filename_component(LIBTINFO_LOC_PARENT ${LIBTINFO_LOC} DIRECTORY)
1037
        set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath-link,${LIBTINFO_LOC_PARENT}")
1038
      endif()
1039
    endif()
1040
  endif()
1041

1042
  include(${CMAKE_CURRENT_LIST_DIR}/public/LoadHIP.cmake)
1043
  if(PYTORCH_FOUND_HIP)
1044
    message(INFO "Compiling with HIP for AMD.")
1045
    caffe2_update_option(USE_ROCM ON)
1046

1047
    if(USE_NCCL AND NOT USE_SYSTEM_NCCL)
1048
      message(INFO "Forcing USE_SYSTEM_NCCL to ON since it's required by using RCCL")
1049
      caffe2_update_option(USE_SYSTEM_NCCL ON)
1050
    endif()
1051

1052
    list(APPEND HIP_CXX_FLAGS -fPIC)
1053
    list(APPEND HIP_CXX_FLAGS -D__HIP_PLATFORM_AMD__=1)
1054
    list(APPEND HIP_CXX_FLAGS -DCUDA_HAS_FP16=1)
1055
    list(APPEND HIP_CXX_FLAGS -DUSE_ROCM)
1056
    list(APPEND HIP_CXX_FLAGS -D__HIP_NO_HALF_OPERATORS__=1)
1057
    list(APPEND HIP_CXX_FLAGS -D__HIP_NO_HALF_CONVERSIONS__=1)
1058
    list(APPEND HIP_CXX_FLAGS -DTORCH_HIP_VERSION=${TORCH_HIP_VERSION})
1059
    list(APPEND HIP_CXX_FLAGS -Wno-shift-count-negative)
1060
    list(APPEND HIP_CXX_FLAGS -Wno-shift-count-overflow)
1061
    list(APPEND HIP_CXX_FLAGS -Wno-duplicate-decl-specifier)
1062
    list(APPEND HIP_CXX_FLAGS -DCAFFE2_USE_MIOPEN)
1063
    list(APPEND HIP_CXX_FLAGS -DTHRUST_DEVICE_SYSTEM=THRUST_DEVICE_SYSTEM_HIP)
1064
    list(APPEND HIP_CXX_FLAGS -std=c++17)
1065
    list(APPEND HIP_CXX_FLAGS -DHIPBLAS_V2)
1066
    if(HIP_NEW_TYPE_ENUMS)
1067
      list(APPEND HIP_CXX_FLAGS -DHIP_NEW_TYPE_ENUMS)
1068
    endif()
1069
    add_definitions(-DROCM_VERSION=${ROCM_VERSION_DEV_INT})
1070
    add_definitions(-DTORCH_HIP_VERSION=${TORCH_HIP_VERSION})
1071
    message("TORCH_HIP_VERSION=${TORCH_HIP_VERSION} is added as a compiler defines")
1072

1073
    if(CMAKE_BUILD_TYPE MATCHES Debug)
1074
       list(APPEND HIP_CXX_FLAGS -g2)
1075
       list(APPEND HIP_CXX_FLAGS -O0)
1076
       list(APPEND HIP_HIPCC_FLAGS -fdebug-info-for-profiling)
1077
    endif(CMAKE_BUILD_TYPE MATCHES Debug)
1078

1079
    # needed for compat with newer versions of hip-clang that introduced C++20 mangling rules
1080
    list(APPEND HIP_HIPCC_FLAGS -fclang-abi-compat=17)
1081

1082
    set(HIP_CLANG_FLAGS ${HIP_CXX_FLAGS})
1083
    # Ask hcc to generate device code during compilation so we can use
1084
    # host linker to link.
1085
    list(APPEND HIP_CLANG_FLAGS -fno-gpu-rdc)
1086
    foreach(pytorch_rocm_arch ${PYTORCH_ROCM_ARCH})
1087
      list(APPEND HIP_CLANG_FLAGS --offload-arch=${pytorch_rocm_arch})
1088
    endforeach()
1089

1090
    set(Caffe2_HIP_INCLUDE
1091
       $<INSTALL_INTERFACE:include> ${Caffe2_HIP_INCLUDE})
1092
    # This is needed for library added by hip_add_library (same for hip_add_executable)
1093
    hip_include_directories(${Caffe2_HIP_INCLUDE})
1094

1095
    set(Caffe2_PUBLIC_HIP_DEPENDENCY_LIBS
1096
      ${PYTORCH_HIP_LIBRARIES} ${PYTORCH_MIOPEN_LIBRARIES} ${hipcub_LIBRARIES} ${ROCM_HIPRTC_LIB} ${ROCM_ROCTX_LIB})
1097
    list(APPEND Caffe2_PUBLIC_HIP_DEPENDENCY_LIBS ${hipblaslt_LIBRARIES})
1098

1099
    list(APPEND Caffe2_PUBLIC_HIP_DEPENDENCY_LIBS
1100
      roc::hipblas hip::hipfft hip::hiprand roc::hipsparse roc::hipsolver)
1101

1102
    # ---[ Kernel asserts
1103
    # Kernel asserts is disabled for ROCm by default.
1104
    # It can be turned on by turning on the env USE_ROCM_KERNEL_ASSERT to the build system.
1105
    if(USE_ROCM_KERNEL_ASSERT)
1106
      message(STATUS "Enabling Kernel Assert for ROCm")
1107
    else()
1108
      message(STATUS "Disabling Kernel Assert for ROCm")
1109
    endif()
1110

1111
  else()
1112
    caffe2_update_option(USE_ROCM OFF)
1113
  endif()
1114
endif()
1115

1116
# ---[ NCCL
1117
if(USE_NCCL)
1118
  if(NOT (USE_CUDA OR USE_ROCM))
1119
    message(WARNING
1120
        "Not using CUDA/ROCM, so disabling USE_NCCL. Suppress this warning with "
1121
        "-DUSE_NCCL=OFF.")
1122
    caffe2_update_option(USE_NCCL OFF)
1123
  elseif(NOT CMAKE_SYSTEM_NAME STREQUAL "Linux")
1124
    message(WARNING "NCCL is currently only supported under Linux.")
1125
    caffe2_update_option(USE_NCCL OFF)
1126
  elseif(USE_CUDA)
1127
    include(${CMAKE_CURRENT_LIST_DIR}/External/nccl.cmake)
1128
    list(APPEND Caffe2_CUDA_DEPENDENCY_LIBS __caffe2_nccl)
1129
  elseif(USE_ROCM)
1130
    include(${CMAKE_CURRENT_LIST_DIR}/External/rccl.cmake)
1131
    list(APPEND Caffe2_CUDA_DEPENDENCY_LIBS __caffe2_nccl)
1132
  endif()
1133
endif()
1134

1135
# ---[ UCC
1136
if(USE_UCC)
1137
  if(NOT CMAKE_SYSTEM_NAME STREQUAL "Linux")
1138
    message(WARNING "UCC is currently only supported under Linux.")
1139
    caffe2_update_option(USE_UCC OFF)
1140
  else()
1141
    include(${CMAKE_CURRENT_LIST_DIR}/External/ucc.cmake)
1142
  endif()
1143
endif()
1144

1145
# ---[ CUB
1146
if(USE_CUDA)
1147
  find_package(CUB)
1148
  if(NOT CUB_FOUND)
1149
    message(FATAL_ERROR "Cannot find CUB.")
1150
  endif()
1151
  include_directories(SYSTEM ${CUB_INCLUDE_DIRS})
1152
endif()
1153

1154
if(USE_DISTRIBUTED AND USE_TENSORPIPE)
1155
  if(MSVC)
1156
    message(WARNING "Tensorpipe cannot be used on Windows.")
1157
  else()
1158
    if(USE_CUDA)
1159
      set(TP_USE_CUDA ON CACHE BOOL "" FORCE)
1160
      set(TP_ENABLE_CUDA_IPC ON CACHE BOOL "" FORCE)
1161
    endif()
1162
    set(TP_BUILD_LIBUV ON CACHE BOOL "" FORCE)
1163
    add_compile_options(-DTORCH_USE_LIBUV)
1164
    include_directories(BEFORE SYSTEM ${CMAKE_CURRENT_LIST_DIR}/../third_party/tensorpipe/third_party/libuv/include)
1165
    set(TP_STATIC_OR_SHARED STATIC CACHE STRING "" FORCE)
1166

1167
    # Tensorpipe uses cuda_add_library
1168
    torch_update_find_cuda_flags()
1169
    add_subdirectory(${PROJECT_SOURCE_DIR}/third_party/tensorpipe)
1170

1171
    list(APPEND Caffe2_DEPENDENCY_LIBS tensorpipe)
1172
    list(APPEND Caffe2_DEPENDENCY_LIBS nlohmann)
1173
    if(USE_CUDA)
1174
      list(APPEND Caffe2_CUDA_DEPENDENCY_LIBS tensorpipe_cuda)
1175
    elseif(USE_ROCM)
1176
      message(WARNING "TensorPipe doesn't yet support ROCm")
1177
      # Not yet...
1178
      # list(APPEND Caffe2_HIP_DEPENDENCY_LIBS tensorpipe_hip)
1179
    endif()
1180
  endif()
1181
endif()
1182

1183
if(USE_GLOO)
1184
  if(NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
1185
    message(WARNING "Gloo can only be used on 64-bit systems.")
1186
    caffe2_update_option(USE_GLOO OFF)
1187
  else()
1188
    # Don't install gloo
1189
    set(GLOO_INSTALL OFF CACHE BOOL "" FORCE)
1190
    set(GLOO_STATIC_OR_SHARED STATIC CACHE STRING "" FORCE)
1191

1192
    # Temporarily override variables to avoid building Gloo tests/benchmarks
1193
    set(__BUILD_TEST ${BUILD_TEST})
1194
    set(__BUILD_BENCHMARK ${BUILD_BENCHMARK})
1195
    set(BUILD_TEST OFF)
1196
    set(BUILD_BENCHMARK OFF)
1197
    if(USE_ROCM)
1198
      set(ENV{GLOO_ROCM_ARCH} "${PYTORCH_ROCM_ARCH}")
1199
    endif()
1200
    if(NOT USE_SYSTEM_GLOO)
1201
      if(USE_DISTRIBUED AND USE_TENSORPIPE)
1202
        get_target_property(_include_dirs uv_a INCLUDE_DIRECTORIES)
1203
        set_target_properties(uv_a PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${_include_dirs}")
1204
      endif()
1205
      if(USE_NCCL AND NOT USE_SYSTEM_NCCL)
1206
        # Tell Gloo build system to use bundled NCCL, see
1207
        # https://github.com/facebookincubator/gloo/blob/950c0e23819779a9e0c70b861db4c52b31d1d1b2/cmake/Dependencies.cmake#L123
1208
        set(NCCL_EXTERNAL ON)
1209
      endif()
1210
      set(GLOO_USE_CUDA_TOOLKIT ON CACHE BOOL "" FORCE)
1211
      add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../third_party/gloo)
1212
    else()
1213
      add_library(gloo SHARED IMPORTED)
1214
      find_library(GLOO_LIBRARY gloo)
1215
      if(NOT GLOO_LIBRARY)
1216
        message(FATAL_ERROR "Cannot find gloo")
1217
      endif()
1218
      message("Found gloo: ${GLOO_LIBRARY}")
1219
      set_target_properties(gloo PROPERTIES IMPORTED_LOCATION ${GLOO_LIBRARY})
1220
    endif()
1221
    # Here is a little bit hacky. We have to put PROJECT_BINARY_DIR in front
1222
    # of PROJECT_SOURCE_DIR with/without conda system. The reason is that
1223
    # gloo generates a new config.h in the binary diretory.
1224
    include_directories(BEFORE SYSTEM ${CMAKE_CURRENT_LIST_DIR}/../third_party/gloo)
1225
    include_directories(BEFORE SYSTEM ${PROJECT_BINARY_DIR}/third_party/gloo)
1226
    set(BUILD_TEST ${__BUILD_TEST})
1227
    set(BUILD_BENCHMARK ${__BUILD_BENCHMARK})
1228

1229
    # Add explicit dependency since NCCL is built from third_party.
1230
    # Without dependency, make -jN with N>1 can fail if the NCCL build
1231
    # hasn't finished when CUDA targets are linked.
1232
    if(NOT USE_SYSTEM_NCCL AND USE_NCCL AND NOT USE_ROCM)
1233
      add_dependencies(gloo_cuda nccl_external)
1234
    endif()
1235
    # Pick the right dependency depending on USE_CUDA
1236
    list(APPEND Caffe2_DEPENDENCY_LIBS gloo)
1237
    if(USE_CUDA)
1238
      list(APPEND Caffe2_CUDA_DEPENDENCY_LIBS gloo_cuda)
1239
    elseif(USE_ROCM)
1240
      list(APPEND Caffe2_HIP_DEPENDENCY_LIBS gloo_hip)
1241
    endif()
1242
    add_compile_options(-DCAFFE2_USE_GLOO)
1243
  endif()
1244
endif()
1245

1246
# ---[ profiling
1247
if(USE_PROF)
1248
  find_package(htrace)
1249
  if(htrace_FOUND)
1250
    set(USE_PROF_HTRACE ON)
1251
  else()
1252
    message(WARNING "htrace not found. Caffe2 will build without htrace prof")
1253
  endif()
1254
endif()
1255

1256
if(USE_SNPE AND ANDROID)
1257
  if(SNPE_LOCATION AND SNPE_HEADERS)
1258
    message(STATUS "Using SNPE location specified by -DSNPE_LOCATION: " ${SNPE_LOCATION})
1259
    message(STATUS "Using SNPE headers specified by -DSNPE_HEADERS: " ${SNPE_HEADERS})
1260
    include_directories(SYSTEM ${SNPE_HEADERS})
1261
    add_library(snpe SHARED IMPORTED)
1262
    set_property(TARGET snpe PROPERTY IMPORTED_LOCATION ${SNPE_LOCATION})
1263
    list(APPEND Caffe2_DEPENDENCY_LIBS snpe)
1264
  else()
1265
    caffe2_update_option(USE_SNPE OFF)
1266
  endif()
1267
endif()
1268

1269
if(USE_NNAPI AND NOT ANDROID)
1270
  message(WARNING "NNApi is only used in android builds.")
1271
  caffe2_update_option(USE_NNAPI OFF)
1272
endif()
1273

1274
# ---[ Onnx
1275
if(CAFFE2_CMAKE_BUILDING_WITH_MAIN_REPO AND NOT INTERN_DISABLE_ONNX)
1276
  if(EXISTS "${CAFFE2_CUSTOM_PROTOC_EXECUTABLE}")
1277
    set(ONNX_CUSTOM_PROTOC_EXECUTABLE ${CAFFE2_CUSTOM_PROTOC_EXECUTABLE})
1278
  endif()
1279
  set(TEMP_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS})
1280
  set(BUILD_SHARED_LIBS OFF)
1281
  set(ONNX_USE_MSVC_STATIC_RUNTIME ${CAFFE2_USE_MSVC_STATIC_RUNTIME})
1282
  set(ONNX_USE_LITE_PROTO ${CAFFE2_USE_LITE_PROTO})
1283
  # If linking local protobuf, make sure ONNX has the same protobuf
1284
  # patches as Caffe2 and Caffe proto. This forces some functions to
1285
  # not be inline and instead route back to the statically-linked protobuf.
1286
  if(CAFFE2_LINK_LOCAL_PROTOBUF)
1287
    set(ONNX_PROTO_POST_BUILD_SCRIPT ${PROJECT_SOURCE_DIR}/cmake/ProtoBufPatch.cmake)
1288
  endif()
1289
  if(ONNX_ML)
1290
    add_definitions(-DONNX_ML=1)
1291
  endif()
1292
  add_definitions(-DONNXIFI_ENABLE_EXT=1)
1293
  if(NOT USE_SYSTEM_ONNX)
1294
    add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../third_party/onnx EXCLUDE_FROM_ALL)
1295
    if(NOT MSVC)
1296
      set_target_properties(onnx_proto PROPERTIES CXX_STANDARD 17)
1297
    endif()
1298
  endif()
1299

1300
  add_definitions(-DONNX_NAMESPACE=${ONNX_NAMESPACE})
1301
  if(NOT USE_SYSTEM_ONNX)
1302
    include_directories(${ONNX_INCLUDE_DIRS})
1303
    # In mobile build we care about code size, and so we need drop
1304
    # everything (e.g. checker) in onnx but the pb definition.
1305
    if(ANDROID OR IOS)
1306
      caffe2_interface_library(onnx_proto onnx_library)
1307
    else()
1308
      caffe2_interface_library(onnx onnx_library)
1309
    endif()
1310
    list(APPEND Caffe2_DEPENDENCY_WHOLE_LINK_LIBS onnx_library)
1311
  else()
1312
    add_library(onnx SHARED IMPORTED)
1313
    find_library(ONNX_LIBRARY onnx)
1314
    if(NOT ONNX_LIBRARY)
1315
      message(FATAL_ERROR "Cannot find onnx")
1316
    endif()
1317
    set_property(TARGET onnx PROPERTY IMPORTED_LOCATION ${ONNX_LIBRARY})
1318
    add_library(onnx_proto SHARED IMPORTED)
1319
    find_library(ONNX_PROTO_LIBRARY onnx_proto)
1320
    if(NOT ONNX_PROTO_LIBRARY)
1321
      message(FATAL_ERROR "Cannot find onnx")
1322
    endif()
1323
    set_property(TARGET onnx_proto PROPERTY IMPORTED_LOCATION ${ONNX_PROTO_LIBRARY})
1324
    message("-- Found onnx: ${ONNX_LIBRARY} ${ONNX_PROTO_LIBRARY}")
1325
    list(APPEND Caffe2_DEPENDENCY_LIBS onnx_proto onnx)
1326
  endif()
1327
  # Recover the build shared libs option.
1328
  set(BUILD_SHARED_LIBS ${TEMP_BUILD_SHARED_LIBS})
1329
endif()
1330

1331
# --[ ATen checks
1332
set(USE_LAPACK 0)
1333

1334
# we need to build all targets to be linked with PIC
1335
if(USE_KINETO AND INTERN_BUILD_MOBILE AND USE_LITE_INTERPRETER_PROFILER)
1336
  set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
1337
endif()
1338

1339
if(NOT INTERN_BUILD_MOBILE)
1340
  set(TORCH_CUDA_ARCH_LIST $ENV{TORCH_CUDA_ARCH_LIST})
1341
  string(APPEND CMAKE_CUDA_FLAGS " $ENV{TORCH_NVCC_FLAGS}")
1342
  set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
1343

1344
  # Top-level build config
1345
  ############################################
1346
  # Flags
1347
  # When using MSVC
1348
  # Detect CUDA architecture and get best NVCC flags
1349
  # finding cuda must be first because other things depend on the result
1350
  #
1351
  # NB: We MUST NOT run this find_package if NOT USE_CUDA is set, because upstream
1352
  # FindCUDA has a bug where it will still attempt to make use of NOTFOUND
1353
  # compiler variables to run various probe tests.  We could try to fix
1354
  # this, but since FindCUDA upstream is subsumed by first-class support
1355
  # for CUDA language, it seemed not worth fixing.
1356

1357
  if(MSVC)
1358
    # we want to respect the standard, and we are bored of those **** .
1359
    add_definitions(-D_CRT_SECURE_NO_DEPRECATE=1)
1360
    string(APPEND CMAKE_CUDA_FLAGS " -Xcompiler=/wd4819,/wd4503,/wd4190,/wd4244,/wd4251,/wd4275,/wd4522")
1361
  endif()
1362

1363
  string(APPEND CMAKE_CUDA_FLAGS " -Wno-deprecated-gpu-targets --expt-extended-lambda")
1364

1365
  # use cub in a safe manner, see:
1366
  # https://github.com/pytorch/pytorch/pull/55292
1367
  string(APPEND CMAKE_CUDA_FLAGS " -DCUB_WRAPPED_NAMESPACE=at_cuda_detail")
1368

1369
  message(STATUS "Found CUDA with FP16 support, compiling with torch.cuda.HalfTensor")
1370
  string(APPEND CMAKE_CUDA_FLAGS " -DCUDA_HAS_FP16=1"
1371
                                 " -D__CUDA_NO_HALF_OPERATORS__"
1372
                                 " -D__CUDA_NO_HALF_CONVERSIONS__"
1373
                                 " -D__CUDA_NO_HALF2_OPERATORS__"
1374
                                 " -D__CUDA_NO_BFLOAT16_CONVERSIONS__")
1375

1376
  string(APPEND CMAKE_C_FLAGS_RELEASE " -DNDEBUG")
1377
  string(APPEND CMAKE_CXX_FLAGS_RELEASE " -DNDEBUG")
1378
  if(NOT GENERATOR_IS_MULTI_CONFIG)
1379
    if(${CMAKE_BUILD_TYPE} STREQUAL "Release")
1380
      message(STATUS "Adding -DNDEBUG to compile flags")
1381
      string(APPEND CMAKE_C_FLAGS " -DNDEBUG")
1382
      string(APPEND CMAKE_CXX_FLAGS " -DNDEBUG")
1383
    else()
1384
      message(STATUS "Removing -DNDEBUG from compile flags")
1385
      string(REGEX REPLACE "[-/]DNDEBUG" "" CMAKE_C_FLAGS "" ${CMAKE_C_FLAGS})
1386
      string(REGEX REPLACE "[-/]DNDEBUG" "" CMAKE_CXX_FLAGS "" ${CMAKE_CXX_FLAGS})
1387
    endif()
1388
  endif()
1389
  string(REGEX REPLACE "[-/]DNDEBUG" "" CMAKE_C_FLAGS_DEBUG "" ${CMAKE_C_FLAGS_DEBUG})
1390
  string(REGEX REPLACE "[-/]DNDEBUG" "" CMAKE_CXX_FLAGS_DEBUG "" ${CMAKE_CXX_FLAGS_DEBUG})
1391

1392
  set(CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE OFF)
1393

1394
  if(USE_CUDA OR USE_ROCM)
1395
    if(USE_MAGMA)
1396
      find_package(MAGMA)
1397
      if(MAGMA_FOUND)
1398
        message(STATUS "Compiling with MAGMA support")
1399
        message(STATUS "MAGMA INCLUDE DIRECTORIES: ${MAGMA_INCLUDE_DIR}")
1400
        message(STATUS "MAGMA LIBRARIES: ${MAGMA_LIBRARIES}")
1401
        message(STATUS "MAGMA V2 check: ${MAGMA_V2}")
1402
      else()
1403
        message(STATUS "MAGMA not found. Compiling without MAGMA support")
1404
        caffe2_update_option(USE_MAGMA OFF)
1405
      endif()
1406
    endif()
1407
  elseif(USE_MAGMA)
1408
    message(WARNING
1409
      "Not compiling with MAGMA. Suppress this warning with "
1410
      "-DUSE_MAGMA=OFF.")
1411
    caffe2_update_option(USE_MAGMA OFF)
1412
  endif()
1413

1414
  # ARM specific flags
1415
  find_package(ARM)
1416
  if(ASIMD_FOUND)
1417
    message(STATUS "asimd/Neon found with compiler flag : -D__NEON__")
1418
    add_compile_options(-D__NEON__)
1419
  elseif(NEON_FOUND)
1420
    if(APPLE)
1421
      message(STATUS "Neon found with compiler flag : -D__NEON__")
1422
      add_compile_options(-D__NEON__)
1423
    else()
1424
      message(STATUS "Neon found with compiler flag : -mfpu=neon -D__NEON__")
1425
      add_compile_options(-mfpu=neon -D__NEON__)
1426
    endif()
1427
  endif()
1428
  if(CORTEXA8_FOUND)
1429
    message(STATUS "Cortex-A8 Found with compiler flag : -mcpu=cortex-a8")
1430
    add_compile_options(-mcpu=cortex-a8 -fprefetch-loop-arrays)
1431
  endif()
1432
  if(CORTEXA9_FOUND)
1433
    message(STATUS "Cortex-A9 Found with compiler flag : -mcpu=cortex-a9")
1434
    add_compile_options(-mcpu=cortex-a9)
1435
  endif()
1436

1437
  find_package(LAPACK)
1438
  if(LAPACK_FOUND)
1439
    set(USE_LAPACK 1)
1440
    list(APPEND Caffe2_PRIVATE_DEPENDENCY_LIBS ${LAPACK_LIBRARIES})
1441
  endif()
1442

1443
  if(NOT USE_CUDA)
1444
    message("disabling CUDA because NOT USE_CUDA is set")
1445
    set(AT_CUDA_ENABLED 0)
1446
  else()
1447
    set(AT_CUDA_ENABLED 1)
1448
  endif()
1449

1450
  if(NOT USE_ROCM)
1451
    message("disabling ROCM because NOT USE_ROCM is set")
1452
    message(STATUS "MIOpen not found. Compiling without MIOpen support")
1453
    set(AT_ROCM_ENABLED 0)
1454
  else()
1455
    include_directories(BEFORE ${MIOPEN_INCLUDE_DIRS})
1456
    set(AT_ROCM_ENABLED 1)
1457
  endif()
1458

1459
  if(USE_MKLDNN)
1460
    if(NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
1461
      message(WARNING
1462
        "x64 operating system is required for MKLDNN. "
1463
        "Not compiling with MKLDNN. "
1464
        "Turn this warning off by USE_MKLDNN=OFF.")
1465
      set(USE_MKLDNN OFF)
1466
    endif()
1467
    if(USE_MKLDNN_ACL)
1468
      set(AT_MKLDNN_ACL_ENABLED 1)
1469
    endif()
1470
  endif()
1471
  if(USE_MKLDNN)
1472
    include(${CMAKE_CURRENT_LIST_DIR}/public/mkldnn.cmake)
1473
    if(MKLDNN_FOUND)
1474
      set(AT_MKLDNN_ENABLED 1)
1475
      include_directories(AFTER SYSTEM ${MKLDNN_INCLUDE_DIR})
1476
    else()
1477
      message(WARNING "MKLDNN could not be found.")
1478
      caffe2_update_option(USE_MKLDNN OFF)
1479
    endif()
1480
  else()
1481
    message("disabling MKLDNN because USE_MKLDNN is not set")
1482
  endif()
1483

1484
  if(UNIX AND NOT APPLE)
1485
     include(CheckLibraryExists)
1486
     # https://github.com/libgit2/libgit2/issues/2128#issuecomment-35649830
1487
     CHECK_LIBRARY_EXISTS(rt clock_gettime "time.h" NEED_LIBRT)
1488
     if(NEED_LIBRT)
1489
       list(APPEND Caffe2_DEPENDENCY_LIBS rt)
1490
       set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} rt)
1491
     endif(NEED_LIBRT)
1492
  endif(UNIX AND NOT APPLE)
1493

1494
  if(UNIX)
1495
    set(CMAKE_EXTRA_INCLUDE_FILES "sys/mman.h")
1496
    CHECK_FUNCTION_EXISTS(mmap HAVE_MMAP)
1497
    if(HAVE_MMAP)
1498
      add_definitions(-DHAVE_MMAP=1)
1499
    endif(HAVE_MMAP)
1500
    # done for lseek: https://www.gnu.org/software/libc/manual/html_node/File-Position-Primitive.html
1501
    add_definitions(-D_FILE_OFFSET_BITS=64)
1502
    CHECK_FUNCTION_EXISTS(shm_open HAVE_SHM_OPEN)
1503
    if(HAVE_SHM_OPEN)
1504
      add_definitions(-DHAVE_SHM_OPEN=1)
1505
    endif(HAVE_SHM_OPEN)
1506
    CHECK_FUNCTION_EXISTS(shm_unlink HAVE_SHM_UNLINK)
1507
    if(HAVE_SHM_UNLINK)
1508
      add_definitions(-DHAVE_SHM_UNLINK=1)
1509
    endif(HAVE_SHM_UNLINK)
1510
    CHECK_FUNCTION_EXISTS(malloc_usable_size HAVE_MALLOC_USABLE_SIZE)
1511
    if(HAVE_MALLOC_USABLE_SIZE)
1512
      add_definitions(-DHAVE_MALLOC_USABLE_SIZE=1)
1513
    endif(HAVE_MALLOC_USABLE_SIZE)
1514
  endif(UNIX)
1515

1516
  add_definitions(-DUSE_EXTERNAL_MZCRC)
1517
  add_definitions(-DMINIZ_DISABLE_ZIP_READER_CRC32_CHECKS)
1518

1519
  find_package(ZVECTOR) # s390x simd support
1520
endif()
1521

1522
#
1523
# End ATen checks
1524
#
1525
set(TEMP_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS})
1526
set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared libs" FORCE)
1527
add_subdirectory(${PROJECT_SOURCE_DIR}/third_party/fmt)
1528

1529
# Disable compiler feature checks for `fmt`.
1530
#
1531
# CMake compiles a little program to check compiler features. Some of our build
1532
# configurations (notably the mobile build analyzer) will populate
1533
# CMAKE_CXX_FLAGS in ways that break feature checks. Since we already know
1534
# `fmt` is compatible with a superset of the compilers that PyTorch is, it
1535
# shouldn't be too bad to just disable the checks.
1536
set_target_properties(fmt-header-only PROPERTIES INTERFACE_COMPILE_FEATURES "")
1537

1538
list(APPEND Caffe2_DEPENDENCY_LIBS fmt::fmt-header-only)
1539
set(BUILD_SHARED_LIBS ${TEMP_BUILD_SHARED_LIBS} CACHE BOOL "Build shared libs" FORCE)
1540

1541
# ---[ Kineto
1542
# edge profiler depends on KinetoProfiler but it only does cpu
1543
# profiling. Thus we dont need USE_CUDA/USE_ROCM
1544
if(USE_KINETO AND INTERN_BUILD_MOBILE AND NOT (BUILD_LITE_INTERPRETER AND USE_LITE_INTERPRETER_PROFILER))
1545
  message(STATUS "Not using libkineto in a mobile build.")
1546
  set(USE_KINETO OFF)
1547
endif()
1548

1549
if(USE_KINETO AND INTERN_BUILD_MOBILE AND USE_LITE_INTERPRETER_PROFILER AND (USE_CUDA OR USE_ROCM))
1550
  message(FATAL_ERROR "Mobile build with profiler does not support CUDA or ROCM")
1551
endif()
1552

1553
if(USE_KINETO)
1554
  if((NOT USE_CUDA) OR MSVC)
1555
    set(LIBKINETO_NOCUPTI ON CACHE STRING "" FORCE)
1556
  else()
1557
    set(LIBKINETO_NOCUPTI OFF CACHE STRING "")
1558
    message(STATUS "Using Kineto with CUPTI support")
1559
  endif()
1560

1561
  if(NOT USE_ROCM)
1562
    set(LIBKINETO_NOROCTRACER ON CACHE STRING "" FORCE)
1563
  else()
1564
    set(LIBKINETO_NOROCTRACER OFF CACHE STRING "")
1565
    message(STATUS "Using Kineto with Roctracer support")
1566
  endif()
1567

1568
  if((NOT USE_XPU) OR WIN32)
1569
    set(LIBKINETO_NOXPUPTI ON CACHE STRING "" FORCE)
1570
  else()
1571
    set(LIBKINETO_NOXPUPTI OFF CACHE STRING "")
1572
    message(STATUS "Using Kineto with XPUPTI support")
1573
  endif()
1574

1575
  if(LIBKINETO_NOCUPTI AND LIBKINETO_NOROCTRACER AND LIBKINETO_NOXPUPTI)
1576
    message(STATUS "Using CPU-only version of Kineto")
1577
  endif()
1578

1579
  set(CAFFE2_THIRD_PARTY_ROOT "${PROJECT_SOURCE_DIR}/third_party" CACHE STRING "")
1580
  set(KINETO_SOURCE_DIR "${CAFFE2_THIRD_PARTY_ROOT}/kineto/libkineto" CACHE STRING "")
1581
  set(KINETO_BUILD_TESTS OFF CACHE BOOL "")
1582
  set(KINETO_LIBRARY_TYPE "static" CACHE STRING "")
1583

1584
  message(STATUS "Configuring Kineto dependency:")
1585
  message(STATUS "  KINETO_SOURCE_DIR = ${KINETO_SOURCE_DIR}")
1586
  message(STATUS "  KINETO_BUILD_TESTS = ${KINETO_BUILD_TESTS}")
1587
  message(STATUS "  KINETO_LIBRARY_TYPE = ${KINETO_LIBRARY_TYPE}")
1588

1589
  if(NOT LIBKINETO_NOCUPTI)
1590
    set(CUDA_SOURCE_DIR "${CUDA_TOOLKIT_ROOT_DIR}" CACHE STRING "")
1591
    message(STATUS "  CUDA_SOURCE_DIR = ${CUDA_SOURCE_DIR}")
1592
    message(STATUS "  CUDA_INCLUDE_DIRS = ${CUDA_INCLUDE_DIRS}")
1593

1594
    if(NOT MSVC)
1595
      if(USE_CUPTI_SO)
1596
        set(CUPTI_LIB_NAME "libcupti.so")
1597
      else()
1598
        set(CUPTI_LIB_NAME "libcupti_static.a")
1599
      endif()
1600
    else()
1601
      set(CUPTI_LIB_NAME "cupti.lib")
1602
    endif()
1603

1604
    find_library(CUPTI_LIBRARY_PATH ${CUPTI_LIB_NAME} PATHS
1605
        ${CUDA_SOURCE_DIR}
1606
        ${CUDA_SOURCE_DIR}/extras/CUPTI/lib64
1607
        ${CUDA_SOURCE_DIR}/lib
1608
        ${CUDA_SOURCE_DIR}/lib64
1609
        NO_DEFAULT_PATH)
1610

1611
    find_path(CUPTI_INCLUDE_DIR cupti.h PATHS
1612
        ${CUDA_SOURCE_DIR}/extras/CUPTI/include
1613
        ${CUDA_INCLUDE_DIRS}
1614
        ${CUDA_SOURCE_DIR}
1615
        ${CUDA_SOURCE_DIR}/include
1616
        NO_DEFAULT_PATH)
1617

1618
    if(CUPTI_LIBRARY_PATH AND CUPTI_INCLUDE_DIR)
1619
      message(STATUS "  CUPTI_INCLUDE_DIR = ${CUPTI_INCLUDE_DIR}")
1620
      set(CUDA_cupti_LIBRARY ${CUPTI_LIBRARY_PATH})
1621
      message(STATUS "  CUDA_cupti_LIBRARY = ${CUDA_cupti_LIBRARY}")
1622
      message(STATUS "Found CUPTI")
1623
      set(LIBKINETO_NOCUPTI OFF CACHE STRING "" FORCE)
1624

1625
      # I've only tested this sanity check on Linux; if someone
1626
      # runs into this bug on another platform feel free to
1627
      # generalize it accordingly
1628
      if(NOT USE_CUPTI_SO AND UNIX)
1629
        include(CheckCXXSourceRuns)
1630
        # rt is handled by the CMAKE_REQUIRED_LIBRARIES set above
1631
        if(NOT APPLE)
1632
          set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} "dl" "pthread")
1633
        endif()
1634
        set(CMAKE_REQUIRED_LINK_OPTIONS "-Wl,--whole-archive,${CUPTI_LIBRARY_PATH},--no-whole-archive")
1635
        check_cxx_source_runs("#include <stdexcept>
1636
  int main() {
1637
    try {
1638
      throw std::runtime_error(\"error\");
1639
    } catch (...) {
1640
      return 0;
1641
    }
1642
    return 1;
1643
  }" EXCEPTIONS_WORK)
1644
        set(CMAKE_REQUIRED_LINK_OPTIONS "")
1645
        if(NOT EXCEPTIONS_WORK)
1646
          message(FATAL_ERROR "Detected that statically linking against CUPTI causes exceptions to stop working.  See https://github.com/pytorch/pytorch/issues/57744 for more details.  Perhaps try: USE_CUPTI_SO=1 python setup.py develop --cmake")
1647
        endif()
1648
      endif()
1649

1650
    else()
1651
      message(STATUS "Could not find CUPTI library, using CPU-only Kineto build")
1652
      set(LIBKINETO_NOCUPTI ON CACHE STRING "" FORCE)
1653
    endif()
1654
  endif()
1655

1656
  if(NOT LIBKINETO_NOROCTRACER)
1657
    if("$ENV{ROCM_SOURCE_DIR}" STREQUAL "")
1658
      set(ENV{ROCM_SOURCE_DIR} "/opt/rocm")
1659
    endif()
1660
  endif()
1661

1662
  if(NOT TARGET kineto)
1663
    add_subdirectory("${KINETO_SOURCE_DIR}")
1664
    set_property(TARGET kineto PROPERTY POSITION_INDEPENDENT_CODE ON)
1665
  endif()
1666
  list(APPEND Caffe2_DEPENDENCY_LIBS kineto)
1667
  string(APPEND CMAKE_CXX_FLAGS " -DUSE_KINETO")
1668
  if(LIBKINETO_NOCUPTI)
1669
    string(APPEND CMAKE_CXX_FLAGS " -DLIBKINETO_NOCUPTI")
1670
  endif()
1671
  if(LIBKINETO_NOROCTRACER)
1672
    string(APPEND CMAKE_CXX_FLAGS " -DLIBKINETO_NOROCTRACER")
1673
  endif()
1674
  if(LIBKINETO_NOXPUPTI)
1675
    string(APPEND CMAKE_CXX_FLAGS " -DLIBKINETO_NOXPUPTI=ON")
1676
  else()
1677
    string(APPEND CMAKE_CXX_FLAGS " -DLIBKINETO_NOXPUPTI=OFF")
1678
  endif()
1679
  if(LIBKINETO_NOCUPTI AND LIBKINETO_NOROCTRACER AND LIBKINETO_NOXPUPTI)
1680
    message(STATUS "Configured Kineto (CPU)")
1681
  else()
1682
    message(STATUS "Configured Kineto")
1683
  endif()
1684
endif()
1685

1686
# Include google/FlatBuffers
1687
include(${CMAKE_CURRENT_LIST_DIR}/FlatBuffers.cmake)
1688

1689
# Include cpp-httplib
1690
add_library(httplib INTERFACE IMPORTED)
1691
target_include_directories(httplib SYSTEM INTERFACE ${PROJECT_SOURCE_DIR}/third_party/cpp-httplib)
1692

1693
# Include nlohmann-json
1694
add_library(nlohmann INTERFACE IMPORTED)
1695
include_directories(nlohmann SYSTEM INTERFACE ${PROJECT_SOURCE_DIR}/third_party/nlohmann/include)
1696

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.