-
Notifications
You must be signed in to change notification settings - Fork 561
/
CMakeLists.txt
1445 lines (1286 loc) · 53 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
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
project(deepdetect)
cmake_minimum_required(VERSION 3.10)
option(RELEASE "release mode" OFF)
option(WARNING "enable warning" ON)
option(USE_CAFFE "build caffe backend" OFF)
option(USE_CAFFE_DEBUG "enable caffe debug" OFF)
option(USE_CAFFE2 "build caffe2 backend" OFF)
option(USE_TF "use TF backend" OFF)
option(USE_NCNN "use NCNN backend" OFF)
option(USE_TORCH "use libtorch backend" ON)
option(USE_HDF5 "use HDF5" ON)
option(USE_TENSORRT "use TensorRT backend" OFF)
option(USE_TENSORRT_OSS "alias of USE_TENSORRT" OFF)
option(USE_XGBOOST "use XGBOOST backend" OFF)
option(USE_DLIB "use Dlib backend" OFF)
option(USE_CUDNN "enable CUDNN" ON)
option(USE_TSNE "enable TSNE" OFF)
option(USE_CUDA_CV "use CUDA with OpenCV (Requires OpenCV build for CUDA)" OFF)
option(USE_SIMSEARCH "build index and search services" OFF)
option(USE_ANNOY "use annoy as indexer" OFF)
option(USE_FAISS "use FAISS as indexer" ON)
option(BUILD_SPDLOG "build SPDLOG instead of using system library" ON)
option(BUILD_PROTOBUF "build PROTOBUF instead of using system library" ON)
option(USE_BOOST_BACKTRACE "use boost backtrace" ON)
option(USE_OPENMP "use OpenMP" ON)
if (USE_CAFFE)
add_definitions(-DUSE_CAFFE)
endif()
if (USE_TENSORRT_OSS)
set(USE_TENSORRT ON)
endif()
if (USE_TF AND USE_CAFFE2)
message(FATAL_ERROR "Building with tensorflow AND caffe2 can't be build together")
endif()
if (USE_TORCH AND USE_CAFFE2)
message(FATAL_ERROR "Building with torch AND caffe2 can't be build together")
endif()
if (USE_TF AND USE_TORCH)
message(FATAL_ERROR "Building with tensorflow AND torch can't be build together")
endif()
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
include(ProcessorCount)
ProcessorCount(N)
include(ExternalProject)
# options
OPTION(BUILD_TESTS "Should the tests be built")
OPTION(BUILD_TOOLS "Should the tools be built")
OPTION(USE_COMMAND_LINE "build command line JSON API" ON)
OPTION(USE_JSON_API "build internal JSON API" ON)
OPTION(USE_HTTP_SERVER "build cppnet-lib version of http JSON API " OFF)
OPTION(USE_HTTP_SERVER_OATPP "build oatpp version of http JSON API" ON)
OPTION(USE_OATPP_SWAGGER "Enable Swagger documentation endpoint" ON)
# user set variables
set(USE_OPENCV_VERSION CACHE STRING "OpenCV Version used by DeepDetect")
# Get the current working branch
execute_process(
COMMAND git rev-parse --abbrev-ref HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_BRANCH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# Get the current version
execute_process(
COMMAND git describe --tags --broken
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# Get the latest abbreviated commit hash of the working branch
execute_process(
COMMAND git log -1 --format=%H
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_COMMIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if (NOT EXISTS ${CMAKE_BINARY_DIR}/src)
execute_process(
COMMAND bash -c "mkdir ${CMAKE_BINARY_DIR}/src")
endif()
if (USE_OPENMP)
if (APPLE)
set(FOPENMP "-Xclang -fopenmp")
find_library(OPENMP_LIBRARIES REQUIRED
NAMES omp libomp
HINTS /opt/homebrew/Cellar/libomp/*/lib/)
message(STATUS "OpenMP location: ${OPENMP_LIBRARIES}")
find_path(OPENMP_INCLUDE_DIRS REQUIRED
NAMES omp.h
HINTS /opt/homebrew/Cellar/libomp/*/include/)
message(STATUS "OpenMP header ${OPENMP_INCLUDE_DIRS}")
include_directories(SYSTEM ${OPENMP_INCLUDE_DIRS})
else()
set(FOPENMP "-fopenmp")
endif()
else()
set(FOPENMP "")
endif()
if (APPLE)
set(CMAKE_CXX_FLAGS "-g -O2 -Wall -Wextra ${FOPENMP} -fPIC -std=c++17")
message(STATUS "Apple build: CUDA is disabled")
set(USE_CUDNN OFF)
set(USE_CUDA_CV OFF)
else()
set(CMAKE_CXX_FLAGS "-g -O2 -Wall -Wextra ${FOPENMP} -fPIC -std=c++17 -Wl,--no-as-needed -ltcmalloc_minimal")
endif()
set(CMAKE_CXX_STANDARD 17)
add_definitions("-DUSE_OPENCV" "-DUSE_LMDB")
if(WARNING)
string(APPEND CMAKE_CXX_FLAGS " -Werror")
endif()
if(RELEASE)
set(BUILD_TYPE release)
else()
set(BUILD_TYPE dev)
endif()
if (USE_COMMAND_LINE)
if (NOT USE_CAFFE)
set(USE_JSON_API ON)
endif()
string(APPEND CMAKE_CXX_FLAGS " -DUSE_COMMAND_LINE")
endif()
if (USE_HTTP_SERVER)
set(USE_JSON_API ON)
string(APPEND CMAKE_CXX_FLAGS " -DUSE_HTTP_SERVER")
endif()
if (USE_HTTP_SERVER_OATPP)
set(USE_JSON_API ON)
string(APPEND CMAKE_CXX_FLAGS " -DUSE_HTTP_SERVER_OATPP")
endif()
if (USE_JSON_API)
string(APPEND CMAKE_CXX_FLAGS " -DUSE_JSON_API")
endif()
# VARIANT
if (APPLE)
# Variant is not on brew
set(VARIANT_VERSION v1.2.0)
message(STATUS "Download Variant library ${VARIANT_VERSION}")
ExternalProject_Add(
variant
PREFIX variant
UPDATE_DISCONNECTED 1
URL https://github.com/mapbox/variant/archive/refs/tags/${VARIANT_VERSION}.tar.gz
URL_HASH SHA256=7059f4420d504c4bc96f8a462a0f6d029c5be914ba55cc030a0a773366dd7bc8
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
)
set(VARIANT_INCLUDE_DIRS "${CMAKE_BINARY_DIR}/variant/src/variant/include/")
endif()
# PROTOBUF
# use protobuf same version as pytorch one
if (BUILD_PROTOBUF)
set(PROTOBUF_VERSION 3.11.4)
ExternalProject_Add(
protobuf
PREFIX protobuf
UPDATE_DISCONNECTED 1
URL https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOBUF_VERSION}/protobuf-cpp-${PROTOBUF_VERSION}.tar.gz
URL_HASH SHA256=ba4bbc3e6b58d2ccfe406e616576ef48710a2aae205f463618025fc691549cfe
SOURCE_SUBDIR cmake
CMAKE_ARGS
-DCMAKE_BUILD_TYPE=$CMAKE_BUILD_TYPE
-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=ON
-DBUILD_SHARED_LIBS:BOOL=ON
-Dprotobuf_BUILD_TESTS:BOOL=OFF
-Dprotobuf_BUILD_EXAMPLES:BOOL=OFF
INSTALL_COMMAND ""
)
set(PROTOBUF_INCLUDE_DIR ${CMAKE_BINARY_DIR}/protobuf/src/protobuf/src)
set(PROTOBUF_LIB_DIR ${CMAKE_BINARY_DIR}/protobuf/src/protobuf-build/)
set(PROTOBUF_PROTOC ${PROTOBUF_LIB_DIR}/protoc)
if (APPLE)
set(PROTOBUF_LIB_DEPS ${PROTOBUF_LIB_DIR}/libprotobuf.dylib ${PROTOBUF_LIB_DIR}/libprotoc.dylib ${PROTOBUF_LIB_DIR}/libprotobuf-lite.dylib)
else()
set(PROTOBUF_LIB_DEPS ${PROTOBUF_LIB_DIR}/libprotobuf.so ${PROTOBUF_LIB_DIR}/libprotoc.so ${PROTOBUF_LIB_DIR}/libprotobuf-lite.so)
endif()
link_directories(${PROTOBUF_LIB_DIR})
include_directories(SYSTEM ${PROTOBUF_INCLUDE_DIR})
else()
if (USE_CAFFE OR USE_TORCH)
find_package(Protobuf REQUIRED 3.11.4)
else()
find_package(Protobuf REQUIRED)
endif()
set(PROTOBUF_PROTOC ${Protobuf_PROTOC_EXECUTABLE})
set(PROTOBUF_INCLUDE_DIR ${Protobuf_INCLUDE_DIRS})
set(PROTOBUF_LIB_DEPS protobuf::libprotobuf)
add_custom_target(protobuf)
# absl for protobuf 22+
if (${Protobuf_VERSION} VERSION_GREATER_EQUAL 4.22.0)
message(STATUS "Add Abseil dependency required by Protobuf V${Protobuf_VERSION}")
if(NOT TARGET absl::strings)
find_package(absl CONFIG)
endif()
set_target_properties(protobuf::libprotobuf PROPERTIES
INTERFACE_LINK_LIBRARIES "absl::absl_check;absl::absl_log;absl::algorithm;absl::base;absl::bind_front;absl::bits;absl::btree;absl::cleanup;absl::cord;absl::core_headers;absl::debugging;absl::die_if_null;absl::dynamic_annotations;absl::flags;absl::flat_hash_map;absl::flat_hash_set;absl::function_ref;absl::hash;absl::layout;absl::log_initialize;absl::log_severity;absl::memory;absl::node_hash_map;absl::node_hash_set;absl::optional;absl::span;absl::status;absl::statusor;absl::strings;absl::synchronization;absl::time;absl::type_traits;absl::utility;absl::variant"
)
endif()
endif()
file(
DOWNLOAD https://raw.githubusercontent.com/jolibrain/caffe/master/src/caffe/proto/caffe.proto ${CMAKE_BINARY_DIR}/caffe.proto
EXPECTED_HASH SHA256=e82a1d51635be93e964c6debcb4cd76514fada46348fa7b30355c14850767360
)
add_custom_command(
OUTPUT ${CMAKE_BINARY_DIR}/src/caffe.pb.h ${CMAKE_BINARY_DIR}/src/caffe.pb.cc
COMMAND LD_LIBRARY_PATH=${PROTOBUF_LIB_DIR} ${PROTOBUF_PROTOC} --proto_path=${CMAKE_BINARY_DIR} --cpp_out=${CMAKE_BINARY_DIR}/src ${CMAKE_BINARY_DIR}/caffe.proto
MAIN_DEPENDENCY ${CMAKE_BINARY_DIR}/caffe.proto
COMMENT Generating caffe.pb.h and caffe.pb.cc
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
DEPENDS protobuf
)
add_custom_target(
caffe_pb_h
DEPENDS ${CMAKE_BINARY_DIR}/src/caffe.pb.h ${CMAKE_BINARY_DIR}/src/caffe.pb.cc
)
# read documentation
file(
READ "${CMAKE_SOURCE_DIR}/docs/api_swagger.md"
API_DOC
)
# dependency on Eigen for confusion matrix fast computation
if (USE_TF)
set(TENSORFLOW_CC_DIR ${CMAKE_BINARY_DIR}/tensorflow_cc/src/tensorflow_cc-build/)
set(EIGEN3_INCLUDE_DIR ${TENSORFLOW_CC_DIR}/tensorflow/tensorflow/contrib/makefile/downloads/eigen/)
elseif (USE_CAFFE2)
set(PYTORCH_PATH ${CMAKE_BINARY_DIR}/pytorch/src/pytorch)
set(DETECTRON_PATH ${CMAKE_BINARY_DIR}/detectron/src/detectron)
set(EIGEN3_INCLUDE_DIR ${PYTORCH_PATH}/third_party/eigen)
else()
find_package(PkgConfig)
pkg_search_module(Eigen3 REQUIRED eigen3)
set(EIGEN3_INCLUDE_DIR "/usr/include/eigen3")
endif()
set(eigen_archive_hash "50812b426b7c")
include_directories("${EIGEN3_INCLUDE_DIR}")
# spdlog, usefull for ubuntu20.04/rhel/centos that ship a bugged version (missing header, don't compile with nvcc, ...)
if (BUILD_SPDLOG)
ExternalProject_Add(
spdlog
UPDATE_DISCONNECTED 1
PREFIX spdlog
URL https://github.com/gabime/spdlog/archive/v1.8.2.tar.gz
URL_HASH SHA256=e20e6bd8f57e866eaf25a5417f0a38a116e537f1a77ac7b5409ca2b180cec0d5
BUILD_IN_SOURCE true
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/spdlog/build -DCMAKE_POSITION_INDEPENDENT_CODE=ON
)
set(SPDLOG_LIB_DEPS ${CMAKE_BINARY_DIR}/spdlog/build/lib/libspdlog.a)
set(SPDLOG_LIB_DIR ${CMAKE_BINARY_DIR}/spdlog/build/lib)
set(SPDLOG_CAFFE_LIB_DEPS :libspdlog.a)
set(SPDLOG_INCLUDE_DIR ${CMAKE_BINARY_DIR}/spdlog/build/include)
include_directories(SYSTEM ${SPDLOG_INCLUDE_DIR})
else()
find_package(spdlog 1.8.2 CONFIG REQUIRED)
set(SPDLOG_LIB_DEPS spdlog::spdlog)
endif()
# hdf5
if (USE_HDF5)
if (RPI3)
set(HDF5_LIB /usr/lib/arm-linux-gnueabihf/hdf5/serial)
else()
set(HDF5_LIB /usr/lib/x86_64-linux-gnu/hdf5/serial)
endif()
set (HDF5_INCLUDE /usr/include/hdf5/serial)
include_directories(${HDF5_INCLUDE})
endif()
# dependency on Boost
if (USE_BOOST_BACKTRACE)
add_definitions(-DUSE_BOOST_BACKTRACE)
find_package(Boost 1.54 REQUIRED COMPONENTS filesystem thread system iostreams stacktrace_backtrace)
string(APPEND CMAKE_CXX_FLAGS " -DBOOST_STACKTRACE_USE_BACKTRACE -DBOOST_STACKTRACE_LINK")
else()
find_package(Boost 1.54 REQUIRED COMPONENTS filesystem thread system iostreams)
endif()
# CUDA OR CPU options
option(USE_XGBOOST_CPU_ONLY "use XGBOOST without CUDA" ON)
option(USE_TF_CPU_ONLY "use TF without CUDA" OFF)
option(USE_TORCH_CPU_ONLY "use TORCH without CUDA" OFF)
option(USE_CAFFE_CPU_ONLY "use CAFFE without CUDA" OFF)
option(USE_DLIB_CPU_ONLY "use DLIB without CUDA" OFF)
option(USE_CAFFE2_CPU_ONLY "use CAFFE2 without CUDA" OFF)
option(USE_FAISS_CPU_ONLY "use FAISS without CUDA" OFF)
# Dlib AVX option
option(USE_DLIB_AVX "build dlib with AVX enabled" OFF)
# Deprecated flag
if (USE_XGBOOST_GPU)
set(USE_XGBOOST_CPU_ONLY OFF)
endif()
if (USE_CPU_ONLY)
set(USE_XGBOOST_CPU_ONLY ON)
set(USE_CAFFE_CPU_ONLY ON)
set(USE_DLIB_CPU_ONLY ON)
set(USE_TF_CPU_ONLY ON)
set(USE_CAFFE2_CPU_ONLY ON)
set(USE_TORCH_CPU_ONLY ON)
set(USE_FAISS_CPU_ONLY ON)
set(USE_CUDNN OFF)
else()
cmake_minimum_required(VERSION 3.14)
include(cmake/Cuda.cmake) # cuda + cudnn
endif()
# CUDA validation
if (NOT APPLE AND NOT CUDA_FOUND)
if (USE_TENSORRT)
message(FATAL, "USE_TENSORRT=ON needs CUDA installed")
endif()
if (USE_TF AND NOT USE_TF_CPU_ONLY)
message(FATAL, "USE_TF=ON needs CUDA installed")
endif()
if (USE_CAFFE AND NOT USE_CAFFE_CPU_ONLY)
message(FATAL, "USE_CAFFE=ON needs CUDA installed")
endif()
if (USE_DLIB AND NOT USE_DLIB_CPU_ONLY)
message(FATAL, "USE_DLIB=ON needs CUDA installed")
if (USE_CUDNN)
message(FATAL "Dlib GPU enabled without cuDNN, please set -DUSE_CUDNN=ON")
endif()
endif()
if (USE_TORCH AND NOT USE_TORCH_CPU_ONLY)
message(FATAL, "USE_TORCH=ON needs CUDA installed")
endif()
if (USE_CAFFE2 AND NOT USE_CAFFE2_CPU_ONLY)
message(FATAL, "USE_CAFFE2=ON needs CUDA installed")
endif()
if (USE_FAISS AND NOT USE_FAISS_CPU_ONLY)
message(FATAL, "USE_FAISS=ON needs CUDA installed")
endif()
endif()
# annoy
if (USE_CAFFE OR USE_TORCH)
if (USE_SIMSEARCH)
if (USE_FAISS AND USE_ANNOY)
message (STATUS "ANNOY selected, using ANNOY as simsearch backend")
set(USE_FAISS OFF)
endif()
if (NOT USE_FAISS AND NOT USE_ANNOY)
message (STATUS "FAISS deselected , using ANNOY as simssearch backend")
set(USE_ANNOY ON)
endif()
IF (USE_ANNOY)
message(STATUS "Fetching Annoy")
add_definitions(-DUSE_SIMSEARCH)
add_definitions(-DUSE_ANNOY)
ExternalProject_Add(
annoy
PREFIX annoy
GIT_REPOSITORY https://github.com/spotify/annoy.git
CONFIGURE_COMMAND python setup.py build
BUILD_COMMAND ""
INSTALL_COMMAND ""
BUILD_IN_SOURCE 1
)
set(ANNOY_INCLUDE_DIR ${CMAKE_BINARY_DIR}/annoy/src/annoy/src/)
include_directories(SYSTEM "${ANNOY_INCLUDE_DIR}")
endif()
if(USE_FAISS)
if (USE_FAISS_CPU_ONLY)
set(CONFIGURE_OPTS "-DFAISS_ENABLE_GPU=OFF" "-DBUILD_TESTING=OFF" "-DFAISS_ENABLE_PYTHON=OFF")
else()
set(CONFIGURE_OPTS "-DCMAKE_CUDA_COMPILER=/usr/local/cuda/bin/nvcc" "-DBUILD_TESTING=OFF" "-DFAISS_ENABLE_PYTHON=OFF")
endif()
message(STATUS "Fetching FAISS")
add_definitions(-DUSE_FAISS)
add_definitions(-DUSE_SIMSEARCH)
ExternalProject_Add(
faisslib
PREFIX faiss
SOURCE_DIR ${CMAKE_BINARY_DIR}/faiss/src/faiss
GIT_REPOSITORY https://github.com/facebookresearch/faiss
GIT_TAG main
UPDATE_DISCONNECTED 1
CONFIGURE_COMMAND cmake ${CONFIGURE_OPTS} -B build .
BUILD_COMMAND make -C build -j${N}
INSTALL_COMMAND ""
BUILD_IN_SOURCE 1
)
set(FAISS_INCLUDE_DIR ${CMAKE_BINARY_DIR}/faiss/src/faiss)
include_directories("${FAISS_INCLUDE_DIR}")
set(FAISS_LIB_DIR ${CMAKE_BINARY_DIR}/faiss/src/faiss/build/faiss)
set(FAISS_LIB_DEPS openblas faiss)
endif()
endif()
else()
set(USE_SIMSEARCH OFF)
endif()
if (USE_CUDNN)
find_package(CUDNN REQUIRED)
endif()
# CUDA dependencies
if (CUDA_FOUND)
set(CUDA_LIB_DEPS ${CUDA_LIBRARIES} ${CUDA_CUBLAS_LIBRARIES} ${CUDA_curand_LIBRARY} ${CUDA_CUDART_LIBRARY} ${CUDA_cusolver_LIBRARY})
if (USE_CUDNN)
set(CUDA_LIB_DEPS ${CUDA_LIB_DEPS} ${CUDNN_LIBRARY})
endif()
if ("${CUDA_ARCH}" STREQUAL "")
message(STATUS "CUDA_ARCH not set, using detected set ${NVCC_ARCH_EXTRA}")
# Convert arch to correct format
foreach(arch ${NVCC_ARCH_EXTRA})
string(REGEX REPLACE "(.*)(.)" "\\1.\\2" arch_with_dots "${arch}")
string(APPEND CUDA_ARCH "${arch_with_dots};")
endforeach()
# remove last semi-colon if any
string(REGEX REPLACE ".$" "" CUDA_ARCH "${CUDA_ARCH}")
endif()
message(STATUS "CUDA_ARCH=${CUDA_ARCH}")
else()
set(CUDA_LIB_DEPS "")
if (NOT APPLE)
# XXX: On Apple platforms MPS can be used, so we'd need a different condition
add_definitions(-DCPU_ONLY)
endif()
endif()
if (USE_DLIB)
# Dlib
# Currently supported release version of dlib
set(DLIB_RELEASE_VERSION v19.24)
message(STATUS "Using Dlib version ${DLIB_RELEASE_VERSION}")
add_definitions(-DUSE_DLIB)
set(DLIB_LIB_DEPS -ldlib -lopenblas)
if (USE_DLIB_CPU_ONLY)
ExternalProject_Add(
dlib
PREFIX dlib
URL https://github.com/davisking/dlib/archive/${DLIB_RELEASE_VERSION}.tar.gz
CONFIGURE_COMMAND cd dlib && mkdir -p build && cd build && cmake .. -DUSE_AVX_INSTRUCTIONS=${USE_DLIB_AVX} -DDLIB_NO_GUI_SUPPORT=ON -DDLIB_USE_CUDA=OFF -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/dlib/build && cmake --build . --config Release --target install
BUILD_COMMAND ""
INSTALL_COMMAND ""
BUILD_IN_SOURCE 1
)
else()
if (NOT USE_CUDNN)
message(FATAL_ERROR "Dlib with CUDA must also enable cuDNN. Use -DUSE_CUDNN=ON")
endif()
ExternalProject_Add(
dlib
PREFIX dlib
URL https://github.com/davisking/dlib/archive/${DLIB_RELEASE_VERSION}.tar.gz
CONFIGURE_COMMAND cd dlib && mkdir -p build && cd build && cmake .. -DUSE_AVX_INSTRUCTIONS=${USE_DLIB_AVX} -DDLIB_NO_GUI_SUPPORT=ON -DDLIB_USE_CUDA=ON -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/dlib/build && cmake --build . --config Release --target install
BUILD_COMMAND ""
INSTALL_COMMAND ""
BUILD_IN_SOURCE 1
)
endif()
set(DLIB_INC_DIR ${CMAKE_BINARY_DIR}/dlib/build/include)
set(DLIB_LIB_DIR ${CMAKE_BINARY_DIR}/dlib/build/lib)
include_directories("${DLIB_INC_DIR}")
message(STATUS "Dlib will be built")
endif()
set(CAFFE_DD_USER jolibrain)
set(CAFFE_DD_BRANCH master)
if (USE_CAFFE2)
message(DEPRECATION "CAFFE2 backend is deprecated and will be removed in the future")
add_definitions(-DUSE_CAFFE2)
list(APPEND CAFFE2_LIB_DEPS -lcaffe2)
if (NOT USE_CAFFE2_CPU_ONLY)
list(APPEND CAFFE2_LIB_DEPS -lcaffe2_gpu)
endif()
include_directories(
${PYTORCH_PATH}
${PYTORCH_PATH}-build
${PYTORCH_PATH}/aten/src
)
set(CAFFE2_PATCHES ${CMAKE_BINARY_DIR}/patches/caffe2)
set(PYTORCH_SUPPORTED_COMMIT ff608a9) # Pre-release v1.0rc1
set(PYTORCH_PATCHES
${CAFFE2_PATCHES}/pytorch/0001-eigen.patch
${CAFFE2_PATCHES}/pytorch/0002-logging.patch
${CAFFE2_PATCHES}/pytorch/0003-collect_proposals.patch
)
set(DETECTRON_SUPPORTED_COMMIT 8181a32) # Nov 7, 2018
set(DETECTRON_PATCHES
${CAFFE2_PATCHES}/detectron/0001-dependencies.patch
${CAFFE2_PATCHES}/detectron/0002-compiled.patch
${CAFFE2_PATCHES}/detectron/0003-ops.patch
${CAFFE2_PATCHES}/detectron/0004-import.patch
${CAFFE2_PATCHES}/detectron/0005-visual_genome.patch
${CAFFE2_PATCHES}/detectron/0006-pkl_cache.patch
${CAFFE2_PATCHES}/detectron/0007-weight_transfer.patch
)
list(APPEND CAFFE2_OPS
${CAFFE2_PATCHES}/custom_ops/bbox_to_roi_op.h
${CAFFE2_PATCHES}/custom_ops/bbox_to_roi_op.cc
${CAFFE2_PATCHES}/custom_ops/segment_mask_op.h
${CAFFE2_PATCHES}/custom_ops/segment_mask_op.cc
${CAFFE2_PATCHES}/custom_ops/multi_level_roi_op.h
${CAFFE2_PATCHES}/custom_ops/multi_level_roi_op.cc
)
list(APPEND PYTORCH_FLAGS
-DBUILD_CUSTOM_PROTOBUF=OFF
-DCAFFE2_LINK_LOCAL_PROTOBUF=0
-DUSE_OPENMP=ON
-DUSE_MPI=OFF
-DUSE_GFLAGS=OFF
-DUSE_GLOG=OFF
-DBUILD_TEST=OFF
-DBUILD_BINARY=OFF
-DBUILD_DOCS=OFF
)
# Only a few submodules are currently used by caffe2
# (No need to log, benchmark, compile for IOS, make python libraries, ...)
list(APPEND PYTORCH_SUBMODULES
third_party/cpuinfo
third_party/cub
third_party/eigen
third_party/FP16
third_party/FXdiv
third_party/gloo
third_party/NNPACK
third_party/onnx
third_party/psimd
third_party/pthreadpool
third_party/pybind11
third_party/python-peachpy
third_party/sleef
)
# Pytorch
set(PYTORCH_COMPLETE ${CMAKE_BINARY_DIR}/CMakeFiles/pytorch-complete)
ExternalProject_Add(
pytorch
PREFIX pytorch
GIT_REPOSITORY https://github.com/pytorch/pytorch.git
GIT_SUBMODULES ${PYTORCH_SUBMODULES}
UPDATE_DISCONNECTED 1
GIT_TAG ${PYTORCH_SUPPORTED_COMMIT}
PATCH_COMMAND test -f ${PYTORCH_COMPLETE} && echo Skipping || echo cp modules/detectron/*_op.* caffe2/operators | bash && cp ${CAFFE2_OPS} caffe2/operators && git am ${PYTORCH_PATCHES}
CONFIGURE_COMMAND test -f ${PYTORCH_COMPLETE} && echo Skipping || PATH=${PROTOBUF_LIB_DIR}:$ENV{PATH} cmake ../pytorch ${PYTORCH_FLAGS}
BUILD_COMMAND test -f ${PYTORCH_COMPLETE} && echo Skipping || make -j${N}
INSTALL_COMMAND ""
DEPENDS protobuf
)
# Detectron
set(DETECTRON_COMPLETE ${CMAKE_BINARY_DIR}/CMakeFiles/detectron-complete)
ExternalProject_Add(
detectron
PREFIX detectron
GIT_REPOSITORY https://github.com/facebookresearch/Detectron
UPDATE_DISCONNECTED 1
GIT_TAG ${DETECTRON_SUPPORTED_COMMIT}
PATCH_COMMAND test -f ${DETECTRON_COMPLETE} && echo Skipping || git am ${DETECTRON_PATCHES}
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
DEPENDS protobuf
)
# Python path
if (NOT EXISTS ${CMAKE_BINARY_DIR}/python_path)
execute_process(COMMAND mkdir -p ${CMAKE_BINARY_DIR}/python_path)
execute_process(COMMAND ln -s ${PYTORCH_PATH}-build
${CMAKE_BINARY_DIR}/python_path/pytorch)
execute_process(COMMAND ln -s ${DETECTRON_PATH}
${CMAKE_BINARY_DIR}/python_path/detectron)
endif()
endif()
if (USE_TF)
# Tensorflow
message(STATUS "Fetching Tensorflow")
add_definitions(-DUSE_TF)
set(TF_LIB_DEPS -ltensorflow_cc)
if (USE_TF_CPU_ONLY)
add_definitions(-DUSE_TF_CPU_ONLY)
ExternalProject_Add(
tensorflow_cc
PREFIX tensorflow_cc
GIT_REPOSITORY https://github.com/FloopCZ/tensorflow_cc.git
GIT_TAG v1.15.0
SOURCE_SUBDIR tensorflow_cc
CMAKE_ARGS -DTENSORFLOW_STATIC=OFF -DTENSORFLOW_SHARED=ON -DALLOW_CUDA=OFF
INSTALL_COMMAND ""
BUILD_IN_SOURCE 1
)
else()
ExternalProject_Add(
tensorflow_cc
PREFIX tensorflow_cc
GIT_REPOSITORY https://github.com/FloopCZ/tensorflow_cc.git
GIT_TAG v1.15.0
SOURCE_SUBDIR tensorflow_cc
CMAKE_ARGS -DTENSORFLOW_STATIC=OFF -DTENSORFLOW_SHARED=ON
INSTALL_COMMAND ""
BUILD_IN_SOURCE 1
)
endif()
set(TF_INC_DIR ${TENSORFLOW_CC_DIR}/tensorflow/ ${TENSORFLOW_CC_DIR}/tensorflow/bazel-genfiles/ ${TENSORFLOW_CC_DIR}/tensorflow/tensorflow/contrib/makefile/downloads/nsync/public/ ${TENSORFLOW_CC_DIR}/tensorflow/tensorflow/contrib/makefile/downloads/absl/)
set(TF_LIB_DIR ${TENSORFLOW_CC_DIR}/tensorflow/bazel-bin/tensorflow/)
include_directories("${TF_INC_DIR}")
endif() # USE_TF
# OpenCV
set(OPENCV_MODULES core imgproc highgui imgcodecs videoio)
if (USE_CUDA_CV)
list(APPEND OPENCV_MODULES cudaimgproc cudaarithm cudawarping cudacodec)
endif()
if (USE_OPENCV_VERSION STREQUAL "")
find_package(OpenCV 3 QUIET COMPONENTS ${OPENCV_MODULES})
if (NOT OpenCV_FOUND)
find_package(OpenCV 4 QUIET COMPONENTS ${OPENCV_MODULES})
endif()
if (NOT OpenCV_FOUND)
find_package(OpenCV 2 REQUIRED COMPONENTS ${OPENCV_MODULES})
endif()
else()
find_package(OpenCV ${USE_OPENCV_VERSION} REQUIRED COMPONENTS ${OPENCV_MODULES})
endif()
set(OPENCV_VERSION ${OpenCV_VERSION_MAJOR})
include_directories(${OpenCV_INCLUDE_DIRS})
message(STATUS "OpenCV ${OPENCV_VERSION} (${OpenCV_VERSION}) found (${OpenCV_CONFIG_PATH})")
if (USE_CUDA_CV)
message(STATUS "Using CUDA OpenCV")
add_definitions(-DUSE_CUDA_CV)
endif()
# customized Caffe as external project
if (CAFFE_INC_DIR AND CAFFE_LIB_DIR)
# do nothing
elseif(USE_CAFFE)
message(STATUS "Configuring customized caffe")
if (USE_DD_SYSLOG)
set(USE_SYSLOG 1)
else()
set(USE_SYSLOG 0)
endif()
# Set config file
if (USE_CAFFE_CPU_ONLY)
add_definitions(-DUSE_CAFFE_CPU_ONLY)
set(CAFFE_DD_CONFIG_FILE Makefile.config.cpu)
else()
if (HAVE_CUDNN AND USE_CUDNN)
if(JETSON)
set(CAFFE_DD_CONFIG_FILE Makefile.config.gpu.cudnn.jetson)
else()
set(CAFFE_DD_CONFIG_FILE Makefile.config.gpu.cudnn)
endif()
else() # HAVE_CUDNN
set(CAFFE_DD_CONFIG_FILE Makefile.config.gpu)
endif() # HAVE_CUDNN
endif()
if (RPI3)
set(CAFFE_DD_CONFIG_FILE Makefile.config.pi3)
endif()
# Set caffe DEBUG mode
if (USE_CAFFE_DEBUG)
set(CAFFE_DEBUG 1)
else()
set(CAFFE_DEBUG 0)
endif()
message(STATUS "include_dirs : ${INCLUDE_DIRS}")
set(CAFFE_DD_TARBALL_HASH "6d340fff2213c37886e058d188c9b54458a0747422d54bc294db4e5029a68aa0")
ExternalProject_Add(
caffe_dd
PREFIX caffe_dd
URL https://github.com/${CAFFE_DD_USER}/caffe/archive/${CAFFE_DD_BRANCH}.tar.gz
URL_HASH SHA256=${CAFFE_DD_TARBALL_HASH}
CONFIGURE_COMMAND
sh -c "\
diff ${CMAKE_BINARY_DIR}/caffe_dd/src/caffe_dd/.build_release/src/caffe/proto/caffe.pb.cc ${CMAKE_CURRENT_BINARY_DIR}/src/caffe.pb.cc > /dev/null 2>&1 \
&& ( echo 'caffe version of caffe.pb.h/caffe.pb.cc is already up to date') \
|| ( echo 'caffe.pb.h/caffe.pb.cc have change rebuilding caffe' && rm -rf ${CMAKE_BINARY_DIR}/caffe_dd/src/caffe_dd/.build_release ) \
" &&
ln -sf ${CAFFE_DD_CONFIG_FILE} Makefile.config &&
echo "OPENCV_VERSION:=${OPENCV_VERSION}" >> Makefile.config &&
echo "USE_SYSLOG:=${USE_SYSLOG}" >> Makefile.config &&
echo "DEBUG:=${CAFFE_DEBUG}" >> Makefile.config &&
echo "INCLUDE_DIRS+=${SPDLOG_INCLUDE_DIR}" >> Makefile.config &&
echo "INCLUDE_DIRS+=${PROTOBUF_INCLUDE_DIR}" >> Makefile.config &&
echo "INCLUDE_DIRS+=${OpenCV_INCLUDE_DIRS}" >> Makefile.config &&
echo "CUDA_ARCH:=${CUDA_ARCH_FLAGS}" >> Makefile.config &&
echo "LIBRARIES+=${SPDLOG_CAFFE_LIB_DEPS}" >> Makefile.config &&
echo "LIBRARIES+=${OpenCV_LIBS}" >> Makefile.config &&
echo "LIBRARY_DIRS+=${SPDLOG_LIB_DIR}" >> Makefile.config &&
echo "LIBRARY_DIRS+=${PROTOBUF_LIB_DIR}" >> Makefile.config &&
echo "LIBRARY_DIRS+=${OpenCV_CONFIG_PATH}/lib" >> Makefile.config
BUILD_COMMAND
${CMAKE_COMMAND} -E env LD_LIBRARY_PATH=${PROTOBUF_LIB_DIR}:$ENV{LD_LIBRARY_PATH} PATH=${PROTOBUF_LIB_DIR}:$ENV{PATH} make -j${N} proto &&
${CMAKE_COMMAND} -E env LD_LIBRARY_PATH=${PROTOBUF_LIB_DIR}:$ENV{LD_LIBRARY_PATH} PATH=${PROTOBUF_LIB_DIR}:$ENV{PATH} make -j${N} all
INSTALL_COMMAND ""
BUILD_IN_SOURCE 1
DEPENDS caffe_pb_h protobuf spdlog
)
if (USE_HDF5)
if (JETSON)
set(HDF5_LIB /usr/lib/aarch64-linux-gnu/hdf5/serial)
elseif (RPI3)
set(HDF5_LIB /usr/lib/arm-linux-gnueabihf/hdf5/serial)
else()
set(HDF5_LIB /usr/lib/x86_64-linux-gnu/hdf5/serial)
endif()
endif()
if (USE_HDF5)
if (USE_CAFFE_CPU_ONLY)
set(CAFFE_INC_DIR ${CMAKE_BINARY_DIR}/caffe_dd/src/caffe_dd/include ${CMAKE_BINARY_DIR}/caffe_dd/src/caffe_dd/build/src /usr/include/hdf5/serial)
set(CAFFE_LIB_DIR $ENV{HOME}/lib ${CMAKE_BINARY_DIR}/caffe_dd/src/caffe_dd/build/lib ${CMAKE_BINARY_DIR}/caffe_dd/src/caffe_dd/build/src ${HDF5_LIB})
else()
set(CAFFE_INC_DIR ${CMAKE_BINARY_DIR}/caffe_dd/src/caffe_dd/include ${CMAKE_BINARY_DIR}/caffe_dd/src/caffe_dd/build/src ${CUDA_INCLUDE_DIRS})
set(CAFFE_LIB_DIR ${CMAKE_BINARY_DIR}/caffe_dd/src/caffe_dd/build/lib ${CMAKE_BINARY_DIR}/caffe_dd/src/caffe_dd/build/src ${HDF5_LIB})
endif()
else()
if (USE_CAFFE_CPU_ONLY)
set(CAFFE_INC_DIR ${CMAKE_BINARY_DIR}/caffe_dd/src/caffe_dd/include ${CMAKE_BINARY_DIR}/caffe_dd/src/caffe_dd/build/src)
set(CAFFE_LIB_DIR $ENV{HOME}/lib ${CMAKE_BINARY_DIR}/caffe_dd/src/caffe_dd/build/lib ${CMAKE_BINARY_DIR}/caffe_dd/src/caffe_dd/build/src)
else()
set(CAFFE_INC_DIR ${CMAKE_BINARY_DIR}/caffe_dd/src/caffe_dd/include ${CMAKE_BINARY_DIR}/caffe_dd/src/caffe_dd/build/src ${CUDA_INCLUDE_DIRS})
set(CAFFE_LIB_DIR ${CMAKE_BINARY_DIR}/caffe_dd/src/caffe_dd/build/lib ${CMAKE_BINARY_DIR}/caffe_dd/src/caffe_dd/build/src)
endif()
endif()
endif()
# Caffe dependencies
if (USE_CAFFE)
set(CAFFE_LIB_DEPS -lleveldb -lsnappy -llmdb -lopenblas -lcaffe)
if (USE_HDF5)
string(APPEND CAFFE_LIB_DEPS " -lhdf5_hl -lhdf5")
endif()
endif()
# NCNN
if (USE_NCNN)
message(STATUS "Configuring NCNN")
add_definitions(-DUSE_NCNN)
set(NCNN_PATCHES_PATH ${CMAKE_BINARY_DIR}/patches/ncnn)
set(NCNN_PATCHES
${NCNN_PATCHES_PATH}/ncnn_inner_keep_h.patch
${NCNN_PATCHES_PATH}/ncnn_lstm_cont.patch
${NCNN_PATCHES_PATH}/ncnn_variable_h.patch
${NCNN_PATCHES_PATH}/ncnn_flatten_axis.patch
${NCNN_PATCHES_PATH}/ncnn_cont_indic.patch
)
set(NCNN_VERSION "20201218")
set(NCNN_TARBALL_HASH "1dac4571168b83ee99efaba969c01e8054cd8e3d9b67ca4893f32b767ab4ec48")
set(NCNN_BUILD_FLAGS -DCMAKE_BUILD_TYPE=Release -DNCNN_BUILD_EXAMPLES=OFF -DNCNN_BUILD_BENCHMARK=OFF -DNCNN_BUILD_TOOLS=OFF -DNCNN_BUILD_TESTS=OFF)
if (RPI3)
ExternalProject_Add(
ncnn
PREFIX ncnn
URL https://github.com/Tencent/ncnn/releases/download/${NCNN_VERSION}/ncnn-${NCNN_VERSION}-full-source.zip
URL_HASH SHA256=${NCNN_TARBALL_HASH}
PATCH_COMMAND ${CMAKE_SOURCE_DIR}/cmake/patches-apply.sh ${NCNN_PATCHES}
CMAKE_ARGS -DPI3=ON -DCMAKE_TOOLCHAIN_FILE=../toolchains/pi3.toolchain.cmake ${NCNN_BUILD_FLAGS}
INSTALL_COMMAND ""
)
else ()
ExternalProject_Add(
ncnn
PREFIX ncnn
URL https://github.com/Tencent/ncnn/releases/download/${NCNN_VERSION}/ncnn-${NCNN_VERSION}-full-source.zip
URL_HASH SHA256=${NCNN_TARBALL_HASH}
PATCH_COMMAND ${CMAKE_SOURCE_DIR}/cmake/patches-apply.sh ${NCNN_PATCHES}
CMAKE_ARGS ${NCNN_BUILD_FLAGS}
INSTALL_COMMAND ""
)
endif()
set(NCNN_LIB_DEPS ${CMAKE_BINARY_DIR}/ncnn/src/ncnn-build/src/libncnn.a)
set(NCNN_INC_DIR ${CMAKE_BINARY_DIR}/ncnn/src/ncnn/src ${CMAKE_BINARY_DIR}/ncnn/src/ncnn-build/src)
set(NCNN_LIB_DIR ${CMAKE_BINARY_DIR}/ncnn/src/ncnn-build/src)
endif()
# Torch
if (USE_TORCH)
if (!APPLE)
set(CMAKE_EXE_LINKER_FLAGS "-Wl,--no-as-needed")
endif()
set(PYTORCH_PATCHES_PATH ${CMAKE_BINARY_DIR}/patches/pytorch)
set(PYTORCH_PATCHES
${PYTORCH_PATCHES_PATH}/pytorch_15_compile.patch
${PYTORCH_PATCHES_PATH}/pytorch_113_new_logger.patch
${PYTORCH_PATCHES_PATH}/pytorch_241_use_new_logger.patch
${PYTORCH_PATCHES_PATH}/pytorch_23_cloneable.patch
)
if (APPLE)
list(APPEND PYTORCH_PATCHES ${PYTORCH_PATCHES_PATH}/pytorch_113_apple_includes.patch)
endif()
message(STATUS "Configuring libtorch")
add_definitions(-DUSE_TORCH)
if (NOT TORCH_LOCATION)
set(PYTORCH_COMMIT v2.4.1)
set(PYTORCH_COMPLETE ${CMAKE_BINARY_DIR}/CMakeFiles/pytorch-complete)
if (APPLE)
if(USE_TORCH_CPU_ONLY)
set(PYTORCH_USE_MPS 0)
else()
set(PYTORCH_USE_MPS 1)
add_definitions("-DUSE_MPS")
endif()
message(STATUS "PROTOBUF_PROTOC_EXECUTABLE=${PROTOBUF_PROTOC} PROTOBUF_INCLUDE_DIRS=${PROTOBUF_INCLUDE_DIR} PROTOBUF_LIBRARIES=${PROTOBUF_LIB_DEPS}")
ExternalProject_Add(
pytorch
PREFIX pytorch
GIT_REPOSITORY https://github.com/pytorch/pytorch.git
GIT_TAG ${PYTORCH_COMMIT}
GIT_CONFIG advice.detachedHead=false
UPDATE_DISCONNECTED 1
PATCH_COMMAND "" test -f ${PYTORCH_COMPLETE} && echo Skipping || git apply ${PYTORCH_PATCHES} && echo Applying ${PYTORCH_PATCHES}
CONFIGURE_COMMAND "" cd ${CMAKE_BINARY_DIR}/pytorch/src/pytorch/third_party/fmt/ && git checkout 7.1.0
BUILD_COMMAND ""
COMMAND test -f ${PYTORCH_COMPLETE} && echo Skipping || ${CMAKE_COMMAND} -E env PATH=${PROTOBUF_LIB_DIR}:${PROTOBUF_INCLUDE_DIR}:$ENV{PATH} BUILD_CUSTOM_PROTOBUF=0 BUILD_TEST=0 USE_MPS=${PYTORCH_USE_MPS} USE_DDLOG=1 USE_TENSORRT=0 "CMAKE_CXX_FLAGS=-isystem ${SPDLOG_INCLUDE_DIR} -isystem ${PROTOBUF_INCLUDE_DIR}" "CMAKE_CUDA_FLAGS=-isystem ${SPDLOG_INCLUDE_DIR} -isystem ${PROTOBUF_INCLUDE_DIR}" CMAKE_PREFIX_PATH="${PROTOBUF_LIB_DIR}/cmake" MAX_JOBS=8 python3 ../pytorch/tools/build_libtorch.py
INSTALL_COMMAND ""
DEPENDS spdlog protobuf
)
set(TORCH_BINARY_LOCATION ${CMAKE_BINARY_DIR}/pytorch/src/pytorch-build/build)
else()
if(USE_TORCH_CPU_ONLY)
set(PYTORCH_USE_CUDA 0)
else()
set(PYTORCH_USE_CUDA 1)
endif()
file(WRITE ${CMAKE_BINARY_DIR}/build_pytorch.sh "set -x\n${CMAKE_COMMAND} -E env PATH=${PROTOBUF_LIB_DIR}:$ENV{PATH} BUILD_CUSTOM_PROTOBUF=0 GLIBCXX_USE_CXX11_ABI=1 BUILD_TEST=0 USE_CUDA=${PYTORCH_USE_CUDA} BUILD_CAFFE2=1 BUILD_CAFFE2_OPS=1 BUILD_CAFFE2_MOBILE=0 USE_DDLOG=1 USE_TENSORRT=0 CAFFE2_LINK_LOCAL_PROTOBUF=0 \"CMAKE_CXX_FLAGS=-isystem ${SPDLOG_INCLUDE_DIR} -isystem ${PROTOBUF_INCLUDE_DIR} -isystem /usr/lib/x86_64-linux-gnu/openmpi/include\" \"CMAKE_CUDA_FLAGS=-isystem ${SPDLOG_INCLUDE_DIR} -isystem ${PROTOBUF_INCLUDE_DIR} -isystem /usr/lib/x86_64-linux-gnu/openmpi/include\" TORCH_CUDA_ARCH_LIST=\"${CUDA_ARCH}\" \"CMAKE_CUDA_COMPILER=/usr/local/cuda/bin/nvcc\" CMAKE_PREFIX_PATH=${PROTOBUF_LIB_DIR}/cmake MAX_JOBS=8 python3 ../pytorch/tools/build_libtorch.py")
ExternalProject_Add(
pytorch
PREFIX pytorch
GIT_REPOSITORY https://github.com/pytorch/pytorch.git
GIT_TAG ${PYTORCH_COMMIT}
GIT_CONFIG advice.detachedHead=false
UPDATE_DISCONNECTED 1
PATCH_COMMAND "" test -f ${PYTORCH_COMPLETE} && echo Skipping || git apply ${PYTORCH_PATCHES} && echo Applying ${PYTORCH_PATCHES}
CONFIGURE_COMMAND "" cd ${CMAKE_BINARY_DIR}/pytorch/src/pytorch/third_party/fmt/ && git checkout 7.1.0
BUILD_COMMAND ""
COMMAND test -f ${PYTORCH_COMPLETE} && echo Skipping || sh ${CMAKE_BINARY_DIR}/build_pytorch.sh
INSTALL_COMMAND ""
DEPENDS spdlog protobuf
)
endif()
set(TORCH_LOCATION ${CMAKE_BINARY_DIR}/pytorch/src/pytorch/torch)
endif()
if (APPLE)
set(TORCH_LIB_DEPS ${TORCH_BINARY_LOCATION}/lib/libtorch.dylib ${TORCH_BINARY_LOCATION}/lib/libtorch_cpu.dylib ${TORCH_BINARY_LOCATION}/lib/libc10.dylib ${TORCH_BINARY_LOCATION}/lib/libtorch_global_deps.dylib -llmdb)
else()
set(TORCH_LIB_DEPS ${TORCH_LOCATION}/lib/libtorch.so ${TORCH_LOCATION}/lib/libtorch_cpu.so ${TORCH_LOCATION}/lib/libc10.so -llmdb)
if (USE_TORCH_CPU_ONLY)
list(APPEND TORCH_LIB_DEPS iomp5)
else()
list(APPEND TORCH_LIB_DEPS ${TORCH_LOCATION}/lib/libc10_cuda.so ${TORCH_LOCATION}/lib/libtorch_cuda.so)
endif()
endif()
set(TORCH_INC_DIR ${TORCH_LOCATION}/include/ ${TORCH_LOCATION}/include/torch/csrc/api/include/ ${CMAKE_BINARY_DIR}/pytorch/src/pytorch/torch/include/torch/csrc/api/include ${TORCH_LOCATION}/.. ${CMAKE_BINARY_DIR}/src)
set(TORCH_LIB_DIR ${TORCH_LOCATION}/lib/)
# TORCH VISION
message(STATUS "Configuring Pytorch Vision")
set(PYTORCH_VISION_COMMIT "v0.19.1")
set(PYTORCH_VISION_PATCHES_PATH ${CMAKE_BINARY_DIR}/patches/pytorch/vision)
# set(PYTORCH_VISION_PATCHES
# ${PYTORCH_VISION_PATCHES_PATH}/xxx.patch # add patches here
# )
set(PYTORCH_VISION_COMPLETE ${CMAKE_BINARY_DIR}/CMakeFiles/pytorch_vision-complete)
set(TORCHVISION_LOCATION "${CMAKE_BINARY_DIR}/pytorch_vision/src/pytorch_vision-install")
file(WRITE ${CMAKE_BINARY_DIR}/build_pytorch_vision.sh "sh ${CMAKE_SOURCE_DIR}/cmake/build_external.sh PYTORCH_VISION ${CMAKE_BINARY_DIR}/pytorch_vision ${PYTORCH_VISION_COMPLETE} src/pytorch_vision src/pytorch_vision-build ${N} \"install\" ${CMAKE_COMMAND} ${PYTORCH_VISION_FLAGS} -DWITH_CUDA=${PYTORCH_USE_CUDA} -DCMAKE_PREFIX_PATH=${TORCH_LOCATION} -DCMAKE_INSTALL_PREFIX=${TORCHVISION_LOCATION} -DCMAKE_INCLUDE_PATH=${PROTOBUF_INCLUDE_DIR} -DCMAKE_LIBRARY_PATH=${PROTOBUF_LIB_DIR} \"-DCMAKE_CXX_FLAGS=-isystem ${CMAKE_BINARY_DIR}/pytorch/src/pytorch/ -isystem ${SPDLOG_INCLUDE_DIR} -isystem ${PROTOBUF_INCLUDE_DIR}\" \"-DCMAKE_CUDA_FLAGS=-isystem ${CMAKE_BINARY_DIR}/pytorch/src/pytorch/ -isystem ${SPDLOG_INCLUDE_DIR} -isystem ${PROTOBUF_INCLUDE_DIR}\" \"-DCMAKE_CUDA_STANDARD=17\" \"-DTORCH_CUDA_ARCH_LIST=${CUDA_ARCH}\" -DCMAKE_CUDA_COMPILER=/usr/local/cuda/bin/nvcc")
ExternalProject_Add(
pytorch_vision
PREFIX pytorch_vision
GIT_REPOSITORY https://github.com/pytorch/vision.git
GIT_TAG ${PYTORCH_VISION_COMMIT}
GIT_CONFIG advice.detachedHead=false
UPDATE_DISCONNECTED 1
PATCH_COMMAND "" #test -f ${PYTORCH_VISION_COMPLETE} && echo Skipping || git apply ${PYTORCH_VISION_PATCHES} && echo Applying ${PYTORCH_VISION_PATCHES}
CONFIGURE_COMMAND ""
BUILD_COMMAND sh ${CMAKE_BINARY_DIR}/build_pytorch_vision.sh
INSTALL_COMMAND ""
DEPENDS protobuf pytorch
)
list(APPEND TORCH_INC_DIR "${TORCHVISION_LOCATION}/include/")
list(APPEND TORCH_LIB_DIR "${TORCHVISION_LOCATION}/lib/")
list(APPEND TORCH_LIB_DEPS torchvision)
endif()
# XGBoost
if (USE_XGBOOST)
message(STATUS "Configuring XGBoost")
add_definitions(-DUSE_XGBOOST)
set(XGBOOST_LIB_DEPS -Wl,--whole-archive ${CMAKE_BINARY_DIR}/xgboost/src/xgboost-build/libxgboost.a -Wl,--no-whole-archive ${CMAKE_BINARY_DIR}/xgboost/src/xgboost-build/dmlc-core/libdmlc.a ${CMAKE_BINARY_DIR}/xgboost/src/xgboost-build/librabit.a)
if (NOT USE_XGBOOST_CPU_ONLY)
add_definitions(-DUSE_XGBOOST_GPU)
list(APPEND XGBOOST_LIB_DEPS ${CMAKE_BINARY_DIR}/xgboost/src/xgboost/build/CMakeFiles/gpuxgboost.dir/plugin/updater_gpu/src/gpuxgboost_generated_updater_gpu.cu.o ${CMAKE_BINARY_DIR}/xgboost/src/xgboost/build/nccl/libnccl.a)
ExternalProject_Add(
xgboost_cub
PREFIX xgboost_cub
URL https://github.com/NVlabs/cub/archive/1.6.4.zip
URL_HASH SHA256=4198e9c447a1e2a963b9e0e4d861df48baa47fb02e5e4fc507d1834afc99185a
INSTALL_COMMAND ""
BUILD_COMMAND ""
CONFIGURE_COMMAND ""
)
ExternalProject_Add(
xgboost
PREFIX xgboost
GIT_REPOSITORY https://github.com/dmlc/xgboost.git
GIT_TAG 84d992babcc370bff6cf4fe89985f072b0b91a64
GIT_CONFIG advice.detachedHead=false
PATCH_COMMAND
git reset --hard &&