forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDependencies.cmake
1994 lines (1808 loc) · 74.5 KB
/
Dependencies.cmake
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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# RPATH stuff
# see https://cmake.org/Wiki/CMake_RPATH_handling
if(APPLE)
set(CMAKE_MACOSX_RPATH ON)
set(_rpath_portable_origin "@loader_path")
else()
set(_rpath_portable_origin $ORIGIN)
endif(APPLE)
# Use separate rpaths during build and install phases
set(CMAKE_SKIP_BUILD_RPATH FALSE)
# Don't use the install-rpath during the build phase
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
set(CMAKE_INSTALL_RPATH "${_rpath_portable_origin}")
# Automatically add all linked folders that are NOT in the build directory to
# the rpath (per library?)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
# UBSAN triggers when compiling protobuf, so we need to disable it.
set(UBSAN_FLAG "-fsanitize=undefined")
macro(disable_ubsan)
if(CMAKE_C_FLAGS MATCHES ${UBSAN_FLAG} OR CMAKE_CXX_FLAGS MATCHES ${UBSAN_FLAG})
set(CAFFE2_UBSAN_ENABLED ON)
string(REPLACE ${UBSAN_FLAG} "" CMAKE_C_FLAGS ${CMAKE_C_FLAGS})
string(REPLACE ${UBSAN_FLAG} "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
endif()
endmacro()
macro(enable_ubsan)
if(CAFFE2_UBSAN_ENABLED)
set(CMAKE_C_FLAGS "${UBSAN_FLAG} ${CMAKE_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${UBSAN_FLAG} ${CMAKE_CXX_FLAGS}")
endif()
endmacro()
# ---[ CUDA
if(USE_CUDA)
# public/*.cmake uses CAFFE2_USE_*
set(CAFFE2_USE_CUDA ${USE_CUDA})
set(CAFFE2_USE_CUDNN ${USE_CUDNN})
set(CAFFE2_USE_NVRTC ${USE_NVRTC})
set(CAFFE2_USE_TENSORRT ${USE_TENSORRT})
include(${CMAKE_CURRENT_LIST_DIR}/public/cuda.cmake)
if(CAFFE2_USE_CUDA)
# A helper variable recording the list of Caffe2 dependent libraries
# torch::cudart is dealt with separately, due to CUDA_ADD_LIBRARY
# design reason (it adds CUDA_LIBRARIES itself).
set(Caffe2_PUBLIC_CUDA_DEPENDENCY_LIBS
caffe2::cufft caffe2::curand caffe2::cublas)
if(CAFFE2_USE_NVRTC)
list(APPEND Caffe2_PUBLIC_CUDA_DEPENDENCY_LIBS caffe2::cuda caffe2::nvrtc)
else()
caffe2_update_option(USE_NVRTC OFF)
endif()
if(CAFFE2_USE_CUDNN)
list(APPEND Caffe2_PUBLIC_CUDA_DEPENDENCY_LIBS caffe2::cudnn-public)
else()
caffe2_update_option(USE_CUDNN OFF)
endif()
if(CAFFE2_USE_TENSORRT)
list(APPEND Caffe2_PUBLIC_CUDA_DEPENDENCY_LIBS caffe2::tensorrt)
else()
caffe2_update_option(USE_TENSORRT OFF)
endif()
else()
message(WARNING
"Not compiling with CUDA. Suppress this warning with "
"-DUSE_CUDA=OFF.")
caffe2_update_option(USE_CUDA OFF)
caffe2_update_option(USE_CUDNN OFF)
caffe2_update_option(USE_NVRTC OFF)
caffe2_update_option(USE_TENSORRT OFF)
set(CAFFE2_USE_CUDA OFF)
set(CAFFE2_USE_CUDNN OFF)
set(CAFFE2_USE_NVRTC OFF)
set(CAFFE2_USE_TENSORRT OFF)
endif()
endif()
# ---[ Custom Protobuf
if(CAFFE2_CMAKE_BUILDING_WITH_MAIN_REPO AND (NOT INTERN_BUILD_MOBILE OR BUILD_CAFFE2_MOBILE))
disable_ubsan()
include(${CMAKE_CURRENT_LIST_DIR}/ProtoBuf.cmake)
enable_ubsan()
endif()
# For MSVC,
# 1. Remove /Zi, /ZI and /Z7 for Release, MinSizeRel and Default builds
# 2. Switch off incremental linking in debug builds
# 3. If MSVC_Z7_OVERRIDE is ON, then /Zi and /ZI will be replaced with /Z7
# for Debug and RelWithDebInfo builds
if(MSVC)
# skip unwanted includes from windows.h
add_definitions(-DWIN32_LEAN_AND_MEAN)
foreach(flag_var
CMAKE_C_FLAGS CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_MINSIZEREL
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_MINSIZEREL)
if(${flag_var} MATCHES "/Z[iI7]")
string(REGEX REPLACE "/Z[iI7]" "" ${flag_var} "${${flag_var}}")
endif()
endforeach(flag_var)
if(MSVC_Z7_OVERRIDE)
foreach(flag_var
CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELWITHDEBINFO
CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELWITHDEBINFO)
if(${flag_var} MATCHES "/Z[iI]")
string(REGEX REPLACE "/Z[iI]" "/Z7" ${flag_var} "${${flag_var}}")
endif()
endforeach(flag_var)
endif(MSVC_Z7_OVERRIDE)
foreach(flag_var
CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO
CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO
CMAKE_SHARED_LINKER_FLAGS_DEBUG CMAKE_STATIC_LINKER_FLAGS_DEBUG
CMAKE_EXE_LINKER_FLAGS_DEBUG CMAKE_MODULE_LINKER_FLAGS_DEBUG)
if(${flag_var} MATCHES "/INCREMENTAL" AND NOT ${flag_var} MATCHES "/INCREMENTAL:NO")
string(REGEX REPLACE "/INCREMENTAL" "/INCREMENTAL:NO" ${flag_var} "${${flag_var}}")
endif()
endforeach(flag_var)
endif(MSVC)
# ---[ Threads
include(${CMAKE_CURRENT_LIST_DIR}/public/threads.cmake)
if(TARGET caffe2::Threads)
list(APPEND Caffe2_PUBLIC_DEPENDENCY_LIBS caffe2::Threads)
else()
message(FATAL_ERROR
"Cannot find threading library. Caffe2 requires Threads to compile.")
endif()
if(USE_TBB)
if(USE_SYSTEM_TBB)
find_package(TBB 2018.0 REQUIRED CONFIG COMPONENTS tbb)
get_target_property(TBB_INCLUDE_DIR TBB::tbb INTERFACE_INCLUDE_DIRECTORIES)
else()
message(STATUS "Compiling TBB from source")
# Unset our restrictive C++ flags here and reset them later.
# Remove this once we use proper target_compile_options.
set(OLD_CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
set(CMAKE_CXX_FLAGS)
set(TBB_ROOT_DIR "${PROJECT_SOURCE_DIR}/third_party/tbb")
set(TBB_BUILD_STATIC OFF CACHE BOOL " " FORCE)
set(TBB_BUILD_SHARED ON CACHE BOOL " " FORCE)
set(TBB_BUILD_TBBMALLOC OFF CACHE BOOL " " FORCE)
set(TBB_BUILD_TBBMALLOC_PROXY OFF CACHE BOOL " " FORCE)
set(TBB_BUILD_TESTS OFF CACHE BOOL " " FORCE)
add_subdirectory(${PROJECT_SOURCE_DIR}/aten/src/ATen/cpu/tbb)
set_property(TARGET tbb tbb_def_files PROPERTY FOLDER "dependencies")
set(CMAKE_CXX_FLAGS ${OLD_CMAKE_CXX_FLAGS})
set(TBB_INCLUDE_DIR "${TBB_ROOT_DIR}/include")
add_library(TBB::tbb ALIAS tbb)
endif()
endif()
# ---[ protobuf
if(CAFFE2_CMAKE_BUILDING_WITH_MAIN_REPO)
if(USE_LITE_PROTO)
set(CAFFE2_USE_LITE_PROTO 1)
endif()
endif()
# ---[ BLAS
# setting default preferred BLAS options if not already present.
if(NOT INTERN_BUILD_MOBILE)
set(BLAS "MKL" CACHE STRING "Selected BLAS library")
else()
set(BLAS "Eigen" CACHE STRING "Selected BLAS library")
set(AT_MKLDNN_ENABLED 0)
set(AT_MKL_ENABLED 0)
endif()
set_property(CACHE BLAS PROPERTY STRINGS "ATLAS;BLIS;Eigen;FLAME;Generic;MKL;OpenBLAS;vecLib")
message(STATUS "Trying to find preferred BLAS backend of choice: " ${BLAS})
if(BLAS STREQUAL "Eigen")
# Eigen is header-only and we do not have any dependent libraries
set(CAFFE2_USE_EIGEN_FOR_BLAS ON)
elseif(BLAS STREQUAL "ATLAS")
find_package(Atlas REQUIRED)
include_directories(SYSTEM ${ATLAS_INCLUDE_DIRS})
list(APPEND Caffe2_DEPENDENCY_LIBS ${ATLAS_LIBRARIES})
list(APPEND Caffe2_DEPENDENCY_LIBS cblas)
set(BLAS_INFO "atlas")
set(BLAS_FOUND 1)
set(BLAS_LIBRARIES ${ATLAS_LIBRARIES} cblas)
elseif(BLAS STREQUAL "OpenBLAS")
find_package(OpenBLAS REQUIRED)
include_directories(SYSTEM ${OpenBLAS_INCLUDE_DIR})
list(APPEND Caffe2_DEPENDENCY_LIBS ${OpenBLAS_LIB})
set(BLAS_INFO "open")
set(BLAS_FOUND 1)
set(BLAS_LIBRARIES ${OpenBLAS_LIB})
elseif(BLAS STREQUAL "BLIS")
find_package(BLIS REQUIRED)
include_directories(SYSTEM ${BLIS_INCLUDE_DIR})
list(APPEND Caffe2_DEPENDENCY_LIBS ${BLIS_LIB})
elseif(BLAS STREQUAL "MKL")
if(BLAS_SET_BY_USER)
find_package(MKL REQUIRED)
else()
find_package(MKL QUIET)
endif()
include(${CMAKE_CURRENT_LIST_DIR}/public/mkl.cmake)
if(MKL_FOUND)
message(STATUS "MKL libraries: ${MKL_LIBRARIES}")
message(STATUS "MKL include directory: ${MKL_INCLUDE_DIR}")
message(STATUS "MKL OpenMP type: ${MKL_OPENMP_TYPE}")
message(STATUS "MKL OpenMP library: ${MKL_OPENMP_LIBRARY}")
include_directories(AFTER SYSTEM ${MKL_INCLUDE_DIR})
list(APPEND Caffe2_PUBLIC_DEPENDENCY_LIBS caffe2::mkl)
set(CAFFE2_USE_MKL ON)
set(BLAS_INFO "mkl")
set(BLAS_FOUND 1)
set(BLAS_LIBRARIES ${MKL_LIBRARIES})
else()
message(WARNING "MKL could not be found. Defaulting to Eigen")
set(CAFFE2_USE_EIGEN_FOR_BLAS ON)
set(CAFFE2_USE_MKL OFF)
endif()
elseif(BLAS STREQUAL "vecLib")
find_package(vecLib REQUIRED)
include_directories(SYSTEM ${vecLib_INCLUDE_DIR})
list(APPEND Caffe2_DEPENDENCY_LIBS ${vecLib_LINKER_LIBS})
set(BLAS_INFO "veclib")
set(BLAS_FOUND 1)
set(BLAS_LIBRARIES ${vecLib_LINKER_LIBS})
elseif(BLAS STREQUAL "FlexiBLAS")
find_package(FlexiBLAS REQUIRED)
include_directories(SYSTEM ${FlexiBLAS_INCLUDE_DIR})
list(APPEND Caffe2_DEPENDENCY_LIBS ${FlexiBLAS_LIB})
elseif(BLAS STREQUAL "Generic")
# On Debian family, the CBLAS ABIs have been merged into libblas.so
if(ENV{GENERIC_BLAS_LIBRARIES} STREQUAL "")
set(GENERIC_BLAS "blas")
else()
set(GENERIC_BLAS $ENV{GENERIC_BLAS_LIBRARIES})
endif()
find_library(BLAS_LIBRARIES NAMES ${GENERIC_BLAS})
message("-- Using BLAS: ${BLAS_LIBRARIES}")
list(APPEND Caffe2_DEPENDENCY_LIBS ${BLAS_LIBRARIES})
set(GENERIC_BLAS_FOUND TRUE)
set(BLAS_INFO "generic")
set(BLAS_FOUND 1)
else()
message(FATAL_ERROR "Unrecognized BLAS option: " ${BLAS})
endif()
if(NOT INTERN_BUILD_MOBILE)
set(AT_MKL_ENABLED 0)
set(AT_MKL_SEQUENTIAL 0)
set(AT_MKL_MT 0)
set(USE_BLAS 1)
if(NOT (ATLAS_FOUND OR BLIS_FOUND OR GENERIC_BLAS_FOUND OR MKL_FOUND OR OpenBLAS_FOUND OR VECLIB_FOUND OR FlexiBLAS_FOUND))
message(WARNING "Preferred BLAS (" ${BLAS} ") cannot be found, now searching for a general BLAS library")
find_package(BLAS)
if(NOT BLAS_FOUND)
set(USE_BLAS 0)
endif()
endif()
if(MKL_FOUND)
if("${MKL_THREADING}" STREQUAL "SEQ")
set(AT_MKL_SEQUENTIAL 1)
endif()
if(MSVC AND MKL_LIBRARIES MATCHES ".*libiomp5md\\.lib.*")
add_definitions(-D_OPENMP_NOFORCE_MANIFEST)
set(AT_MKL_MT 1)
endif()
set(AT_MKL_ENABLED 1)
endif()
elseif(INTERN_USE_EIGEN_BLAS)
# Eigen BLAS for Mobile
set(USE_BLAS 1)
include(${CMAKE_CURRENT_LIST_DIR}/External/EigenBLAS.cmake)
list(APPEND Caffe2_DEPENDENCY_LIBS eigen_blas)
endif()
# ---[ FFTW
set(AT_FFTW_ENABLED 0)
set(USE_FFTW OFF)
if(USE_FFTW OR NOT MKL_FOUND)
find_library(LIBFFTW3 fftw3)
if(LIBFFTW3)
find_path(FFTW3_INCLUDE_DIR NAMES fftw3.h ONLY_CMAKE_FIND_ROOT_PATH)
if(FFTW3_INCLUDE_DIR)
SET(AT_FFTW_ENABLED 1)
SET(USE_FFTW ON)
include_directories(${FFTW3_INCLUDE_DIR})
endif()
endif()
endif()
# --- [ PocketFFT
set(AT_POCKETFFT_ENABLED 0)
if(NOT AT_MKL_ENABLED)
set(POCKETFFT_INCLUDE_DIR "${Torch_SOURCE_DIR}/third_party/pocketfft/")
if(NOT EXISTS "${POCKETFFT_INCLUDE_DIR}")
message(FATAL_ERROR "pocketfft directory not found, expected ${POCKETFFT_INCLUDE_DIR}")
elif(NOT EXISTS "${POCKETFFT_INCLUDE_DIR}/pocketfft_hdronly.h")
message(FATAL_ERROR "pocketfft headers not found in ${POCKETFFT_INCLUDE_DIR}")
endif()
set(AT_POCKETFFT_ENABLED 1)
message(STATUS "Using pocketfft in directory: ${POCKETFFT_INCLUDE_DIR}")
endif()
# ---[ Dependencies
# NNPACK and family (QNNPACK, PYTORCH_QNNPACK, and XNNPACK) can download and
# compile their dependencies in isolation as part of their build. These dependencies
# are then linked statically with PyTorch. To avoid the possibility of a version
# mismatch between these shared dependencies, explicitly declare our intent to these
# libraries that we are interested in using the exact same source dependencies for all.
if(USE_NNPACK OR USE_QNNPACK OR USE_PYTORCH_QNNPACK OR USE_XNNPACK)
set(DISABLE_NNPACK_AND_FAMILY OFF)
# Sanity checks - Can we actually build NNPACK and family given the configuration provided?
# Disable them and warn the user if not.
if(IOS)
list(LENGTH IOS_ARCH IOS_ARCH_COUNT)
if(IOS_ARCH_COUNT GREATER 1)
message(WARNING
"Multi-architecture (${IOS_ARCH}) builds are not supported in {Q/X}NNPACK. "
"Specify a single architecture in IOS_ARCH and re-configure, or "
"turn this warning off by USE_{Q/X}NNPACK=OFF.")
set(DISABLE_NNPACK_AND_FAMILY ON)
endif()
if(NOT IOS_ARCH MATCHES "^(i386|x86_64|armv7.*|arm64.*)$")
message(WARNING
"Target architecture \"${IOS_ARCH}\" is not supported in {Q/X}NNPACK. "
"Supported architectures are x86, x86-64, ARM, and ARM64. "
"Turn this warning off by USE_{Q/X}NNPACK=OFF.")
set(DISABLE_NNPACK_AND_FAMILY ON)
endif()
else()
if(NOT IOS AND NOT (CMAKE_SYSTEM_NAME MATCHES "^(Android|Linux|Darwin|Windows)$"))
message(WARNING
"Target platform \"${CMAKE_SYSTEM_NAME}\" is not supported in {Q/X}NNPACK. "
"Supported platforms are Android, iOS, Linux, and macOS. "
"Turn this warning off by USE_{Q/X}NNPACK=OFF.")
set(DISABLE_NNPACK_AND_FAMILY ON)
endif()
if(NOT IOS AND NOT (CMAKE_SYSTEM_PROCESSOR MATCHES "^(i686|AMD64|x86_64|armv[0-9].*|arm64|aarch64)$"))
message(WARNING
"Target architecture \"${CMAKE_SYSTEM_PROCESSOR}\" is not supported in {Q/X}NNPACK. "
"Supported architectures are x86, x86-64, ARM, and ARM64. "
"Turn this warning off by USE_{Q/X}NNPACK=OFF.")
set(DISABLE_NNPACK_AND_FAMILY ON)
endif()
endif()
if(DISABLE_NNPACK_AND_FAMILY)
caffe2_update_option(USE_NNPACK OFF)
caffe2_update_option(USE_QNNPACK OFF)
caffe2_update_option(USE_PYTORCH_QNNPACK OFF)
caffe2_update_option(USE_XNNPACK OFF)
else()
# Disable unsupported NNPack combinations with MSVC
if(MSVC)
caffe2_update_option(USE_NNPACK OFF)
caffe2_update_option(USE_QNNPACK OFF)
caffe2_update_option(USE_PYTORCH_QNNPACK OFF)
endif()
set(CAFFE2_THIRD_PARTY_ROOT "${PROJECT_SOURCE_DIR}/third_party")
if(NOT DEFINED CPUINFO_SOURCE_DIR)
set(CPUINFO_SOURCE_DIR "${CAFFE2_THIRD_PARTY_ROOT}/cpuinfo" CACHE STRING "cpuinfo source directory")
endif()
if(NOT DEFINED FP16_SOURCE_DIR)
set(FP16_SOURCE_DIR "${CAFFE2_THIRD_PARTY_ROOT}/FP16" CACHE STRING "FP16 source directory")
endif()
if(NOT DEFINED FXDIV_SOURCE_DIR)
set(FXDIV_SOURCE_DIR "${CAFFE2_THIRD_PARTY_ROOT}/FXdiv" CACHE STRING "FXdiv source directory")
endif()
if(NOT DEFINED PSIMD_SOURCE_DIR)
set(PSIMD_SOURCE_DIR "${CAFFE2_THIRD_PARTY_ROOT}/psimd" CACHE STRING "PSimd source directory")
endif()
if(NOT DEFINED PTHREADPOOL_SOURCE_DIR)
set(PTHREADPOOL_SOURCE_DIR "${CAFFE2_THIRD_PARTY_ROOT}/pthreadpool" CACHE STRING "pthreadpool source directory")
endif()
endif()
else()
set(DISABLE_NNPACK_AND_FAMILY ON)
endif()
if(USE_QNNPACK AND CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64" AND CMAKE_SYSTEM_NAME STREQUAL "Darwin")
message(WARNING
"QNNPACK does not compile for Apple Silicon. "
"Turn this warning off by explicit USE_QNNPACK=OFF.")
caffe2_update_option(USE_QNNPACK OFF)
endif()
set(CONFU_DEPENDENCIES_SOURCE_DIR ${PROJECT_BINARY_DIR}/confu-srcs
CACHE PATH "Confu-style dependencies source directory")
set(CONFU_DEPENDENCIES_BINARY_DIR ${PROJECT_BINARY_DIR}/confu-deps
CACHE PATH "Confu-style dependencies binary directory")
# ---[ pthreadpool
# Only add a dependency on pthreadpool if we are on a mobile build
# or are building any of the libraries in the {Q/X}NNPACK family.
if(INTERN_BUILD_MOBILE OR NOT DISABLE_NNPACK_AND_FAMILY)
set(USE_PTHREADPOOL ON CACHE BOOL "" FORCE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_PTHREADPOOL")
# Always use third_party/pthreadpool.
set(USE_INTERNAL_PTHREADPOOL_IMPL OFF CACHE BOOL "" FORCE)
if(NOT TARGET pthreadpool)
if(USE_SYSTEM_PTHREADPOOL)
add_library(pthreadpool SHARED IMPORTED)
find_library(PTHREADPOOL_LIBRARY pthreadpool)
set_property(TARGET pthreadpool PROPERTY IMPORTED_LOCATION "${PTHREADPOOL_LIBRARY}")
if(NOT PTHREADPOOL_LIBRARY)
message(FATAL_ERROR "Cannot find pthreadpool")
endif()
message("-- Found pthreadpool: ${PTHREADPOOL_LIBRARY}")
elseif(NOT USE_INTERNAL_PTHREADPOOL_IMPL)
if(NOT DEFINED PTHREADPOOL_SOURCE_DIR)
set(CAFFE2_THIRD_PARTY_ROOT "${PROJECT_SOURCE_DIR}/third_party")
set(PTHREADPOOL_SOURCE_DIR "${CAFFE2_THIRD_PARTY_ROOT}/pthreadpool" CACHE STRING "pthreadpool source directory")
endif()
set(PTHREADPOOL_BUILD_TESTS OFF CACHE BOOL "")
set(PTHREADPOOL_BUILD_BENCHMARKS OFF CACHE BOOL "")
set(PTHREADPOOL_LIBRARY_TYPE "static" CACHE STRING "")
set(PTHREADPOOL_ALLOW_DEPRECATED_API ON CACHE BOOL "")
add_subdirectory(
"${PTHREADPOOL_SOURCE_DIR}"
"${CONFU_DEPENDENCIES_BINARY_DIR}/pthreadpool")
set_property(TARGET pthreadpool PROPERTY POSITION_INDEPENDENT_CODE ON)
endif()
if(USE_INTERNAL_PTHREADPOOL_IMPL)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_INTERNAL_PTHREADPOOL_IMPL")
else()
list(APPEND Caffe2_DEPENDENCY_LIBS pthreadpool)
endif()
endif()
else()
set(USE_PTHREADPOOL OFF CACHE BOOL "" FORCE)
endif()
# ---[ Caffe2 uses cpuinfo library in the thread pool
if(NOT TARGET cpuinfo AND USE_SYSTEM_CPUINFO)
add_library(cpuinfo SHARED IMPORTED)
find_library(CPUINFO_LIBRARY cpuinfo)
if(NOT CPUINFO_LIBRARY)
message(FATAL_ERROR "Cannot find cpuinfo")
endif()
message("Found cpuinfo: ${CPUINFO_LIBRARY}")
set_target_properties(cpuinfo PROPERTIES IMPORTED_LOCATION "${CPUINFO_LIBRARY}")
elseif(NOT TARGET cpuinfo)
if(NOT DEFINED CPUINFO_SOURCE_DIR)
set(CPUINFO_SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/../third_party/cpuinfo" CACHE STRING "cpuinfo source directory")
endif()
set(CPUINFO_BUILD_TOOLS OFF CACHE BOOL "")
set(CPUINFO_BUILD_UNIT_TESTS OFF CACHE BOOL "")
set(CPUINFO_BUILD_MOCK_TESTS OFF CACHE BOOL "")
set(CPUINFO_BUILD_BENCHMARKS OFF CACHE BOOL "")
set(CPUINFO_LIBRARY_TYPE "static" CACHE STRING "")
set(CPUINFO_LOG_LEVEL "error" CACHE STRING "")
if(MSVC)
if(CAFFE2_USE_MSVC_STATIC_RUNTIME)
set(CPUINFO_RUNTIME_TYPE "static" CACHE STRING "")
else()
set(CPUINFO_RUNTIME_TYPE "shared" CACHE STRING "")
endif()
endif()
add_subdirectory(
"${CPUINFO_SOURCE_DIR}"
"${CONFU_DEPENDENCIES_BINARY_DIR}/cpuinfo")
# We build static version of cpuinfo but link
# them into a shared library for Caffe2, so they need PIC.
set_property(TARGET cpuinfo PROPERTY POSITION_INDEPENDENT_CODE ON)
# Need to set this to avoid conflict with XNNPACK's clog external project
set(CLOG_SOURCE_DIR "${CPUINFO_SOURCE_DIR}/deps/clog")
endif()
list(APPEND Caffe2_DEPENDENCY_LIBS cpuinfo)
# ---[ QNNPACK
if(USE_QNNPACK)
set(CAFFE2_THIRD_PARTY_ROOT "${PROJECT_SOURCE_DIR}/third_party")
if(NOT DEFINED QNNPACK_SOURCE_DIR)
set(QNNPACK_SOURCE_DIR "${CAFFE2_THIRD_PARTY_ROOT}/QNNPACK" CACHE STRING "QNNPACK source directory")
endif()
if(NOT TARGET qnnpack)
if(NOT USE_SYSTEM_PTHREADPOOL AND USE_INTERNAL_PTHREADPOOL_IMPL)
set(QNNPACK_CUSTOM_THREADPOOL ON CACHE BOOL "")
endif()
set(QNNPACK_BUILD_TESTS OFF CACHE BOOL "")
set(QNNPACK_BUILD_BENCHMARKS OFF CACHE BOOL "")
set(QNNPACK_LIBRARY_TYPE "static" CACHE STRING "")
add_subdirectory(
"${QNNPACK_SOURCE_DIR}"
"${CONFU_DEPENDENCIES_BINARY_DIR}/QNNPACK")
# TODO: See https://github.com/pytorch/pytorch/issues/56285
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_options(qnnpack PRIVATE -Wno-deprecated-declarations)
endif()
# We build static versions of QNNPACK and pthreadpool but link
# them into a shared library for Caffe2, so they need PIC.
set_property(TARGET qnnpack PROPERTY POSITION_INDEPENDENT_CODE ON)
set_property(TARGET cpuinfo PROPERTY POSITION_INDEPENDENT_CODE ON)
if(QNNPACK_CUSTOM_THREADPOOL)
target_compile_definitions(
qnnpack PRIVATE
pthreadpool_t=legacy_pthreadpool_t
pthreadpool_function_1d_t=legacy_pthreadpool_function_1d_t
pthreadpool_function_1d_tiled_t=legacy_pthreadpool_function_1d_tiled_t
pthreadpool_function_2d_t=legacy_pthreadpool_function_2d_t
pthreadpool_function_2d_tiled_t=legacy_pthreadpool_function_2d_tiled_t
pthreadpool_function_3d_tiled_t=legacy_pthreadpool_function_3d_tiled_t
pthreadpool_function_4d_tiled_t=legacy_pthreadpool_function_4d_tiled_t
pthreadpool_create=legacy_pthreadpool_create
pthreadpool_destroy=legacy_pthreadpool_destroy
pthreadpool_get_threads_count=legacy_pthreadpool_get_threads_count
pthreadpool_compute_1d=legacy_pthreadpool_compute_1d
pthreadpool_parallelize_1d=legacy_pthreadpool_parallelize_1d
pthreadpool_compute_1d_tiled=legacy_pthreadpool_compute_1d_tiled
pthreadpool_compute_2d=legacy_pthreadpool_compute_2d
pthreadpool_compute_2d_tiled=legacy_pthreadpool_compute_2d_tiled
pthreadpool_compute_3d_tiled=legacy_pthreadpool_compute_3d_tiled
pthreadpool_compute_4d_tiled=legacy_pthreadpool_compute_4d_tiled)
endif()
endif()
list(APPEND Caffe2_DEPENDENCY_LIBS qnnpack)
endif()
# ---[ Caffe2 Int8 operators (enabled by USE_QNNPACK) depend on gemmlowp and neon2sse headers
if(USE_QNNPACK)
set(CAFFE2_THIRD_PARTY_ROOT "${PROJECT_SOURCE_DIR}/third_party")
include_directories(SYSTEM "${CAFFE2_THIRD_PARTY_ROOT}/gemmlowp")
include_directories(SYSTEM "${CAFFE2_THIRD_PARTY_ROOT}/neon2sse")
endif()
# ---[ PYTORCH_QNNPACK
if(USE_PYTORCH_QNNPACK)
if(NOT DEFINED PYTORCH_QNNPACK_SOURCE_DIR)
set(PYTORCH_QNNPACK_SOURCE_DIR "${PROJECT_SOURCE_DIR}/aten/src/ATen/native/quantized/cpu/qnnpack" CACHE STRING "QNNPACK source directory")
endif()
if(NOT TARGET pytorch_qnnpack)
if(NOT USE_SYSTEM_PTHREADPOOL AND USE_INTERNAL_PTHREADPOOL_IMPL)
set(PYTORCH_QNNPACK_CUSTOM_THREADPOOL ON CACHE BOOL "")
endif()
set(PYTORCH_QNNPACK_BUILD_TESTS OFF CACHE BOOL "")
set(PYTORCH_QNNPACK_BUILD_BENCHMARKS OFF CACHE BOOL "")
set(PYTORCH_QNNPACK_LIBRARY_TYPE "static" CACHE STRING "")
add_subdirectory(
"${PYTORCH_QNNPACK_SOURCE_DIR}"
"${CONFU_DEPENDENCIES_BINARY_DIR}/pytorch_qnnpack")
# We build static versions of QNNPACK and pthreadpool but link
# them into a shared library for Caffe2, so they need PIC.
set_property(TARGET pytorch_qnnpack PROPERTY POSITION_INDEPENDENT_CODE ON)
set_property(TARGET cpuinfo PROPERTY POSITION_INDEPENDENT_CODE ON)
if(PYTORCH_QNNPACK_CUSTOM_THREADPOOL)
target_compile_definitions(
pytorch_qnnpack PRIVATE
pthreadpool_t=legacy_pthreadpool_t
pthreadpool_function_1d_t=legacy_pthreadpool_function_1d_t
pthreadpool_function_1d_tiled_t=legacy_pthreadpool_function_1d_tiled_t
pthreadpool_function_2d_t=legacy_pthreadpool_function_2d_t
pthreadpool_function_2d_tiled_t=legacy_pthreadpool_function_2d_tiled_t
pthreadpool_function_3d_tiled_t=legacy_pthreadpool_function_3d_tiled_t
pthreadpool_function_4d_tiled_t=legacy_pthreadpool_function_4d_tiled_t
pthreadpool_create=legacy_pthreadpool_create
pthreadpool_destroy=legacy_pthreadpool_destroy
pthreadpool_get_threads_count=legacy_pthreadpool_get_threads_count
pthreadpool_compute_1d=legacy_pthreadpool_compute_1d
pthreadpool_parallelize_1d=legacy_pthreadpool_parallelize_1d
pthreadpool_compute_1d_tiled=legacy_pthreadpool_compute_1d_tiled
pthreadpool_compute_2d=legacy_pthreadpool_compute_2d
pthreadpool_compute_2d_tiled=legacy_pthreadpool_compute_2d_tiled
pthreadpool_compute_3d_tiled=legacy_pthreadpool_compute_3d_tiled
pthreadpool_compute_4d_tiled=legacy_pthreadpool_compute_4d_tiled)
endif()
endif()
list(APPEND Caffe2_DEPENDENCY_LIBS pytorch_qnnpack)
endif()
# ---[ NNPACK
if(USE_NNPACK)
include(${CMAKE_CURRENT_LIST_DIR}/External/nnpack.cmake)
if(NNPACK_FOUND)
if(TARGET nnpack)
# ---[ NNPACK is being built together with Caffe2: explicitly specify dependency
list(APPEND Caffe2_DEPENDENCY_LIBS nnpack)
else()
include_directories(SYSTEM ${NNPACK_INCLUDE_DIRS})
list(APPEND Caffe2_DEPENDENCY_LIBS ${NNPACK_LIBRARIES})
endif()
else()
message(WARNING "Not compiling with NNPACK. Suppress this warning with -DUSE_NNPACK=OFF")
caffe2_update_option(USE_NNPACK OFF)
endif()
endif()
# ---[ XNNPACK
if(USE_XNNPACK AND NOT USE_SYSTEM_XNNPACK)
if(NOT DEFINED XNNPACK_SOURCE_DIR)
set(XNNPACK_SOURCE_DIR "${CAFFE2_THIRD_PARTY_ROOT}/XNNPACK" CACHE STRING "XNNPACK source directory")
endif()
if(NOT DEFINED XNNPACK_INCLUDE_DIR)
set(XNNPACK_INCLUDE_DIR "${XNNPACK_SOURCE_DIR}/include" CACHE STRING "XNNPACK include directory")
endif()
if(NOT TARGET XNNPACK)
set(XNNPACK_LIBRARY_TYPE "static" CACHE STRING "")
set(XNNPACK_BUILD_BENCHMARKS OFF CACHE BOOL "")
set(XNNPACK_BUILD_TESTS OFF CACHE BOOL "")
add_subdirectory(
"${XNNPACK_SOURCE_DIR}"
"${CONFU_DEPENDENCIES_BINARY_DIR}/XNNPACK")
set_property(TARGET XNNPACK PROPERTY POSITION_INDEPENDENT_CODE ON)
# Workaround for https://github.com/pytorch/pytorch/issues/47292
if(CMAKE_BUILD_TYPE STREQUAL "Debug" AND CMAKE_COMPILER_IS_GNUCXX AND (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.5.0))
# Compiling qu8-requantization/precise-psimd.c without any optimization flags on gcc-7.4 or older i
# Fails with internal compiler error
# Workaround by forcing -O1 for XNNPACK (i.e. build it with RelWithDebInfo)
set_property(TARGET XNNPACK APPEND_STRING PROPERTY COMPILE_FLAGS "-O1")
endif()
endif()
include_directories(SYSTEM ${XNNPACK_INCLUDE_DIR})
list(APPEND Caffe2_DEPENDENCY_LIBS XNNPACK)
elseif(NOT TARGET XNNPACK AND USE_SYSTEM_XNNPACK)
add_library(XNNPACK SHARED IMPORTED)
find_library(XNNPACK_LIBRARY XNNPACK)
set_property(TARGET XNNPACK PROPERTY IMPORTED_LOCATION "${XNNPACK_LIBRARY}")
if(NOT XNNPACK_LIBRARY)
message(FATAL_ERROR "Cannot find XNNPACK")
endif()
message("-- Found XNNPACK: ${XNNPACK_LIBRARY}")
list(APPEND Caffe2_DEPENDENCY_LIBS XNNPACK)
endif()
# ---[ Vulkan deps
if(USE_VULKAN)
set(Vulkan_DEFINES)
set(Vulkan_INCLUDES)
set(Vulkan_LIBS)
include(${CMAKE_CURRENT_LIST_DIR}/VulkanDependencies.cmake)
string(APPEND CMAKE_CXX_FLAGS ${Vulkan_DEFINES})
include_directories(SYSTEM ${Vulkan_INCLUDES})
list(APPEND Caffe2_DEPENDENCY_LIBS ${Vulkan_LIBS})
endif()
# ---[ gflags
if(USE_GFLAGS)
include(${CMAKE_CURRENT_LIST_DIR}/public/gflags.cmake)
if(NOT TARGET gflags)
message(WARNING
"gflags is not found. Caffe2 will build without gflags support but "
"it is strongly recommended that you install gflags. Suppress this "
"warning with -DUSE_GFLAGS=OFF")
caffe2_update_option(USE_GFLAGS OFF)
endif()
endif()
# ---[ Google-glog
if(USE_GLOG)
include(${CMAKE_CURRENT_LIST_DIR}/public/glog.cmake)
if(TARGET glog::glog)
set(CAFFE2_USE_GOOGLE_GLOG 1)
include_directories(SYSTEM ${GLOG_INCLUDE_DIR})
list(APPEND Caffe2_PUBLIC_DEPENDENCY_LIBS glog::glog)
else()
message(WARNING
"glog is not found. Caffe2 will build without glog support but it is "
"strongly recommended that you install glog. Suppress this warning "
"with -DUSE_GLOG=OFF")
caffe2_update_option(USE_GLOG OFF)
endif()
endif()
# ---[ Googletest and benchmark
if(BUILD_TEST OR BUILD_MOBILE_BENCHMARK OR BUILD_MOBILE_TEST)
# Preserve build options.
set(TEMP_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS})
# We will build gtest as static libs and embed it directly into the binary.
set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared libs" FORCE)
# For gtest, we will simply embed it into our test binaries, so we won't
# need to install it.
set(INSTALL_GTEST OFF CACHE BOOL "Install gtest." FORCE)
set(BUILD_GMOCK ON CACHE BOOL "Build gmock." FORCE)
# For Windows, we will check the runtime used is correctly passed in.
if(NOT CAFFE2_USE_MSVC_STATIC_RUNTIME)
set(gtest_force_shared_crt ON CACHE BOOL "force shared crt on gtest" FORCE)
endif()
# We need to replace googletest cmake scripts too.
# Otherwise, it will sometimes break the build.
# To make the git clean after the build, we make a backup first.
if((MSVC AND MSVC_Z7_OVERRIDE) OR USE_CUDA)
execute_process(
COMMAND ${CMAKE_COMMAND}
"-DFILENAME=${CMAKE_CURRENT_LIST_DIR}/../third_party/googletest/googletest/cmake/internal_utils.cmake"
"-DBACKUP=${CMAKE_CURRENT_LIST_DIR}/../third_party/googletest/googletest/cmake/internal_utils.cmake.bak"
"-DREVERT=0"
"-P"
"${CMAKE_CURRENT_LIST_DIR}/GoogleTestPatch.cmake"
RESULT_VARIABLE _exitcode)
if(NOT _exitcode EQUAL 0)
message(WARNING "Patching failed for Google Test. The build may fail.")
endif()
endif()
# Add googletest subdirectory but make sure our INCLUDE_DIRECTORIES
# don't bleed into it. This is because libraries installed into the root conda
# env (e.g. MKL) add a global /opt/conda/include directory, and if there's
# gtest installed in conda, the third_party/googletest/**.cc source files
# would try to include headers from /opt/conda/include/gtest/**.h instead of
# its own. Once we have proper target-based include directories,
# this shouldn't be necessary anymore.
get_property(INC_DIR_temp DIRECTORY PROPERTY INCLUDE_DIRECTORIES)
set_property(DIRECTORY PROPERTY INCLUDE_DIRECTORIES "")
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../third_party/googletest)
set_property(DIRECTORY PROPERTY INCLUDE_DIRECTORIES ${INC_DIR_temp})
include_directories(BEFORE SYSTEM ${CMAKE_CURRENT_LIST_DIR}/../third_party/googletest/googletest/include)
include_directories(BEFORE SYSTEM ${CMAKE_CURRENT_LIST_DIR}/../third_party/googletest/googlemock/include)
# We will not need to test benchmark lib itself.
set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "Disable benchmark testing as we don't need it.")
# We will not need to install benchmark since we link it statically.
set(BENCHMARK_ENABLE_INSTALL OFF CACHE BOOL "Disable benchmark install to avoid overwriting vendor install.")
if(NOT USE_SYSTEM_BENCHMARK)
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../third_party/benchmark)
else()
add_library(benchmark SHARED IMPORTED)
find_library(BENCHMARK_LIBRARY benchmark)
if(NOT BENCHMARK_LIBRARY)
message(FATAL_ERROR "Cannot find google benchmark library")
endif()
message("-- Found benchmark: ${BENCHMARK_LIBRARY}")
set_property(TARGET benchmark PROPERTY IMPORTED_LOCATION ${BENCHMARK_LIBRARY})
endif()
include_directories(${CMAKE_CURRENT_LIST_DIR}/../third_party/benchmark/include)
# Recover build options.
set(BUILD_SHARED_LIBS ${TEMP_BUILD_SHARED_LIBS} CACHE BOOL "Build shared libs" FORCE)
# To make the git clean after the build, we revert the changes here.
if(MSVC AND MSVC_Z7_OVERRIDE)
execute_process(
COMMAND ${CMAKE_COMMAND}
"-DFILENAME=${CMAKE_CURRENT_LIST_DIR}/../third_party/googletest/googletest/cmake/internal_utils.cmake"
"-DBACKUP=${CMAKE_CURRENT_LIST_DIR}/../third_party/googletest/googletest/cmake/internal_utils.cmake.bak"
"-DREVERT=1"
"-P"
"${CMAKE_CURRENT_LIST_DIR}/GoogleTestPatch.cmake"
RESULT_VARIABLE _exitcode)
if(NOT _exitcode EQUAL 0)
message(WARNING "Reverting changes failed for Google Test. The build may fail.")
endif()
endif()
# Cacheing variables to enable incremental build.
# Without this is cross compiling we end up having to blow build directory
# and rebuild from scratch.
if(CMAKE_CROSSCOMPILING)
if(COMPILE_HAVE_STD_REGEX)
set(RUN_HAVE_STD_REGEX 0 CACHE INTERNAL "Cache RUN_HAVE_STD_REGEX output for cross-compile.")
endif()
endif()
endif()
# ---[ FBGEMM
if(USE_FBGEMM)
set(CAFFE2_THIRD_PARTY_ROOT "${PROJECT_SOURCE_DIR}/third_party")
if(NOT DEFINED FBGEMM_SOURCE_DIR)
set(FBGEMM_SOURCE_DIR "${CAFFE2_THIRD_PARTY_ROOT}/fbgemm" CACHE STRING "FBGEMM source directory")
endif()
if(NOT CAFFE2_COMPILER_SUPPORTS_AVX512_EXTENSIONS)
message(WARNING
"A compiler with AVX512 support is required for FBGEMM. "
"Not compiling with FBGEMM. "
"Turn this warning off by USE_FBGEMM=OFF.")
set(USE_FBGEMM OFF)
endif()
if(NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
message(WARNING
"x64 operating system is required for FBGEMM. "
"Not compiling with FBGEMM. "
"Turn this warning off by USE_FBGEMM=OFF.")
set(USE_FBGEMM OFF)
endif()
if(USE_FBGEMM AND NOT TARGET fbgemm)
set(FBGEMM_BUILD_TESTS OFF CACHE BOOL "")
set(FBGEMM_BUILD_BENCHMARKS OFF CACHE BOOL "")
if(MSVC AND BUILD_SHARED_LIBS)
set(FBGEMM_LIBRARY_TYPE "shared" CACHE STRING "")
else()
set(FBGEMM_LIBRARY_TYPE "static" CACHE STRING "")
endif()
add_subdirectory("${FBGEMM_SOURCE_DIR}")
set_property(TARGET fbgemm_generic PROPERTY POSITION_INDEPENDENT_CODE ON)
set_property(TARGET fbgemm_avx2 PROPERTY POSITION_INDEPENDENT_CODE ON)
set_property(TARGET fbgemm_avx512 PROPERTY POSITION_INDEPENDENT_CODE ON)
set_property(TARGET fbgemm PROPERTY POSITION_INDEPENDENT_CODE ON)
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 13.0.0)
# See https://github.com/pytorch/pytorch/issues/74352
target_compile_options(asmjit PRIVATE -Wno-deprecated-copy)
if(("${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 13.1.6)
OR("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 13.0.0))
# -Wno-unused-but-set-variable doesn't exist in Apple clang version 13.0.0 (clang-1300.0.29.30)
target_compile_options(asmjit PRIVATE -Wno-unused-but-set-variable)
endif()
endif()
endif()
if(USE_FBGEMM)
list(APPEND Caffe2_DEPENDENCY_LIBS fbgemm)
endif()
endif()
if(USE_FBGEMM)
caffe2_update_option(USE_FBGEMM ON)
else()
caffe2_update_option(USE_FBGEMM OFF)
message(WARNING
"Turning USE_FAKELOWP off as it depends on USE_FBGEMM.")
caffe2_update_option(USE_FAKELOWP OFF)
endif()
# ---[ LMDB
if(USE_LMDB)
find_package(LMDB)
if(LMDB_FOUND)
include_directories(SYSTEM ${LMDB_INCLUDE_DIR})
list(APPEND Caffe2_DEPENDENCY_LIBS ${LMDB_LIBRARIES})
else()
message(WARNING "Not compiling with LMDB. Suppress this warning with -DUSE_LMDB=OFF")
caffe2_update_option(USE_LMDB OFF)
endif()
endif()
if(USE_OPENCL)
message(INFO "USING OPENCL")
find_package(OpenCL REQUIRED)
include_directories(SYSTEM ${OpenCL_INCLUDE_DIRS})
include_directories(${CMAKE_CURRENT_LIST_DIR}/../caffe2/contrib/opencl)
list(APPEND Caffe2_DEPENDENCY_LIBS ${OpenCL_LIBRARIES})
endif()
# ---[ LevelDB
# ---[ Snappy
if(USE_LEVELDB)
find_package(LevelDB)
find_package(Snappy)
if(LEVELDB_FOUND AND SNAPPY_FOUND)
include_directories(SYSTEM ${LevelDB_INCLUDE})
list(APPEND Caffe2_DEPENDENCY_LIBS ${LevelDB_LIBRARIES})
include_directories(SYSTEM ${Snappy_INCLUDE_DIR})
list(APPEND Caffe2_DEPENDENCY_LIBS ${Snappy_LIBRARIES})
else()
message(WARNING "Not compiling with LevelDB. Suppress this warning with -DUSE_LEVELDB=OFF")
caffe2_update_option(USE_LEVELDB OFF)
endif()
endif()
# ---[ NUMA
if(USE_NUMA)
if(LINUX)
find_package(Numa)
if(NUMA_FOUND)
include_directories(SYSTEM ${Numa_INCLUDE_DIR})
list(APPEND Caffe2_DEPENDENCY_LIBS ${Numa_LIBRARIES})
else()
message(WARNING "Not compiling with NUMA. Suppress this warning with -DUSE_NUMA=OFF")
caffe2_update_option(USE_NUMA OFF)
endif()
else()
message(WARNING "NUMA is currently only supported under Linux.")
caffe2_update_option(USE_NUMA OFF)
endif()
endif()
# ---[ ZMQ
if(USE_ZMQ)
find_package(ZMQ)
if(ZMQ_FOUND)
include_directories(SYSTEM ${ZMQ_INCLUDE_DIR})
list(APPEND Caffe2_DEPENDENCY_LIBS ${ZMQ_LIBRARIES})
else()
message(WARNING "Not compiling with ZMQ. Suppress this warning with -DUSE_ZMQ=OFF")
caffe2_update_option(USE_ZMQ OFF)
endif()
endif()
# ---[ Redis
if(USE_REDIS)
find_package(Hiredis)
if(HIREDIS_FOUND)
include_directories(SYSTEM ${Hiredis_INCLUDE})
list(APPEND Caffe2_DEPENDENCY_LIBS ${Hiredis_LIBRARIES})
else()
message(WARNING "Not compiling with Redis. Suppress this warning with -DUSE_REDIS=OFF")
caffe2_update_option(USE_REDIS OFF)
endif()
endif()
# ---[ OpenCV
if(USE_OPENCV)
# OpenCV 4
find_package(OpenCV 4 QUIET COMPONENTS core highgui imgproc imgcodecs optflow videoio video)
if(NOT OpenCV_FOUND)
# OpenCV 3
find_package(OpenCV 3 QUIET COMPONENTS core highgui imgproc imgcodecs videoio video)
if(NOT OpenCV_FOUND)
# OpenCV 2
find_package(OpenCV QUIET COMPONENTS core highgui imgproc)
endif()
endif()
if(OpenCV_FOUND)
include_directories(SYSTEM ${OpenCV_INCLUDE_DIRS})
list(APPEND Caffe2_DEPENDENCY_LIBS ${OpenCV_LIBS})
if(MSVC AND USE_CUDA)
list(APPEND Caffe2_CUDA_DEPENDENCY_LIBS ${OpenCV_LIBS})
endif()
message(STATUS "OpenCV found (${OpenCV_CONFIG_PATH})")
else()
message(WARNING "Not compiling with OpenCV. Suppress this warning with -DUSE_OPENCV=OFF")
caffe2_update_option(USE_OPENCV OFF)
endif()
endif()
# ---[ FFMPEG
if(USE_FFMPEG)
find_package(FFmpeg REQUIRED)
if(FFMPEG_FOUND)
message("Found FFMPEG/LibAV libraries")
include_directories(SYSTEM ${FFMPEG_INCLUDE_DIR})
list(APPEND Caffe2_DEPENDENCY_LIBS ${FFMPEG_LIBRARIES})
else()
message("Not compiling with FFmpeg. Suppress this warning with -DUSE_FFMPEG=OFF")
caffe2_update_option(USE_FFMPEG OFF)
endif()
endif()
if(USE_ITT)
find_package(ITT)
if(ITT_FOUND)
include_directories(SYSTEM ${ITT_INCLUDE_DIR})
list(APPEND Caffe2_DEPENDENCY_LIBS ${ITT_LIBRARIES})
list(APPEND TORCH_PYTHON_LINK_LIBRARIES ${ITT_LIBRARIES})
else()
message(WARNING "Not compiling with ITT. Suppress this warning with -DUSE_ITT=OFF")
set(USE_ITT OFF CACHE BOOL "" FORCE)
caffe2_update_option(USE_ITT OFF)
endif()
endif()
# ---[ Caffe2 depends on FP16 library for half-precision conversions
if(NOT TARGET fp16 AND NOT USE_SYSTEM_FP16)
set(CAFFE2_THIRD_PARTY_ROOT "${PROJECT_SOURCE_DIR}/third_party")
# PSIMD is required by FP16
if(NOT DEFINED PSIMD_SOURCE_DIR)
set(PSIMD_SOURCE_DIR "${CAFFE2_THIRD_PARTY_ROOT}/psimd" CACHE STRING "PSimd source directory")
endif()
if(NOT DEFINED FP16_SOURCE_DIR)
set(FP16_SOURCE_DIR "${CAFFE2_THIRD_PARTY_ROOT}/FP16" CACHE STRING "FP16 source directory")
endif()
set(FP16_BUILD_TESTS OFF CACHE BOOL "")
set(FP16_BUILD_BENCHMARKS OFF CACHE BOOL "")
add_subdirectory(
"${FP16_SOURCE_DIR}"
"${CONFU_DEPENDENCIES_BINARY_DIR}/FP16")
elseif(NOT TARGET fp16 AND USE_SYSTEM_FP16)
add_library(fp16 STATIC "/usr/include/fp16.h")
set_target_properties(fp16 PROPERTIES LINKER_LANGUAGE C)
endif()
list(APPEND Caffe2_DEPENDENCY_LIBS fp16)
# ---[ EIGEN