-
Notifications
You must be signed in to change notification settings - Fork 78
/
CMakeLists.txt
1232 lines (1049 loc) · 37.3 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
################################################################################
## Copyright (c) 2014-2024, Lawrence Livermore National Security, LLC.
## Produced at the Lawrence Livermore National Laboratory.
## Written by the LBANN Research Team (B. Van Essen, et al.) listed in
## the CONTRIBUTORS file. <[email protected]>
##
## LLNL-CODE-697807.
## All rights reserved.
##
## This file is part of LBANN: Livermore Big Artificial Neural Network
## Toolkit. For details, see http://software.llnl.gov/LBANN or
## https://github.com/LLNL/LBANN.
##
## Licensed under the Apache License, Version 2.0 (the "Licensee"); you
## may not use this file except in compliance with the License. You may
## obtain a copy of the License at:
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
## implied. See the License for the specific language governing
## permissions and limitations under the license.
################################################################################
cmake_minimum_required(VERSION 3.21)
cmake_policy(VERSION 3.21)
project(LBANN C CXX)
# Prevent in-source builds
if (PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR)
message(FATAL_ERROR
"In-source build attempted; please clean the CMake cache and then "
"switch to an out-of-source build, e.g.,\n"
"rm -rf CMakeCache.txt CMakeFiles/\nmkdir build && "
"cd build && cmake <options> ..\n")
endif ()
# Add CMake modules
include(CheckCompilerFlag)
list(APPEND CMAKE_MODULE_PATH
"${CMAKE_CURRENT_SOURCE_DIR}/cmake"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
include(LBANNCMakeUtilities)
# FIXME: RelWithDebInfo too?
if (CMAKE_BUILD_TYPE MATCHES Debug)
set(LBANN_DEBUG TRUE)
endif ()
if (NOT DEFINED BUILD_SHARED_LIBS)
set(BUILD_SHARED_LIBS ON)
endif ()
# Version setup
set(LBANN_VERSION_MAJOR 0)
set(LBANN_VERSION_MINOR 105)
set(LBANN_VERSION_PATCH 0)
set(LBANN_VERSION
"${LBANN_VERSION_MAJOR}.${LBANN_VERSION_MINOR}.${LBANN_VERSION_PATCH}")
# Check to see if we are in a git repo
find_program(__GIT_EXECUTABLE git)
mark_as_advanced(__GIT_EXECUTABLE)
if (__GIT_EXECUTABLE)
execute_process(
COMMAND ${__GIT_EXECUTABLE} rev-parse --is-inside-work-tree
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE __BUILDING_FROM_GIT_SOURCES
OUTPUT_STRIP_TRAILING_WHITESPACE)
if (__BUILDING_FROM_GIT_SOURCES)
# Get the git version so that we can embed it into the executable
execute_process(
COMMAND ${__GIT_EXECUTABLE} rev-parse --show-toplevel
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE __GIT_TOPLEVEL_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(
COMMAND ${__GIT_EXECUTABLE} rev-parse --git-dir
WORKING_DIRECTORY "${__GIT_TOPLEVEL_DIR}"
OUTPUT_VARIABLE __GIT_GIT_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(
COMMAND ${__GIT_EXECUTABLE} --git-dir "${__GIT_GIT_DIR}" describe
--abbrev=7 --always --dirty --tags
WORKING_DIRECTORY "${__GIT_TOPLEVEL_DIR}"
OUTPUT_VARIABLE __GIT_DESCRIBE_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE)
set(LBANN_GIT_VERSION "${__GIT_DESCRIBE_VERSION}"
CACHE STRING "LBANN's version string as told by git.")
endif (__BUILDING_FROM_GIT_SOURCES)
endif (__GIT_EXECUTABLE)
if (CMAKE_HOST_SYSTEM_NAME MATCHES "Linux")
set(LBANN_GNU_LINUX TRUE)
endif ()
# Options
option(LBANN_WITH_CEREAL_XML
"Enable the use of XML archives from Cereal"
OFF)
set(LBANN_HAS_CEREAL_XML_ARCHIVES ${LBANN_WITH_CEREAL_XML})
option(LBANN_WITH_CNPY "Include cnpy" ON)
option(LBANN_WITH_CONDUIT "Enable Conduit library" ON)
option(LBANN_WITH_CUDNN "Include Nvidia cuDNN" ON)
# For now, we just assert CPU support.
option(LBANN_WITH_ONEDNN "Include OneDNN API support" OFF)
option(LBANN_WITH_DISTCONV "Enable DiHydrogen's Distconv" OFF)
if (LBANN_WITH_DISTCONV)
message(WARNING "Distconv support is currently expermimental. "
"There is no stable interface. "
"Use caution before using any features.")
endif (LBANN_WITH_DISTCONV)
option(LBANN_WITH_FFT "Build the FFT layer (requires FFTW)" OFF)
option(LBANN_WITH_HWLOC
"Enable topology-aware optimizations" ON)
option(LBANN_WITH_NVPROF
"Enable NVTX-based instrumentation for nvprof" OFF)
option(LBANN_WITH_ROCTRACER
"Enable roctx-based instrumentation for nvprof" OFF)
option(LBANN_WITH_PYTHON_FRONTEND
"Install Python frontend and enable embedded Python" ON)
option(LBANN_WITH_EMBEDDED_PYTHON
"Enable embedded Python" ON)
if (LBANN_WITH_EMBEDDED_PYTHON AND NOT LBANN_WITH_PYTHON_FRONTEND)
# (trb): This could also be an error.
message(WARNING
"Interesting combination of NOT LBANN_WITH_PYTHON_FRONTEND "
"and LBANN_WITH_EMBEDDED_PYTHON detected. This is just "
"to make sure you're aware.")
endif (LBANN_WITH_EMBEDDED_PYTHON AND NOT LBANN_WITH_PYTHON_FRONTEND)
option(LBANN_WITH_VISION "Include vision processing components" ON)
option(LBANN_WITH_TBINF "Include Tensorboard interface" ${LBANN_WITH_VISION})
option(LBANN_WITH_VTUNE
"Link the Intel VTune profiling library" OFF)
option(LBANN_WITH_CALIPER
"Link the Caliper profiling library" OFF)
option(LBANN_WITH_UNIT_TESTING
"Enable the unit testing framework (requires Catch2)" OFF)
option(LBANN_WITH_ADDRESS_SANITIZER
"Try clang-style use of ASAN (-fsanitize=address)" OFF)
option(LBANN_WITH_ONNX
"Enable exporting onnx model." OFF)
# Use deterministic GPU algorithms and layer operations
option(LBANN_DETERMINISTIC
"Use deterministic algorithms as much as possible." OFF)
if (LBANN_DETERMINISTIC)
set(LBANN_HAS_DETERMINISTIC TRUE)
endif (LBANN_DETERMINISTIC)
option(LBANN_DEBUG_PRINT_SUBTARGETS
"Turn on debugging output of internal target properties." OFF)
mark_as_advanced(LBANN_DEBUG_PRINT_SUBTARGETS)
option(LBANN_WITH_DOUBLE
"Build with support for double precision layers, optimizers, and weights." OFF)
if (LBANN_WITH_DOUBLE)
set(LBANN_HAS_DOUBLE TRUE)
endif (LBANN_WITH_DOUBLE)
option(LBANN_EXPLICIT_LIBDL
"Explicitly find and link to libdl" OFF)
mark_as_advanced(LBANN_EXPLICIT_LIBDL)
# This option is off by default because non-developers should not use
# this option under normal circumstances.
option(LBANN_WARNINGS_AS_ERRORS
"Build with warnings promoted to errors." OFF)
mark_as_advanced(LBANN_WARNINGS_AS_ERRORS)
# The datatype option is not binary
set(LBANN_DATATYPE "float"
CACHE STRING "The datatype to use in LBANN")
# Initialize build
# Get installation directories -- these get used in various places;
# best to just make them available
include(GNUInstallDirs)
include(SetupCXX)
################################################################
# Initialize dependencies
################################################################
# Required dependencies
find_package(Threads REQUIRED)
# Argument parsing backend
find_package(Clara REQUIRED)
find_package(CEREAL CONFIG REQUIRED NAMES CEREAL cereal)
set(LBANN_HAS_CEREAL ${CEREAL_FOUND})
# The imported target is just called "cereal". Super.
if (TARGET cereal)
set(CEREAL_LIBRARIES cereal)
elseif (TARGET cereal::cereal)
set(CEREAL_LIBRARIES cereal::cereal)
endif ()
# Setup the linear algebra library
find_package(Hydrogen 1.5.0 CONFIG REQUIRED)
message(STATUS "Found Hydrogen@${HYDROGEN_VERSION}: ${Hydrogen_DIR}")
set(LBANN_HAS_HYDROGEN ${Hydrogen_FOUND})
# CUDA-ness of LBANN is 1:1 with Hydrogen. Iff Hydrogen has CUDA,
# LBANN gets CUDA.
set(LBANN_HAS_CUDA ${_HYDROGEN_HAVE_CUDA})
set(LBANN_WITH_CUDA ${LBANN_HAS_CUDA})
set(LBANN_HAS_ROCM ${_HYDROGEN_HAVE_ROCM})
if (LBANN_HAS_CUDA OR LBANN_HAS_ROCM)
set(LBANN_HAS_GPU TRUE)
endif ()
# DiHydrogen and Distconv
if (LBANN_WITH_DISTCONV)
find_package(DiHydrogen CONFIG REQUIRED COMPONENTS Meta Patterns DistConv)
set(LBANN_HAS_DISTCONV TRUE)
set(LBANN_H2_LIBS
H2::H2Meta
H2::H2Patterns
H2::H2DistConv)
else ()
find_package(DiHydrogen CONFIG REQUIRED COMPONENTS Meta Patterns)
set(LBANN_H2_LIBS
H2::H2Meta
H2::H2Patterns)
endif ()
set(LBANN_HAS_DIHYDROGEN TRUE)
message(STATUS "Found DiHydrogen: ${DiHydrogen_DIR}")
# Inherit half-precision stuff from Hydrogen
set(LBANN_HAS_HALF ${HYDROGEN_HAVE_HALF}) # This is CPU-only
if (Aluminum_FOUND)
message(STATUS "Found Aluminum@${ALUMINUM_VERSION}: ${Aluminum_DIR}")
message(STATUS "Aluminum found in Hydrogen. Using Aluminum.")
set(LBANN_HAS_ALUMINUM ON)
endif ()
include(SetupOpenMP)
include(SetupMPI)
include(SetupProtobuf)
if (LBANN_DATATYPE STREQUAL "double")
set(LBANN_HAS_DOUBLE TRUE)
endif ()
# Setup FFTW
if (LBANN_WITH_FFT)
find_package(FFTW 3.3 REQUIRED)
set(LBANN_HAS_FFTW ${FFTW_FOUND})
if (TARGET FFTW::FFTW_FLOAT)
set(LBANN_HAS_FFTW_FLOAT TRUE)
endif ()
if (TARGET FFTW::FFTW_DOUBLE)
set(LBANN_HAS_FFTW_DOUBLE TRUE)
endif ()
endif (LBANN_WITH_FFT)
# OpenCV installs a CMake configure file we can exploit
if (LBANN_WITH_VISION)
find_package(OpenCV CONFIG REQUIRED)
endif ()
set(LBANN_HAS_OPENCV ${OpenCV_FOUND})
# OneDNN stuff
if (LBANN_WITH_ONEDNN)
find_package(DNNL 1.6.0 CONFIG)
set(LBANN_HAS_ONEDNN_V1 ${DNNL_FOUND})
if (NOT DNNL_FOUND)
find_package(DNNL 2.0.0 REQUIRED CONFIG)
endif ()
if (DNNL_FOUND)
set(LBANN_DNNL_LIBS DNNL::dnnl)
endif ()
set(LBANN_HAS_ONEDNN ${DNNL_FOUND})
if (NOT DNNL_CPU_RUNTIME STREQUAL "NONE")
set(LBANN_HAS_ONEDNN_CPU TRUE)
# GRU layer strikes again...
set(LBANN_GRU_LAYER_ONEDNN_CPU_SUPPORTED TRUE)
else ()
set(LBANN_HAS_ONEDNN_CPU FALSE)
endif ()
if (NOT DNNL_GPU_RUNTIME STREQUAL "NONE")
set(LBANN_HAS_ONEDNN_GPU TRUE)
else ()
set(LBANN_HAS_ONEDNN_GPU FALSE)
endif ()
endif ()
# Only used if have GPU and have CPU half.
if (LBANN_HAS_GPU AND LBANN_HAS_HALF)
set(LBANN_HAS_GPU_FP16 ${HYDROGEN_GPU_USE_FP16})
endif ()
if (LBANN_HAS_CUDA)
enable_language(CUDA)
if (NOT CMAKE_CUDA_STANDARD OR CMAKE_CUDA_STANDARD EQUAL 98)
set(CMAKE_CUDA_STANDARD 14)
endif ()
set(CMAKE_CUDA_STANDARD_REQUIRED TRUE)
endif ()
if (LBANN_HAS_ALUMINUM)
if (AL_HAS_CUDA AND NOT AL_HAS_ROCM AND NOT LBANN_HAS_CUDA)
message(WARNING
"Aluminum has CUDA support but CUDA support has not been found.")
endif ()
option(LBANN_BUILT_WITH_SPECTRUM "LBANN was built with Spectrum MPI" OFF)
if (LBANN_BUILT_WITH_SPECTRUM)
set(LBANN_ALUMINUM_MPI_PASSTHROUGH ON)
endif (LBANN_BUILT_WITH_SPECTRUM)
endif (LBANN_HAS_ALUMINUM)
# Setup some additional device-side things
set(LBANN_HAS_DNN_LIB FALSE)
if (LBANN_HAS_CUDA)
if (NOT LBANN_WITH_CUDNN)
message(WARNING
"Despite the fact that it looks optional, cuDNN is currently required "
"when building with CUDA support. You have tried LBANN_WITH_CUDNN=OFF. "
"It will be searched for anyway.")
set(LBANN_WITH_CUDNN ON)
endif ()
# Hydrogen will have found this, but it doesn't hurt to find it
# again.
find_package(CUDAToolkit 11.0.0 REQUIRED)
find_package(cuDNN REQUIRED)
set(LBANN_HAS_CUDNN ${cuDNN_FOUND})
set(LBANN_HAS_DNN_LIB ${cuDNN_FOUND})
find_package(cuTENSOR)
set(LBANN_HAS_CUTENSOR ${cuTENSOR_FOUND})
if (NOT LBANN_HAS_CUTENSOR)
find_package(cuTT)
set(LBANN_HAS_CUTT ${cuTT_FOUND})
endif ()
if (LBANN_HAS_CUTENSOR OR LBANN_HAS_CUTT)
set(LBANN_HAS_TENSOR_PERMUTE TRUE)
endif ()
# Special stuff for the GRU layer
if ((CUDAToolkit_VERSION VERSION_GREATER_EQUAL "11.0.0")
AND (CUDNN_VERSION VERSION_GREATER_EQUAL "8.0.4"))
set(LBANN_GRU_LAYER_CUDNN_SUPPORTED TRUE)
endif ()
set(LBANN_CUDA_LIBS
CUDA::cudart
CUDA::nvToolsExt
CUDA::cufft
cuda::cudnn)
if (LBANN_HAS_CUTENSOR)
list(APPEND LBANN_CUDA_LIBS cuTENSOR::cuTENSOR)
endif ()
if (LBANN_HAS_CUTT)
list(APPEND LBANN_CUDA_LIBS cuTT::cuTT)
endif ()
if (LBANN_HAS_ALUMINUM AND AL_HAS_NCCL)
set(LBANN_HAS_NCCL2 TRUE)
else ()
set(LBANN_HAS_NCCL2 FALSE)
endif ()
if (LBANN_WITH_NVSHMEM)
find_package(NVSHMEM REQUIRED)
# Build LBANN as a static library to get around a bug in NVSHMEM
# set(BUILD_SHARED_LIBS OFF)
list(APPEND LBANN_CUDA_LIBS NVSHMEM::NVSHMEM)
endif ()
set(LBANN_HAS_NVSHMEM "${NVSHMEM_FOUND}")
# This is for back-compatibility with old Hydrogen/Aluminum.
if (NOT TARGET cuda::nvtx)
add_library(cuda::nvtx ALIAS CUDA::nvToolsExt)
endif ()
endif (LBANN_HAS_CUDA)
if (LBANN_HAS_ROCM)
if (NOT LBANN_ROCM_PATH)
if (ROCM_PATH)
set(LBANN_ROCM_PATH "${ROCM_PATH}")
elseif (DEFINED ENV{ROCM_PATH})
set(LBANN_ROCM_PATH "$ENV{ROCM_PATH}")
else ()
set(LBANN_ROCM_PATH "/opt/rocm")
endif ()
endif ()
message(STATUS "Using LBANN_ROCM_PATH: ${LBANN_ROCM_PATH}")
# The Catch2 tests are only ever build artifacts, so this needs to
# change too.
if (CMAKE_BUILD_RPATH)
# The first of these actually matters; the last 4 are just good
# measure.
list(REMOVE_ITEM CMAKE_BUILD_RPATH
"${LBANN_ROCM_PATH}/lib"
"/usr/lib64"
"/usr/lib"
"/usr/local/lib64"
"/usr/local/lib"
)
# Write the value out to the cache
set(CMAKE_BUILD_RPATH "${CMAKE_BUILD_RPATH}"
CACHE STRING "The build rpath to use"
FORCE)
endif ()
if (CMAKE_INSTALL_RPATH)
# The first of these actually matters; the last 4 are just good
# measure.
list(REMOVE_ITEM CMAKE_INSTALL_RPATH
"${LBANN_ROCM_PATH}/lib"
"/usr/lib64"
"/usr/lib"
"/usr/local/lib64"
"/usr/local/lib"
)
# Write the value out to the cache
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH}"
CACHE STRING "The install rpath to use"
FORCE)
endif ()
find_package(hip CONFIG REQUIRED)
enable_language(HIP)
find_package(MIOpen CONFIG REQUIRED)
find_library(HSA_LIBRARY hsa-runtime64
HINTS ${LBANN_ROCM_PATH}/hsa ${ROCM_PATH}/hsa $ENV{ROCM_PATH}/hsa
PATH_SUFFIXES lib lib64
DOC "HSA runtime library"
NO_DEFAULT_PATH)
find_library(HSA_LIBRARY hsa-runtime64)
set(LBANN_HAS_MIOPEN ${MIOpen_FOUND})
set(LBANN_HAS_DNN_LIB ${MIOpen_FOUND})
set(LBANN_ROCM_LIBS
hip::host
MIOpen)
if (HSA_LIBRARY)
list(APPEND LBANN_ROCM_LIBS "${HSA_LIBRARY}")
endif ()
if (LBANN_HAS_FFTW)
find_package(rocfft CONFIG REQUIRED)
list(APPEND LBANN_ROCM_LIBS roc::rocfft)
endif ()
if (LBANN_WITH_ROCTRACER)
find_package(Roctracer MODULE COMPONENTS roctracer roctx)
if (Roctracer_FOUND)
set(LBANN_HAS_ROCTRACER TRUE)
list(APPEND LBANN_ROCM_LIBS roctracer::roctracer)
endif ()
endif ()
find_package(cuTT) # hipTT
set(LBANN_HAS_HIPTT ${cuTT_FOUND})
if (LBANN_HAS_HIPTT)
list(APPEND LBANN_ROCM_LIBS cuTT::cuTT)
set(LBANN_HAS_TENSOR_PERMUTE TRUE)
endif ()
# More hand-holding
get_filename_component(LBANN_ROCM_LLVM_BASE_DIR
"${CMAKE_HIP_COMPILER}"
DIRECTORY)
get_filename_component(LBANN_ROCM_LLVM_BASE_DIR
"${LBANN_ROCM_LLVM_BASE_DIR}"
DIRECTORY)
# Clean up some paths
list(REMOVE_ITEM
CMAKE_HIP_IMPLICIT_LINK_DIRECTORIES
"${LBANN_ROCM_PATH}/lib"
"${LBANN_ROCM_LLVM_BASE_DIR}/lib")
# This shouldn't be needed, but it shouldn't hurt.
list(REMOVE_ITEM
CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES
"${LBANN_ROCM_PATH}/lib"
"${LBANN_ROCM_LLVM_BASE_DIR}/lib")
endif (LBANN_HAS_ROCM)
# This is used in the sample list implementation
find_package(ZSTR REQUIRED)
# This shouldn't be here, but is ok for now. This will occasionally be
# part of another TPL's libraries (e.g., MKL), but it's no
# guarantee. There's no harm including it multiple times.
if (LBANN_EXPLICIT_LIBDL AND NOT DL_LIBRARY)
find_library(DL_LIBRARY dl DOC "The dynamic loader library.")
if (DL_LIBRARY)
message(STATUS "Found dl: ${DL_LIBRARY}")
else ()
message(FATAL_ERROR
"dl library not found! This is a required library.\n"
"Please add the path to libdl to CMAKE_LIBRARY_PATH.")
endif (DL_LIBRARY)
endif ()
# Nothing in LBANN explicitly includes the zlib header or, as far as I
# can tell, explicitly calls a zlib function. So some dependency isn't
# propagating its dependencies properly (protobuf of sufficiently new
# enough version is one such culprit). This should work around that.
find_package(ZLIB MODULE REQUIRED)
# Other optional dependencies
# TODO: This probably shouldn't be the case and should disable specific
# callbacks when OpenCV is not available
if (LBANN_WITH_TBINF AND NOT LBANN_HAS_OPENCV)
message(FATAL_ERROR "TensorBoard requires OpenCV. "
"Enable LBANN_WITH_VISION to use TensorBoard.")
endif ()
if (LBANN_WITH_TBINF)
add_subdirectory(external/TBinf)
endif ()
# Find Python
if (LBANN_WITH_PYTHON_FRONTEND OR LBANN_WITH_EMBEDDED_PYTHON)
find_package(Python REQUIRED COMPONENTS Interpreter Development)
if (LBANN_WITH_PYTHON_FRONTEND AND Python_FOUND)
set(LBANN_HAS_PYTHON_FRONTEND TRUE)
endif ()
if (LBANN_WITH_EMBEDDED_PYTHON AND Python_FOUND)
set(LBANN_PYTHON_LIBS Python::Python)
set(LBANN_HAS_EMBEDDED_PYTHON TRUE)
endif ()
if (Python_VERSION_MAJOR LESS 3)
set(LBANN_HAS_PYTHON_FRONTEND FALSE)
set(LBANN_HAS_EMBEDDED_PYTHON FALSE)
message(FATAL_ERROR "Python 2 is not supported.")
endif ()
# Setup the installation stuff
set(PYTHON_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}"
CACHE PATH "The prefix for the python installation")
set(CMAKE_INSTALL_PYTHONDIR
"lib/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}/site-packages"
CACHE PATH
"Relative path from PYTHON_INSTALL_PREFIX to the python package install")
endif (LBANN_WITH_PYTHON_FRONTEND OR LBANN_WITH_EMBEDDED_PYTHON)
if (LBANN_WITH_PYTHON_FRONTEND)
set(LBANN_PFE_PYTHON_EXECUTABLE "${Python_EXECUTABLE}" CACHE FILEPATH "")
set(LBANN_PFE_PYTHONPATH "${PYTHON_INSTALL_PREFIX}/${CMAKE_INSTALL_PYTHONDIR}" CACHE STRING "")
set(AWS_OFI_RCCL_LIBDIR "$ENV{AWS_OFI_RCCL_LIBDIR}" CACHE STRING "")
configure_file(
"${CMAKE_SOURCE_DIR}/cmake/configure_files/lbann_pfe.sh.in"
"${CMAKE_BINARY_DIR}/lbann_pfe.sh"
@ONLY)
install(
PROGRAMS "${PROJECT_BINARY_DIR}/lbann_pfe.sh"
DESTINATION "${CMAKE_INSTALL_BINDIR}")
endif ()
if (LBANN_WITH_VTUNE)
find_package(VTune MODULE)
if (VTune_FOUND)
set(LBANN_VTUNE TRUE)
set(LBANN_HAS_VTUNE TRUE)
else ()
set(LBANN_VTUNE FALSE)
set(LBANN_HAS_VTUNE FALSE)
set(LBANN_WITH_VTUNE OFF)
message(WARNING
"Requested LBANN_WITH_VTUNE=ON, but VTUNE support not detected. "
"Support NOT enabled. "
"Try setting VTUNE_DIR to point to the VTune install prefix "
"and reconfigure.")
endif (VTune_FOUND)
endif (LBANN_WITH_VTUNE)
if (LBANN_WITH_CALIPER)
find_package(caliper REQUIRED)
find_package(adiak REQUIRED)
set(LBANN_HAS_CALIPER TRUE)
message(STATUS "LBANN_WITH_CALIPER")
configure_file(
"${CMAKE_SOURCE_DIR}/cmake/configure_files/adiak_config.hpp.in"
"${CMAKE_BINARY_DIR}/adiak_config.hpp"
@ONLY)
endif (LBANN_WITH_CALIPER)
if (LBANN_WITH_CUDA AND LBANN_WITH_NVPROF)
set(LBANN_NVPROF TRUE)
endif ()
if (LBANN_WITH_CNPY)
find_package(CNPY REQUIRED)
set(LBANN_HAS_CNPY ${CNPY_FOUND})
endif (LBANN_WITH_CNPY)
if (LBANN_WITH_HWLOC)
find_package(HWLOC REQUIRED)
set(LBANN_TOPO_AWARE ${HWLOC_FOUND})
endif (LBANN_WITH_HWLOC)
if (LBANN_WITH_CONDUIT)
find_package(Conduit 0.7.0 CONFIG REQUIRED)
message(STATUS "Found CONDUIT: ${Conduit_DIR}")
if (NOT TARGET conduit::conduit OR NOT TARGET conduit::conduit_mpi)
message(FATAL_ERROR "Missing some CONDUIT required library.")
endif ()
set(CONDUIT_LIBRARIES conduit::conduit conduit::conduit_mpi)
endif (LBANN_WITH_CONDUIT)
if (LBANN_WITH_BOOST)
# Boost (optional)
find_package(Boost)
set(LBANN_HAS_BOOST ${Boost_FOUND})
endif (LBANN_WITH_BOOST)
# Include onnx dependency
if (LBANN_WITH_ONNX)
find_package(ONNX CONFIG REQUIRED)
set (LBANN_HAS_ONNX TRUE)
endif ()
if (LBANN_WITH_UNIT_TESTING)
# LBANN allows for Catch2 v2.* or v3.*
find_package(Catch2 3.0.0 CONFIG QUIET)
if (NOT Catch2_FOUND)
find_package(Catch2 2.0.0 CONFIG REQUIRED)
set(LBANN_USE_CATCH2_V3 FALSE)
else ()
set(LBANN_USE_CATCH2_V3 TRUE)
endif ()
message(STATUS "Found Catch2: Version ${Catch2_VERSION}")
if (CMAKE_CXX_COMPILER_ID MATCHES "ROCMClang")
set_target_properties(Catch2::Catch2
PROPERTIES INTERFACE_COMPILE_FEATURES "cxx_std_17")
endif ()
# Now that Catch2 has been found, start adding the unit tests
include(CTest)
include(Catch)
add_subdirectory(src/callbacks/unit_test)
add_subdirectory(src/execution_algorithms/unit_test)
add_subdirectory(src/data_ingestion/coordinator/unit_test)
add_subdirectory(src/data_ingestion/readers/unit_test)
add_subdirectory(src/layers/unit_test)
add_subdirectory(src/layers/activations/unit_test)
add_subdirectory(src/layers/learning/unit_test)
add_subdirectory(src/layers/regularizers/unit_test)
add_subdirectory(src/layers/transform/unit_test)
add_subdirectory(src/metrics/unit_test)
add_subdirectory(src/models/unit_test)
add_subdirectory(src/proto/unit_test)
add_subdirectory(src/operators/math/unit_test)
add_subdirectory(src/optimizers/unit_test)
add_subdirectory(src/utils/unit_test)
add_subdirectory(src/weights/unit_test)
add_subdirectory(src/transforms/unit_test)
if (LBANN_HAS_OPENCV)
add_subdirectory(src/transforms/vision/unit_test)
endif ()
# Add this one last
add_subdirectory(unit_test)
endif (LBANN_WITH_UNIT_TESTING)
# Handle the documentation
add_subdirectory(docs)
################################################################
# Build LBANN
################################################################
# Add LBANN source files
add_subdirectory(include)
add_subdirectory(src)
# Write the configure file
configure_file(
"${CMAKE_SOURCE_DIR}/cmake/configure_files/lbann_config.hpp.in"
"${CMAKE_BINARY_DIR}/lbann_config.hpp"
@ONLY)
# Create the LBANN library
add_library(lbann
${LBANN_SOURCES}
${LBANN_HEADERS}
${LBANN_GPU_SOURCES})
if (LBANN_HAS_ROCM)
set_source_files_properties(${LBANN_GPU_SOURCES}
PROPERTIES
LANGUAGE HIP)
endif ()
set_target_properties(lbann
PROPERTIES
VERSION ${LBANN_VERSION})
target_include_directories(lbann PUBLIC
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}>
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
if (LBANN_HAS_CALIPER)
target_include_directories(lbann PUBLIC ${caliper_INCLUDE_PATH} ${adiak_INCLUDE_DIRS})
endif (LBANN_HAS_CALIPER)
# The max of CXX_STANDARD and this value will be used.
target_compile_features(lbann PUBLIC cxx_std_17)
target_link_libraries(lbann PUBLIC LbannProto)
if (LBANN_HAS_TBINF)
target_link_libraries(lbann PUBLIC TBinf)
endif ()
target_link_libraries(lbann PUBLIC
${HWLOC_LIBRARIES}
${LBANN_H2_LIBS}
${HYDROGEN_LIBRARIES}
${Aluminum_LIBRARIES}
${CONDUIT_LIBRARIES}
${CNPY_LIBRARIES}
${CLARA_LIBRARIES}
${LBANN_PYTHON_LIBS}
protobuf::libprotobuf
${CEREAL_LIBRARIES}
ZSTR::ZSTR)
if (LBANN_HAS_OPENCV)
target_link_libraries(lbann PUBLIC ${OpenCV_LIBRARIES})
endif ()
if (LBANN_HAS_FFTW)
target_link_libraries(lbann PUBLIC FFTW::FFTW)
endif ()
if (LBANN_HAS_ONNX)
target_link_libraries(lbann PUBLIC onnx)
endif ()
if (LBANN_HAS_VTUNE)
target_link_libraries(lbann PUBLIC ${VTUNE_STATIC_LIB})
endif ()
if(LBANN_HAS_CALIPER)
if(NOT TARGET adiak::adiak)
target_link_libraries(lbann PUBLIC adiak)
else ()
target_link_libraries(lbann PUBLIC adiak::adiak)
endif ()
target_link_libraries(lbann PUBLIC caliper)
endif ()
if (LBANN_EXPLICIT_LIBDL)
target_link_libraries(lbann PUBLIC ${DL_LIBRARY})
endif ()
target_link_libraries(lbann PUBLIC
OpenMP::OpenMP_CXX
Threads::Threads
MPI::MPI_CXX
${LBANN_CUDA_LIBS}
${LBANN_ROCM_LIBS}
${LBANN_DNNL_LIBS}
ZLIB::ZLIB)
# Ensure that MPI flags are passed to the HIP compiler on Cray platforms
get_target_property(LBANN_MPI_CXX_INCL_DIRS
MPI::MPI_CXX INTERFACE_INCLUDE_DIRECTORIES)
if (NOT LBANN_MPI_CXX_INCL_DIRS)
target_include_directories(lbann PRIVATE $<$<COMPILE_LANGUAGE:HIP>:${MPI_CXX_COMPILER_INCLUDE_DIRS}>)
endif ()
if (LBANN_FLAG_Werror_OK)
target_compile_options(lbann
PRIVATE $<$<COMPILE_LANGUAGE:CXX>:$<BUILD_INTERFACE:-Werror>>)
endif ()
if (LBANN_HAS_CUDA)
if (LBANN_HAS_NVSHMEM)
set_target_properties(lbann
PROPERTIES
CUDA_SEPARABLE_COMPILATION ON)
endif ()
# We leak some C++17 into .cu files. Oops, but also CUDA 11 has been
# out for a while.
set_target_properties(lbann
PROPERTIES
CUDA_STANDARD 17)
# Enable device lambdas with nvcc
check_compiler_flag(CUDA "--extended-lambda"
CUDA_COMPILER_SUPPORTS_EXTENDED_LAMBDA)
if (CUDA_COMPILER_SUPPORTS_EXTENDED_LAMBDA)
target_compile_options(lbann PRIVATE
$<$<COMPILE_LANGUAGE:CUDA>:--extended-lambda>)
else ()
check_compiler_flag(CUDA "--expt-extended-lambda"
CUDA_COMPILER_SUPPORTS_EXTENDED_LAMBDA)
if (CUDA_COMPILER_SUPPORTS_EXTENDED_LAMBDA)
target_compile_options(lbann PRIVATE
$<$<COMPILE_LANGUAGE:CUDA>:--expt-extended-lambda>)
endif ()
endif ()
endif (LBANN_HAS_CUDA)
# Fix the -g issue with Clang on OSX
if (APPLE)
message("** CMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}")
message("** CMAKE_CXX_FLAGS_DEBUG=${CMAKE_CXX_FLAGS_DEBUG}")
# Remove -g from the options
string(REGEX REPLACE
" ?-g[gdb0-9]*"
""
CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS}")
string(REGEX REPLACE
" ?-g[gdb0-9]*"
""
CMAKE_CXX_FLAGS_DEBUG
"${CMAKE_CXX_FLAGS_DEBUG}")
# Get all the sources and add "-g" to all of them.
get_target_property(_LBANN_SRCS lbann SOURCES)
# Cleanup source files
foreach (bad_file IN LISTS _LBANN_SRCS)
get_source_file_property(
_SRC_COMPILE_OPTS "${bad_file}" COMPILE_OPTIONS)
string(REGEX REPLACE
" ?-g[gdb0-9]*"
""
_SRC_COMPILE_OPTS
"${COMPILE_OPTIONS}")
set_source_files_properties(
"${bad_file}" PROPERTIES COMPILE_OPTIONS "${_SRC_COMPILE_OPTS}")
endforeach ()
endif ()
# Fix linking error with CUDA when building LBANN as static library
# Note: CMake usually defers linking to device symbols when building
# static libraries. However, the Catch2 executables don't correctly
# link to CUDA objects, leading to linking errors.
if (LBANN_HAS_CUDA AND NOT BUILD_SHARED_LIBS)
set_property(TARGET lbann PROPERTY CUDA_RESOLVE_DEVICE_SYMBOLS ON)
endif ()
# Clean things up
include(LBANNDebugUtilities)
lbann_remove_default_include_paths_from_all_subtargets(lbann)
# This is to fix a bug with certain compilers interacting poorly with
# NVCC. In particular, the NVCC include line would have things like
# "-isystem=/usr/include" which would cause issues resolving STL
# include paths. Since compilers include "/usr/include" in their
# system include paths anyway (things searched by #include <...>), we
# can safely remove these from the explicit link line.
if (LBANN_DEBUG_PRINT_SUBTARGETS)
lbann_print_all_subtargets(lbann)
endif ()
# Build the LBANN drivers
add_subdirectory(src/drivers)
# Add the rest of the things
add_subdirectory(data_utils)
add_subdirectory(model_zoo)
add_subdirectory(model_zoo/tests)
add_subdirectory(model_zoo/jag_utils)
add_subdirectory(applications/CANDLE/pilot2/tools)
add_subdirectory(applications/ATOM/utils)
add_subdirectory(tests)
add_subdirectory(scripts)
################################################################
# Install LBANN
################################################################
include(CMakePackageConfigHelpers)
# Write the version file. This is independent of build/install tree.
write_basic_package_version_file(
LBANNConfigVersion.cmake
VERSION "${LBANN_VERSION}"
COMPATIBILITY SameMajorVersion)
# This is for the build tree
set(INCLUDE_INSTALL_DIRS "${CMAKE_SOURCE_DIR}/include"
"${CMAKE_SOURCE_DIR}/include"
"${CMAKE_SOURCE_DIR}/include/lbann"
"${CMAKE_BINARY_DIR}/include/lbann")
set(LIB_INSTALL_DIR "${CMAKE_BINARY_DIR}")
set(EXTRA_CMAKE_MODULE_DIR "${CMAKE_SOURCE_DIR}/cmake/modules")
configure_package_config_file(cmake/configure_files/LBANNConfig.cmake.in
"${CMAKE_BINARY_DIR}/LBANNConfig.cmake"
INSTALL_DESTINATION "${CMAKE_BINARY_DIR}"
PATH_VARS INCLUDE_INSTALL_DIRS LIB_INSTALL_DIR)
# Build tree export
export(EXPORT LBANNTargets NAMESPACE LBANN:: FILE LBANNTargets.cmake)
# Write the configure file for the install tree
set(INCLUDE_INSTALL_DIRS include)
set(LIB_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR})
set(CMAKE_INSTALL_DIR ${LIB_INSTALL_DIR}/cmake/lbann)
set(EXTRA_CMAKE_MODULE_DIR)
configure_package_config_file(cmake/configure_files/LBANNConfig.cmake.in
"${CMAKE_BINARY_DIR}/LBANNConfig.cmake.install"
INSTALL_DESTINATION "${CMAKE_INSTALL_DIR}"
PATH_VARS INCLUDE_INSTALL_DIRS LIB_INSTALL_DIR)
# Clang format
include(LBANNClangFormat)
if (CLANG_FORMAT_AVAILABLE)
add_clang_format(lbann)
endif ()
# Install library
install(
TARGETS lbann
EXPORT LBANNTargets
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)
# Install export
install(EXPORT LBANNTargets
NAMESPACE LBANN::
DESTINATION "${CMAKE_INSTALL_DIR}")
# Install the cmake stuff
install(FILES
"${PROJECT_BINARY_DIR}/LBANNConfig.cmake.install"
DESTINATION "${CMAKE_INSTALL_DIR}"
RENAME "LBANNConfig.cmake")
install(FILES "${PROJECT_BINARY_DIR}/LBANNConfigVersion.cmake"
DESTINATION ${CMAKE_INSTALL_DIR})
install(DIRECTORY cmake/modules
DESTINATION "${CMAKE_INSTALL_DIR}"
FILES_MATCHING PATTERN "*.cmake")
# Install header files
install(
DIRECTORY "${PROJECT_SOURCE_DIR}/include/lbann"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
FILES_MATCHING PATTERN "*.h" PATTERN "*.hpp")
install(
FILES "${PROJECT_BINARY_DIR}/lbann_config.hpp"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")