-
Notifications
You must be signed in to change notification settings - Fork 139
/
CMakeLists.txt
1172 lines (1045 loc) · 47 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
######################################################################
# CMake version and policies
######################################################################
cmake_minimum_required(VERSION 3.21.0)
# Note that cmake_minimum_required affects policy defaults.
# All policies known to the running version of CMake and introduced in
# cmake_minimum_required version or earlier will be set to use NEW behavior
if(POLICY CMP0127)
cmake_policy(SET CMP0127 NEW) # Condition evaluation v3.22+ https://cmake.org/cmake/help/latest/policy/CMP0127.html
endif()
if(POLICY CMP0144)
cmake_policy(SET CMP0144 NEW) # v3.27+ find_package() uses upper-case <PACKAGENAME>_ROOT variables.
endif()
######################################################################
# QMCPACK project
######################################################################
project(
qmcpack
VERSION 3.17.9
LANGUAGES C CXX)
# add the automatically determined parts of the RPATH
# which point to directories outside the build tree to the install RPATH
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
#--------------------------------------------------------------------
# Directory where customize cmake files reside
#--------------------------------------------------------------------
set(PROJECT_CMAKE ${qmcpack_SOURCE_DIR}/CMake)
list(APPEND CMAKE_MODULE_PATH ${PROJECT_CMAKE})
include(macros)
######################################################################
# Build and install options
######################################################################
#--------------------------------------------------------------------
# Set C++ standard
#--------------------------------------------------------------------
set(QMC_CXX_STANDARD
17
CACHE STRING "QMCPACK C++ language standard")
if(NOT QMC_CXX_STANDARD EQUAL 17)
message(WARNING "C++17 is the only language standard officially supported by this QMCPACK version. "
"Using other versions of the C++ standard is unsupported and done entirely at user's own risk.")
endif()
#--------------------------------------------------------------------
# Programmind model related build options
# MPI, OpenMP, GPU acceleration
#--------------------------------------------------------------------
include(CMakeDependentOption)
option(QMC_MPI "Enable/disable MPI" ON)
option(QMC_OMP "Enable/disable OpenMP" ON)
option(QMC_COMPLEX "Build for complex binary" OFF)
option(ENABLE_CUDA "Build with GPU support through CUDA" OFF)
option(QMC_CUDA2HIP "Map all CUDA kernels and library calls to HIP" OFF)
if(QMC_CUDA2HIP OR ENABLE_HIP)
set(ENABLE_ROCM ON) # option(ENABLE_ROCM) will be no-op
endif()
# explicit HIP source codes only exist in AFQMC.
option(ENABLE_HIP "Build with with GPU support through explicit HIP source code" OFF)
option(ENABLE_ROCM "Build with with GPU support through ROCM libraries" OFF)
option(ENABLE_OFFLOAD "Enable OpenMP offload" OFF)
option(ENABLE_SYCL "Enable SYCL offload" OFF)
# Use CMake object library targets to workaround clang linker not being able to handle fat
# binary archives which contain both host and device codes, for example OpenMP offload regions.
# CMake does not propagate indirect object files by design.
# So the dependency must be explicitly specified with USE_OBJECT_TARGET.
cmake_dependent_option(USE_OBJECT_TARGET "Use CMake object library target" OFF "ENABLE_OFFLOAD" OFF)
if(QMC_CUDA)
message(
FATAL_ERROR
"Legacy GPU implementation using CUDA has been removed! QMC_CUDA cannot be set ON. "
"For NVIDIA GPU support use ENABLE_OFFLOAD with ENABLE_CUDA. Use v3.16.0 or earlier if you need QMC_CUDA.")
endif(QMC_CUDA)
if(ENABLE_CUDA AND ENABLE_SYCL)
message(FATAL_ERROR "ENABLE_CUDA=ON and ENABLE_SYCL=ON can not be set together!")
endif(ENABLE_CUDA AND ENABLE_SYCL)
if(ENABLE_CUDA)
if(QMC_CUDA2HIP)
message(STATUS "ENABLE_CUDA enabled, QMC_CUDA2HIP enabled")
else(QMC_CUDA2HIP)
message(STATUS "ENABLE_CUDA enabled, QMC_CUDA2HIP disabled")
endif()
else(ENABLE_CUDA)
if(QMC_CUDA2HIP)
message(FATAL_ERROR "QMC_CUDA2HIP requires ENABLE_CUDA=ON.")
endif()
message(STATUS "ENABLE_CUDA disabled")
endif(ENABLE_CUDA)
# stop CUDA_ARCH
if(ENABLE_CUDA AND NOT QMC_CUDA2HIP)
if(DEFINED CUDA_ARCH)
unset(CUDA_ARCH CACHE)
message(
FATAL_ERROR "CUDA_ARCH option has been removed. Use -DCMAKE_CUDA_ARCHITECTURES=80 if -DCUDA_ARCH=sm_80 was used.")
endif()
endif()
include(DetermineDeviceArchitectures)
message(STATUS "GPU device architectures: ${QMC_GPU_ARCHS}")
#--------------------------------------------------------------------
# Set compiler-time parameters
# WALKER_MAX_PROPERTIES max number of observables + 12 or so standard
# properties. Properties such forces are per particle so you may need this
# to be rather large. Each property increases walker size by
# sizeof(FULLPRECREALTYPE)
# OHMMS_DIM = dimension of the problem
# OHMMS_INDEXTYPE = type of index
# OHMMS_PRECISION = base precision, float, double etc
# OHMMS_PRECISION_FULL = full precision, double etc
#--------------------------------------------------------------------
set(WALKER_MAX_PROPERTIES
2048
CACHE STRING "Maximum number of properties tracked by walkers")
mark_as_advanced(WALKER_MAX_PROPERTIES)
set(OHMMS_DIM
3
CACHE STRING "Select physical dimension")
set(OHMMS_INDEXTYPE int)
set(OHMMS_PRECISION_FULL double)
if(QMC_VERBOSE_CONFIGURATION)
message(WARNING "QMC_VERBOSE_CONFIGURATION option has been removed. Use --log-level=VERBOSE cmake option instead.")
endif()
#--------------------------------------------------------------------
message(STATUS "Defining the float point precision")
#--------------------------------------------------------------------
option(QMC_MIXED_PRECISION "Enable/disable mixed precision" OFF)
if(QMC_MIXED_PRECISION)
set(OHMMS_PRECISION float)
set(MIXED_PRECISION ON)
else(QMC_MIXED_PRECISION)
set(OHMMS_PRECISION double)
endif(QMC_MIXED_PRECISION)
message(" Base precision = ${OHMMS_PRECISION}")
message(" Full precision = ${OHMMS_PRECISION_FULL}")
#--------------------------------------------------------------------
# Set debug printout
# DEBUG_PSIBUFFER_ON keep track buffer's locator
#--------------------------------------------------------------------
option(PRINT_DEBUG "Enable/disable debug printing" OFF)
option(DEBUG_PSIBUFFER_ON "Debug messages for PSIBUFFER locator" OFF)
mark_as_advanced(DEBUG_PSIBUFFER_ON)
option(DEBUG_PER_STEP_ACCEPT_REJECT "Print accepts and rejects at each step" OFF)
mark_as_advanced(DEBUG_PER_STEP_ACCEPT_REJECT)
#--------------------------------------------------------------------
# Set build feature options
#--------------------------------------------------------------------
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_TOOLCHAIN_FILE)
set(CMAKE_BUILD_TYPE Release)
endif()
string(TOUPPER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE)
message(STATUS "CMAKE_BUILD_TYPE is ${CMAKE_BUILD_TYPE}")
option(QMC_BUILD_SANDBOX_ONLY "Build only applications in Sandbox directory" OFF)
option(ENABLE_GCOV "Enable code coverage" OFF)
option(BUILD_UNIT_TESTS "Build unit tests" ON)
option(BUILD_MICRO_BENCHMARKS "Build micro benchmarks" ON)
option(BUILD_LMYENGINE_INTERFACE "Build LMY engine" ON)
if(MIXED_PRECISION AND BUILD_LMYENGINE_INTERFACE)
message(STATUS "LMY engine is not compatible with CPU mixed precision build! Disabling LMY engine")
set(BUILD_LMYENGINE_INTERFACE OFF)
endif()
option(BUILD_AFQMC "Build with AFQMC" OFF)
option(BUILD_AFQMC_WITH_NCCL "Build AFQMC with NCCL library." OFF)
# AFQMC requires MPI.
if(BUILD_AFQMC AND NOT QMC_MPI)
message(FATAL_ERROR "AFQMC requires building with MPI (QMC_MPI=1). Set BUILD_AFQMC=0 or configure MPI.")
endif()
option(QMC_BUILD_STATIC "Link to static libraries" OFF)
option(ENABLE_TIMERS "Enable internal timers" ON)
option(ENABLE_STACKTRACE "Enable use of boost::stacktrace" OFF)
option(USE_VTUNE_API "Enable use of VTune ittnotify APIs" OFF)
cmake_dependent_option(USE_VTUNE_TASKS "USE VTune ittnotify task annotation" OFF "ENABLE_TIMERS AND USE_VTUNE_API" OFF)
# CMake note - complex conditionals in cmake_dependent_option must have spaces around parentheses
cmake_dependent_option(USE_NVTX_API "Enable/disable NVTX regions in CUDA code." OFF "ENABLE_TIMERS AND ENABLE_CUDA" OFF)
set(HAVE_EINSPLINE 1) # to be removed
option(QMC_EXP_THREADING "Experimental non openmp threading models" OFF)
mark_as_advanced(QMC_EXP_THREADING)
#--------------------------------------------------------------------
# Sanitizer options
#--------------------------------------------------------------------
# Add optional sanitizers ASAN, UBSAN, MSAN
set(VALID_SANITIZERS "none" "asan" "ubsan" "tsan" "msan")
set(ENABLE_SANITIZER
"none"
CACHE STRING "none,asan,ubsan,tsan,msan")
set_property(CACHE ENABLE_SANITIZER PROPERTY STRINGS ${VALID_SANITIZERS})
# Perform sanitizer option check, only works in debug mode
if(NOT ENABLE_SANITIZER IN_LIST VALID_SANITIZERS)
message(FATAL_ERROR "Invalid -DENABLE_SANITIZER=${ENABLE_SANITIZER}, value must be one of ${VALID_SANITIZERS}")
else()
message(STATUS "Enable sanitizer ENABLE_SANITIZER=${ENABLE_SANITIZER}")
endif()
#--------------------------------------------------------------------
# INSTALL_NEXUS install Nexus alongside QMCPACK
#--------------------------------------------------------------------
option(INSTALL_NEXUS "Install Nexus alongside QMCPACK" ON)
if(INSTALL_NEXUS)
install(
CODE "EXECUTE_PROCESS(COMMAND ${qmcpack_SOURCE_DIR}/nexus/install --leave_paths \$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/bin)"
)
endif()
######################################################################
# Set compiler specific options/flags
######################################################################
#-------------------------------------------------------------------------------
# Check for OpenMP compiler support
#
# The CMake OpenMP package is *only* used to to verify compiler support.
# No feature of the package is used and we customize OpenMP options directly
# on a per vendor/compiler basis.
#-------------------------------------------------------------------------------
if(QMC_OMP)
find_package(OpenMP)
if(NOT OpenMP_FOUND)
message(
FATAL_ERROR "No compiler support for OpenMP found. Switching to a compiler with OpenMP support is recommended."
"Alternatively, you will need to run CMake configure with -DQMC_OMP=OFF")
endif()
# explicitly set OpenMP runtime library rpath like other normal libraries.
list(GET OpenMP_CXX_LIBRARIES 0 OpenMP_LIBRARY_FILE)
if(OpenMP_LIBRARY_FILE)
cmake_path(GET OpenMP_LIBRARY_FILE PARENT_PATH OpenMP_LIBRARY_DIR)
list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES ${OpenMP_LIBRARY_DIR} isSystemDir)
if("${isSystemDir}" STREQUAL "-1")
message(STATUS "Append OpenMP runtime library path ${OpenMP_LIBRARY_DIR}")
list(APPEND CMAKE_BUILD_RPATH ${OpenMP_LIBRARY_DIR})
list(APPEND CMAKE_INSTALL_RPATH ${OpenMP_LIBRARY_DIR})
endif("${isSystemDir}" STREQUAL "-1")
endif()
endif(QMC_OMP)
#-------------------------------------------------------------------------------
# Set vendor specific compiler options
#-------------------------------------------------------------------------------
include(TestCXXMainCompiles)
TestCXXMainCompiles("Before_Customization")
if(CMAKE_TOOLCHAIN_FILE)
message(STATUS "Using ${CMAKE_TOOLCHAIN_FILE} toolchain ")
else(CMAKE_TOOLCHAIN_FILE)
message(STATUS "Trying to figure out compiler options ....")
#------------------------
# On Cray's machine
#------------------------
get_filename_component(BASE_CXX_COMPILER_NAME ${CMAKE_CXX_COMPILER} NAME)
if($ENV{CRAYPE_VERSION} MATCHES "." AND NOT BASE_CXX_COMPILER_NAME STREQUAL "CC")
message(WARNING "Cray Programming Environment has been detected but C++ compiler wrapper CC is not used! "
"Please use cc/CC as the C/C++ compiler to ensure correct cross-compiling for the compute nodes "
"unless you understand cross-compiling and intend not to use Cray compiler wrappers.")
endif()
if(CMAKE_SYSTEM_NAME STREQUAL "CrayLinuxEnvironment")
message(STATUS "Running on a Cray machine.")
if(NOT $ENV{CRAYPE_LINK_TYPE} STREQUAL "dynamic")
message(WARNING "Cray Programming Environment uses static linking by default. "
"We prefer dynamic linking which makes library searching easier. "
"Setting environment variable CRAYPE_LINK_TYPE to \"dynamic\" enables dynamic linking.\n")
endif()
if(NOT DEFINED MPIEXEC_EXECUTABLE)
find_program(MPIEXEC_EXECUTABLE aprun)
if(NOT MPIEXEC_EXECUTABLE)
# For slurm use srun
find_program(MPIEXEC_EXECUTABLE srun)
endif(NOT MPIEXEC_EXECUTABLE)
endif()
else()
if($ENV{CRAYPE_VERSION} MATCHES "." AND BASE_CXX_COMPILER_NAME STREQUAL "CC")
message(
FATAL_ERROR
"Cray compiler wrapper detected. Empty the build folder and rerun cmake with -DCMAKE_SYSTEM_NAME=CrayLinuxEnvironment added."
)
endif()
endif()
include(inspectCompiler)
TestCXXMainCompiles("After_Customization")
endif(CMAKE_TOOLCHAIN_FILE)
if(NOT CMAKE_CXX_COMPILER_ID STREQUAL CMAKE_C_COMPILER_ID)
message(FATAL_ERROR "Mixing C and C++ compilers from different vendors is not permitted. Current "
"C compiler is ${CMAKE_C_COMPILER_ID} but C++ compiler is ${CMAKE_CXX_COMPILER_ID}.")
endif()
#-----------------------------------------------------------------------
# Set C++ minimum standard and run basic checks
#-----------------------------------------------------------------------
set(CMAKE_CXX_STANDARD ${QMC_CXX_STANDARD})
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# Check that a C++ compiler is compatible with the underlying libstdc++
include(Testlibstdc++)
# Check that a C++ standard library is configured properly
include(TestCxx17Library)
#-----------------------------------------------------------------------
# SETUP SANITIZERS FLAGS
#-----------------------------------------------------------------------
if(NOT "${ENABLE_SANITIZER}" STREQUAL "none")
if(NOT ${COMPILER} MATCHES "GNU" AND NOT ${COMPILER} MATCHES "Clang")
message(FATAL_ERROR "-DENABLE_SANITIZER=${ENABLE_SANITIZER} only works with GNU or Clang compilers")
endif()
if("${ENABLE_SANITIZER}" STREQUAL "asan")
set(CMAKE_CXX_FLAGS_SAN
"-fsanitize=address -fno-optimize-sibling-calls -fsanitize-address-use-after-scope -fno-omit-frame-pointer"
CACHE STRING "AddressSanitizer C++ compiler builds." FORCE)
elseif("${ENABLE_SANITIZER}" STREQUAL "ubsan")
set(CMAKE_CXX_FLAGS_SAN
"-fsanitize=undefined"
CACHE STRING "UndefinedBehaviorSanitizer C++ compiler builds." FORCE)
elseif("${ENABLE_SANITIZER}" STREQUAL "msan")
set(CMAKE_CXX_FLAGS_SAN
"-fsanitize=memory"
CACHE STRING "MemorySanitizer C++ compiler builds." FORCE)
elseif("${ENABLE_SANITIZER}" STREQUAL "tsan")
set(CMAKE_CXX_FLAGS_SAN
"-fsanitize=thread"
CACHE STRING "ThreadSanitizer C++ compiler builds." FORCE)
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_SAN}")
TestCXXMainCompiles("With_Sanitizers")
endif()
#-----------------------------------------------------------------------
# verify code coverage compiler support
#-----------------------------------------------------------------------
if(ENABLE_GCOV)
if(GCOV_SUPPORTED)
message(STATUS "GCOV is enabled")
else()
message(FATAL_ERROR "ENABLE_GCOV was specified but compiler does not support GCC coverage flag")
endif()
endif(ENABLE_GCOV)
#-------------------------------------------------------------------------------
# Check SIMD alignment for CPU only
#-------------------------------------------------------------------------------
# This is intentionally placed before adding OpenMP offload compile options
# to avoid contamination from device compilation pass.
# When '-march=skylake-avx512 -fopenmp-targets=nvptx64 -march=sm_70' is added
# for Clang, the source code is parsed twice for both host and offload targets.
# A trap for macro __AVX512F__ always fails because the offload pass doesn't
# carry '-march=skylake-avx512' but only takes '-march=sm_70'.
#-------------------------------------------------------------------------------
include(CheckSIMDAlignment)
set(QMC_SIMD_ALIGNMENT
${default_alignment}
CACHE STRING "Cache/SIMD alignment in bytes")
math(EXPR alignment_remainder "${QMC_SIMD_ALIGNMENT} % ${default_alignment}")
if(alignment_remainder)
message(
FATAL_ERROR
"QMC_SIMD_ALIGNMENT must be a multiple of ${default_alignment}. Bad cached value is ${QMC_SIMD_ALIGNMENT}")
endif()
message(STATUS "QMC_SIMD_ALIGNMENT is set to ${QMC_SIMD_ALIGNMENT}")
if(QMC_OMP)
#---------------------------------------------------------
# Determine if OpenMP taskloop works with the CXX compiler
#---------------------------------------------------------
include(TestOpenMPtaskloop)
option(ENABLE_OMP_TASKLOOP "Enable OpenMP taskloop" ${OMP_TASKLOOP_OKAY})
message(STATUS "ENABLE_OMP_TASKLOOP is set to ${ENABLE_OMP_TASKLOOP}")
#---------------------------------------------------------
# Set up OpenMP offload compile options
#---------------------------------------------------------
if(ENABLE_OFFLOAD AND DEFINED OPENMP_OFFLOAD_COMPILE_OPTIONS)
message(STATUS "OpenMP offload CXX flags: ${OPENMP_OFFLOAD_COMPILE_OPTIONS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OPENMP_OFFLOAD_COMPILE_OPTIONS}")
if(DEFINED OpenMP_OFFLOAD_LINKER_FLAGS)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_OFFLOAD_LINKER_FLAGS}")
endif()
endif()
TestCXXMainCompiles("With_OpenMP")
endif()
#-------------------------------------------------------------------------------------
# consider making this always on if OpenMP is no longer UB with Thread Support Library
# We should test out abstractions consistently and c++17 stdlib's all have support for
# std::thread and std::atomic
#-------------------------------------------------------------------------------------
if(QMC_EXP_THREADING)
include(CheckAtomic)
if(HAVE_LIBATOMIC)
link_libraries("${HAVE_LIBATOMIC}")
endif(HAVE_LIBATOMIC)
add_definitions(-DQMC_EXP_THREADING)
endif(QMC_EXP_THREADING)
######################################################################
# Check external libraries.
######################################################################
#-------------------------------------------------------------------
# Check MPI installation. MPI is treated as a library
#-------------------------------------------------------------------
if(QMC_MPI)
# for backward compatibility with MPIEXEC
if(DEFINED MPIEXEC AND NOT DEFINED MPIEXEC_EXECUTABLE)
message(
WARNING
"Setting MPIEXEC_EXECUTABLE based on MPIEXEC. MPIEXEC has been deprecated! Use MPIEXEC_EXECUTABLE instead!")
set(MPIEXEC_EXECUTABLE ${MPIEXEC})
endif(DEFINED MPIEXEC AND NOT DEFINED MPIEXEC_EXECUTABLE)
set(MPI_CXX_SKIP_MPICXX
TRUE
CACHE BOOL "Must be TRUE for QMCPACK. Cached for working around CMake FindMPI issue.")
if(NOT CMAKE_CROSSCOMPILING)
set(MPI_DETERMINE_LIBRARY_VERSION TRUE)
endif()
find_package(MPI COMPONENTS CXX)
if(NOT MPI_FOUND)
message(
FATAL_ERROR
"MPI support not found! Provide MPI compiler wrappers or build without MPI by passing '-DQMC_MPI=OFF' to cmake."
)
endif(NOT MPI_FOUND)
if(${MPI_CXX_LIBRARY_VERSION_STRING} MATCHES "MVAPICH2")
string(REGEX REPLACE "\n" ";" ONE_LINE "${MPI_CXX_LIBRARY_VERSION_STRING}")
string(REGEX REPLACE " +|\t" ";" ONE_LINE "${ONE_LINE}")
list(GET ONE_LINE 3 MVAPICH2_VERSION)
message(STATUS "MVAPICH2 version ${MVAPICH2_VERSION}")
if(${MVAPICH2_VERSION} VERSION_LESS "2.4" AND NOT ${MPI_CXX_LIBRARY_VERSION_STRING} MATCHES
"disable-registration-cache")
message(
FATAL_ERROR
"MVAPICH2 (version < 2.4) with registration cache enabled breaks QMCPACK. "
"Use a different MPI library or a MVAPICH2 >=2.4 "
"or build MVAPICH2 with --disable-registration-cache configure option.")
endif()
endif()
if(${MPI_CXX_LIBRARY_VERSION_STRING} MATCHES "Open MPI")
if(NOT MPIEXEC_PREFLAGS)
set(MPIEXEC_PREFLAGS "--bind-to;none")
message(STATUS "Detected Open MPI. Setting bind-to options for thread affinity in MPIEXEC_PREFLAGS.")
else(NOT MPIEXEC_PREFLAGS)
if(NOT "${MPIEXEC_PREFLAGS}" MATCHES "--bind-to")
message(
WARNING "Default Open MPI thread affinity policy may bind all the threads to a single core and "
"significantly slow down testing. Add proper --bind-to options via MPIEXEC_PREFLAGS. "
"If you don't know exactly what affinity to add, "
"add '--bind-to;none' to your current MPIEXEC_PREFLAGS to stop this warning.")
endif()
endif(NOT MPIEXEC_PREFLAGS)
endif()
if(NOT ${CMAKE_CXX_COMPILER} STREQUAL ${MPI_CXX_COMPILER})
set(MPI_WARNING_LIST
"Building MPI version without using MPI compiler wrappers.\n"
"This may not build qmcpack correctly. To ensure the correct version, specify the compiler wrappers to cmake.\n"
"For example: cmake -DCMAKE_C_COMPILER=mpicc -DCMAKE_CXX_COMPILER=mpic++\n"
"To build without MPI, pass '-DQMC_MPI=OFF' to cmake")
message(WARNING ${MPI_WARNING_LIST})
endif()
message(STATUS "MPI runner MPIEXEC_EXECUTABLE : ${MPIEXEC_EXECUTABLE}")
message(STATUS "MPIEXEC_NUMPROC_FLAG : ${MPIEXEC_NUMPROC_FLAG}")
message(STATUS "MPIEXEC_PREFLAGS : ${MPIEXEC_PREFLAGS}")
string(REPLACE ";" " " MPIEXEC_PREFLAGS_PRINT "${MPIEXEC_PREFLAGS}")
message(
STATUS "Tests run as : ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} NUM_PROCS ${MPIEXEC_PREFLAGS_PRINT} EXECUTABLE"
)
set(HAVE_MPI 1)
message(STATUS "MPI is enabled")
else(QMC_MPI)
set(HAVE_MPI 0)
message(STATUS "MPI is disabled")
endif(QMC_MPI)
#-------------------------------------------------------------------
# check OS related libraries
#-------------------------------------------------------------------
include(CheckFunctionExists)
check_function_exists(posix_memalign HAVE_POSIX_MEMALIGN)
#-------------------------------------------------------------------
# Check LAPACK/BLAS
#-------------------------------------------------------------------
# Add Math::BLAS_LAPACK target
add_library(Math::BLAS_LAPACK INTERFACE IMPORTED)
foreach(MKL_LIB_PATH IN ITEMS ${MKL_ROOT} $ENV{MKL_ROOT} $ENV{MKLROOT} $ENV{MKL_HOME})
set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} ${MKL_LIB_PATH}/lib/intel64)
endforeach()
if(NOT BLA_VENDOR)
message(STATUS "Trying to find LAPACK from Intel MKL")
if(QMC_OMP AND COMPILER STREQUAL "Intel")
set(BLA_VENDOR Intel10_64lp)
else()
set(BLA_VENDOR Intel10_64lp_seq)
endif()
find_package(LAPACK)
if(NOT LAPACK_FOUND)
message(STATUS "Intel MKL library files not found via FindLAPACK.")
message(STATUS "Trying to find alternative LAPACK libraries")
set(BLA_VENDOR All)
find_package(LAPACK REQUIRED)
endif()
else()
message(STATUS "Trying to find LAPACK library as requested BLA_VENDOR=${BLA_VENDOR}")
find_package(LAPACK REQUIRED)
endif()
message(STATUS "LAPACK linker flags: ${LAPACK_LINKER_FLAGS}")
message(STATUS "LAPACK libraries: ${LAPACK_LIBRARIES}")
target_link_libraries(Math::BLAS_LAPACK INTERFACE "${LAPACK_LINKER_FLAGS};${LAPACK_LIBRARIES}")
# Detects MKL header files and other components.
if(LAPACK_LIBRARIES MATCHES "mkl_core")
include(FindMKL)
endif()
if(MKL_FOUND)
target_link_libraries(Math::BLAS_LAPACK INTERFACE MKL::BLAS_LAPACK)
set(MATH_VENDOR_GUESS "INTEL_VML")
endif()
# AFQMC requires MKL sparse for good performance (roughly a factor of 2x)
if(BUILD_AFQMC AND NOT MKL_FOUND)
message(
WARNING
"AFQMC - MKL not found, using simple sparse matrix routines. Link with MKL sparse libraries for better performance."
)
endif()
#-------------------------------------------------------------------
# set up scalar/vector math libraries
#-------------------------------------------------------------------
add_library(Math::scalar_vector_functions INTERFACE IMPORTED)
set(VALID_MATH_VENDORS "GENERIC" "INTEL_VML" "IBM_MASS" "AMD_LIBM")
if(NOT DEFINED MATH_VENDOR_GUESS)
set(MATH_VENDOR_GUESS "GENERIC")
endif()
set(QMC_MATH_VENDOR
${MATH_VENDOR_GUESS}
CACHE STRING "Vendor optimized libraries for scalar and vector math functions")
# Perform math vendor option check
if(NOT QMC_MATH_VENDOR IN_LIST VALID_MATH_VENDORS)
message(FATAL_ERROR "Invalid vendor math library ${QMC_MATH_VENDOR}, value must be one of ${VALID_MATH_VENDORS}")
else()
message(STATUS "Selected vendor math library ${QMC_MATH_VENDOR}")
endif()
# This needs to go before HAVE_SINCOS
if(QMC_MATH_VENDOR STREQUAL "INTEL_VML")
include(FindMKLVML)
elseif(QMC_MATH_VENDOR STREQUAL "IBM_MASS")
include(FindIBMMASS)
elseif(QMC_MATH_VENDOR STREQUAL "AMD_LIBM")
include(FindAMDLibM)
endif()
# CheckSincos relies on SINCOS_INCLUDE which may be modified based on vendor libraries
if(NOT SINCOS_INCLUDE)
set(SINCOS_INCLUDE cmath)
endif(NOT SINCOS_INCLUDE)
message(STATUS "SINCOS_INCLUDE : ${SINCOS_INCLUDE}")
include(CheckSincos)
#-------------------------------------------------------------------
# set up FFTW3 library
#-------------------------------------------------------------------
add_library(Math::FFTW3 INTERFACE IMPORTED)
set(FFTW_FOUND 0)
if(HAVE_MKL)
if(HAVE_MKL_FFTW3)
set(FFTW_FOUND 1)
target_link_libraries(Math::FFTW3 INTERFACE MKL::FFTW3)
endif()
endif()
if(NOT FFTW_FOUND)
find_package(FFTW REQUIRED)
target_link_libraries(Math::FFTW3 INTERFACE FFTW::FFTW3)
endif()
set(HAVE_LIBFFTW 1)
target_compile_definitions(Math::FFTW3 INTERFACE "HAVE_LIBFFTW")
set(QMC_UTIL_LIBS ${QMC_UTIL_LIBS} ${FORTRAN_LIBRARIES})
#-------------------------------------------------------------------
# set up Libxml2 library
#-------------------------------------------------------------------
find_package(ZLIB)
find_package(LibXml2 REQUIRED)
#-------------------------------------------------------------------
# set up HDF5 library
#-------------------------------------------------------------------
if(HAVE_MPI)
option(HDF5_PREFER_PARALLEL "Request parallel/serial HDF5 library" ON)
else(HAVE_MPI)
option(HDF5_PREFER_PARALLEL "Request parallel/serial HDF5 library" OFF)
if(HDF5_PREFER_PARALLEL)
message(FATAL_ERROR "Parallel HDF5 library cannot be selected with QMCPACK non-MPI build. "
"Please set HDF5_PREFER_PARALLEL=0.")
endif(HDF5_PREFER_PARALLEL)
endif(HAVE_MPI)
if(QMC_BUILD_STATIC)
message(STATUS "Linking static HDF5 library")
set(HDF5_USE_STATIC_LIBRARIES on)
else()
message(STATUS "Linking dynamic HDF5 library")
set(HDF5_USE_STATIC_LIBRARIES off)
endif()
find_package(HDF5 COMPONENTS C) # Note: minimum version check is done below to bypass find_package
# and HDF5 version compatibility subtleties
if(HDF5_FOUND)
if(HDF5_VERSION)
if (HDF5_VERSION VERSION_LESS 1.10.0)
message(FATAL_ERROR "QMCPACK requires HDF5 version >= 1.10.0")
endif()
endif(HDF5_VERSION)
if(HDF5_IS_PARALLEL)
if(HAVE_MPI)
message(STATUS "Parallel HDF5 library found")
option(ENABLE_PHDF5 "Enable code paths using parallel HDF5" ON)
else(HAVE_MPI)
message(FATAL_ERROR "Parallel HDF5 library found but cannot be used with QMCPACK non-MPI build. "
"Please provide a serial HDF5 library or switch to building QMCPACK with MPI.")
endif(HAVE_MPI)
else(HDF5_IS_PARALLEL)
message(STATUS "Serial HDF5 library found")
option(ENABLE_PHDF5 "Enable code paths using parallel HDF5" OFF)
if(ENABLE_PHDF5)
if(HAVE_MPI)
message(FATAL_ERROR "Parallel HDF5 code paths requested but serial HDF5 library found! "
"Please either provide parallel HDF5 library or set ENABLE_PHDF5=0.")
else(HAVE_MPI)
message(FATAL_ERROR "Parallel HDF5 code paths cannot be enabled on non-MPI builds! Please set ENABLE_PHDF5=0.")
endif(HAVE_MPI)
endif(ENABLE_PHDF5)
endif(HDF5_IS_PARALLEL)
if(ENABLE_PHDF5)
message(STATUS "Using HDF5 parallel collective I/O code paths")
else(ENABLE_PHDF5)
message(STATUS "Using HDF5 non-scalable serial I/O code paths")
endif(ENABLE_PHDF5)
if(HAVE_MPI AND NOT ENABLE_PHDF5)
message(
WARNING
"MPI builds may have performance loss by not using parallel HDF5! (Safe to ignore for workstation builds).")
endif()
if(CMAKE_BUILD_TYPE AND HDF5_LIBRARIES_DEBUG)
if(CMAKE_BUILD_TYPE MATCHES DEBUG)
set(HDF5_LIBRARIES ${HDF5_LIBRARIES_DEBUG})
else()
set(HDF5_LIBRARIES ${HDF5_LIBRARIES_RELEASE})
endif()
endif()
add_library(IO::HDF5 INTERFACE IMPORTED)
target_include_directories(IO::HDF5 INTERFACE "${HDF5_INCLUDE_DIR}")
target_compile_definitions(IO::HDF5 INTERFACE "H5_USE_110_API")
target_link_libraries(IO::HDF5 INTERFACE "${HDF5_LIBRARIES}")
if(ENABLE_PHDF5)
target_compile_definitions(IO::HDF5 INTERFACE "ENABLE_PHDF5")
endif(ENABLE_PHDF5)
else(HDF5_FOUND)
message(FATAL_ERROR "HDF5 not found. Set HDF5_ROOT")
endif(HDF5_FOUND)
#-------------------------------------------------------------------
# set up libboost library, header only
#-------------------------------------------------------------------
if(CMAKE_VERSION VERSION_LESS 3.30.0)
set(Boost_NO_BOOST_CMAKE on)
find_package(Boost 1.61.0 REQUIRED)
else()
find_package(Boost 1.70.0 CONFIG REQUIRED headers)
endif()
if(Boost_FOUND)
target_compile_definitions(Boost::boost INTERFACE "HAVE_LIBBOOST")
message(STATUS "Setting Boost_INCLUDE_DIRS=${Boost_INCLUDE_DIRS}")
else()
message(FATAL_ERROR "Need boost 1.61.0 or higher. Set BOOST_ROOT")
endif()
#-------------------------------------------------------------------
# set up CUDA compiler options and libraries
#-------------------------------------------------------------------
set(HAVE_CUDA 0)
if(ENABLE_CUDA AND NOT QMC_CUDA2HIP)
if(NOT DEFINED CMAKE_CUDA_STANDARD)
set(CMAKE_CUDA_STANDARD 17)
endif()
set(CMAKE_CUDA_STANDARD_REQUIRED TRUE)
set(CMAKE_CUDA_EXTENSIONS OFF)
# CMAKE_CUDA_STANDARD doesn't affect nvcc detection and using unsupported compilers may choke the detection.
# This happens when Clang default to C++17. Setting CMAKE_CUDA_FLAGS directly works around the issue.
# but CUDA_FLAGS in flags.make may contain -std=c++17 twice with no harm.
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -std=c++${CMAKE_CUDA_STANDARD}")
set(CMAKE_CUDA_HOST_COMPILER
${CMAKE_CXX_COMPILER}
CACHE STRING "nvcc host compiler passed via -ccbin")
if(NOT CMAKE_CUDA_FLAGS MATCHES "allow-unsupported-compiler")
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} --allow-unsupported-compiler")
endif()
if(NOT DEFINED CMAKE_CUDA_ARCHITECTURES)
string(REPLACE "sm_" "" CUDA_ARCH_NUMBERS "${QMC_GPU_ARCHS}")
set(CMAKE_CUDA_ARCHITECTURES ${CUDA_ARCH_NUMBERS})
endif()
enable_language(CUDA)
if(ENABLE_CUDA)
include(TestCUDAHostCompatibility)
endif()
find_package(CUDAToolkit 11.0 REQUIRED)
if(NOT TARGET CUDA::cublas)
message(
FATAL_ERROR
"Found an incomplete CUDA toolkit installation, target CUDA::cublas not found. "
"This often happens when CMake failed in recognizing the NVHPC internal CUDA toolkit with libcublas. "
"Set CMAKE_CUDA_COMPILER to the full path of nvcc from a complete CUDA toolkit installation.")
endif()
# Automatically set the default NVCC flags
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Drestrict=__restrict__ -DNO_CUDA_MAIN")
if(QMC_COMPLEX)
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -DQMC_COMPLEX=${QMC_COMPLEX}")
endif()
set(HAVE_CUDA 1)
message("Project CUDA_FLAGS: ${CMAKE_CUDA_FLAGS}")
endif()
if(USE_NVTX_API AND NOT QMC_CUDA2HIP)
message(STATUS "Enabling use of CUDA NVTX APIs")
find_library(
NVTX_API_LIB NAME nvToolsExt
HINTS ${CUDA_TOOLKIT_ROOT_DIR}
PATH_SUFFIXES lib lib64)
if(NOT NVTX_API_LIB)
message(FATAL_ERROR "USE_NVTX_API set but NVTX_API_LIB not found")
endif(NOT NVTX_API_LIB)
message("CUDA nvToolsExt library: ${NVTX_API_LIB}")
link_libraries(${NVTX_API_LIB})
else()
message(STATUS "CUDA NVTX APIs disabled")
endif(USE_NVTX_API AND NOT QMC_CUDA2HIP)
#-------------------------------------------------------------------
# set up ROCM compiler options and libraries
#-------------------------------------------------------------------
if(ENABLE_ROCM)
enable_language(HIP)
set(CMAKE_HIP_LINKER_PREFERENCE_PROPAGATES 0)
if(DEFINED ROCM_ROOT)
message(STATUS "Using ROCM_ROOT: ${ROCM_ROOT}")
# explicit ROCM_ROOT takes precedence
list(PREPEND CMAKE_PREFIX_PATH ${ROCM_ROOT})
elseif(CMAKE_HIP_COMPILER_ROCM_ROOT)
list(PREPEND CMAKE_PREFIX_PATH ${CMAKE_HIP_COMPILER_ROCM_ROOT})
endif()
# use hip package to supply the hip runtime for CXX source code.
find_package(hip CONFIG)
if(NOT hip_FOUND)
message(
FATAL_ERROR
"The HIP runtime library cmake configure file hip-config.cmake cannot be found! "
"This happens when the ROCm installation cannot be found by CMake. "
"Rerun cmake with -DROCM_ROOT=<your ROCm installation root directory> added.")
endif()
find_package(hipblas CONFIG REQUIRED)
find_package(rocsolver CONFIG REQUIRED)
find_package(rocthrust CONFIG REQUIRED)
# architecture flags
if(DEFINED HIP_ARCH)
unset(HIP_ARCH CACHE)
message(
FATAL_ERROR
"HIP_ARCH option has been removed. Use -DCMAKE_HIP_ARCHITECTURES=gfx90a if -DHIP_ARCH=gfx90a was used.")
endif()
if(NOT DEFINED CMAKE_HIP_ARCHITECTURES)
set(CMAKE_HIP_ARCHITECTURES ${QMC_GPU_ARCHS})
endif()
set(CMAKE_HIP_FLAGS "${CMAKE_HIP_FLAGS} -fPIC -ffast-math --gpu-max-threads-per-block=256")
# warning suppression
set(CMAKE_HIP_FLAGS "${CMAKE_HIP_FLAGS} -Wno-vla -Wno-deprecated-declarations -Wno-unused-command-line-argument")
if(NOT DEFINED ROCM_ROOT)
list(PREPEND CMAKE_PREFIX_PATH ${CMAKE_HIP_COMPILER_ROCM_ROOT})
endif()
if(BUILD_AFQMC)
find_package(rocrand CONFIG REQUIRED)
# connect ROCm shipped libraries
add_library(ROCM::libraries INTERFACE IMPORTED)
# temporarily put rocsolver rocrand here for convenience, should be moved to Platforms.
target_link_libraries(ROCM::libraries INTERFACE roc::rocsolver roc::rocrand)
endif()
message("Project HIP_FLAGS: ${CMAKE_HIP_FLAGS}")
option(QMC_DISABLE_HIP_HOST_REGISTER "Disable hipHostRegister for pinning host memory" ON)
endif(ENABLE_ROCM)
if(USE_NVTX_API AND QMC_CUDA2HIP)
message(STATUS "Enabling use of ROCm rocTX APIs")
find_library(
ROCTX_API_LIB NAME libroctx64.so
PATH_SUFFIXES lib lib64)
if(NOT ROCTX_API_LIB)
message(FATAL_ERROR "USE_ROCTX_API set but ROCTX_API_LIB not found")
endif(NOT ROCTX_API_LIB)
message("ROCm rocTX library: ${ROCTX_API_LIB}")
link_libraries(${ROCTX_API_LIB})
else()
message(STATUS "ROCm rocTX APIs disabled")
endif(USE_NVTX_API AND QMC_CUDA2HIP)
#-------------------------------------------------------------------
# set up HIP compiler options
#-------------------------------------------------------------------
if(ENABLE_HIP)
if(NOT ENABLE_ROCM)
message(FATAL_ERROR "ROCM is required to use HIP. Please set ENABLE_ROCM=ON.")
endif()
find_package(hipsparse CONFIG REQUIRED)
add_library(HIP::HIP INTERFACE IMPORTED)
# temporarily put hipsparse hipblas here for convenience, should be moved to Platforms.
target_link_libraries(HIP::HIP INTERFACE roc::hipsparse roc::hipblas)
target_compile_definitions(HIP::HIP INTERFACE "ENABLE_HIP")
# FindHIP sets HIP_PLATFORM to amd or nvcc
message(STATUS "FindHIP determined HIP_PLATFORM is ${HIP_PLATFORM}.")
if(HIP_PLATFORM STREQUAL "amd")
target_compile_definitions(HIP::HIP INTERFACE "__HIP_PLATFORM_AMD__")
elseif(HIP_PLATFORM STREQUAL "nvcc")
target_compile_definitions(HIP::HIP INTERFACE "__HIP_PLATFORM_NVIDIA__")
else()
message(FATAL_ERROR "Unknown HIP platform ${HIP_PLATFORM} only support 'amd' or 'nvcc'")
endif()
endif(ENABLE_HIP)
#-------------------------------------------------------------------
# set up SYCL compiler options and libraries
#-------------------------------------------------------------------
if(ENABLE_SYCL)
if(NOT "x${CMAKE_CXX_COMPILER_ID}" STREQUAL "xIntelLLVM")
message(FATAL_ERROR "QMCPACK only supports SYCL with LLVM-based Intel oneAPI compiler (icpx).")
endif()
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 2023.0)
message(FATAL_ERROR "Requires Intel oneAPI 2023.0 or higher!")
endif()
add_library(SYCL::host INTERFACE IMPORTED)
add_library(SYCL::device INTERFACE IMPORTED)
find_package(
IntelDPCPP
REQUIRED
CONFIGS
IntelDPCPPConfig-modified.cmake
PATHS
${PROJECT_CMAKE}
NO_DEFAULT_PATH)
target_link_libraries(SYCL::host INTERFACE OneAPI::DPCPP-host)
target_link_libraries(SYCL::device INTERFACE OneAPI::DPCPP-device)
if(TARGET MKL::sycl)
target_link_libraries(MKL::sycl INTERFACE OneAPI::DPCPP-host)
endif()
endif(ENABLE_SYCL)
#--------------------------------------------------------------------
# Resolve Vendor(CUDA/HIP/SYCL) and OpenMP runtime incompatibilities
#--------------------------------------------------------------------
# Some OpenMP offload runtime libraries have composibility issue with vendor native ones.
# A workaround is making the vendor native runtime responsible for memory allocations and OpenMP associate/disassocate them.
set(QMC_OFFLOAD_MEM_ASSOCIATED_DEFAULT OFF)
if(ENABLE_OFFLOAD)
# Known issue HIP<5.5 https://github.com/ROCm/aomp/issues/253
message("check ${COMPILER} ${QMC_CUDA2HIP} ${hip_VERSION}")
if(${COMPILER} MATCHES "Clang" AND QMC_CUDA2HIP AND hip_VERSION VERSION_LESS "5.5")
set(QMC_OFFLOAD_MEM_ASSOCIATED_DEFAULT ON)
endif()
endif()
cmake_dependent_option(QMC_OFFLOAD_MEM_ASSOCIATED "Manage OpenMP memory allocations via the vendor runtime"
${QMC_OFFLOAD_MEM_ASSOCIATED_DEFAULT} "ENABLE_OFFLOAD;ENABLE_CUDA" OFF)
#-------------------------------------------------------------------
# set up VTune ittnotify library
#-------------------------------------------------------------------
if(USE_VTUNE_API)
message(STATUS "Enabling use of VTune ittnotify APIs")
find_path(
VTUNE_ITTNOTIFY_INCLUDE_DIR ittnotify.h
HINTS ${VTUNE_ROOT} $ENV{VTUNE_ROOT}
PATH_SUFFIXES include REQUIRED)
message(STATUS "Found VTUNE_ITTNOTIFY_INCLUDE_DIR ${VTUNE_ITTNOTIFY_INCLUDE_DIR}")
find_library(
VTUNE_ITTNOTIFY_LIBRARY ittnotify
HINTS ${VTUNE_ROOT} $ENV{VTUNE_ROOT}
PATH_SUFFIXES lib64 lib REQUIRED)
message(STATUS "Found VTUNE_ITTNOTIFY_LIBRARY ${VTUNE_ITTNOTIFY_LIBRARY}")
include_directories(${VTUNE_ITTNOTIFY_INCLUDE_DIR})
link_libraries(${VTUNE_ITTNOTIFY_LIBRARY})
if(USE_VTUNE_TASKS)
message(STATUS "VTune ittnotify tasks enabled")
endif()
else()
message(STATUS "VTune ittnotify APIs disabled")
endif()
#-------------------------------------------------------------------
# Add user extra flags
#-------------------------------------------------------------------
if(QMC_INCLUDE)
foreach(tmp ${QMC_INCLUDE})
message(STATUS "Adding '${tmp}' to include directories")
include_directories("${tmp}")
endforeach()
endif()
if(QMC_EXTRA_LIBS)
string(REPLACE " " ";" QMC_EXTRA_LIBS ${QMC_EXTRA_LIBS})
set(QMC_UTIL_LIBS ${QMC_UTIL_LIBS} ${QMC_EXTRA_LIBS})
message("QMC_UTIL_LIBS=${QMC_UTIL_LIBS}")
endif()
if(BUILD_AFQMC AND NOT APPLE)
link_libraries("rt")
endif()
######################################################################
# All the settings related to building QMCPACK are complete
######################################################################
#include build/src
include_directories(${qmcpack_BINARY_DIR}/src)
#include qmcpack/src
include_directories(${PROJECT_SOURCE_DIR}/src)
#-------------------------------------------------------------------
# add definitions DO NOT EXPAND
#-------------------------------------------------------------------
add_definitions(-DHAVE_CONFIG_H -DADD_)
#-------------------------------------------------------------------
# qmcpack.settings
#-------------------------------------------------------------------
execute_process(
COMMAND hostname
OUTPUT_VARIABLE QMC_HOSTNAME
OUTPUT_STRIP_TRAILING_WHITESPACE)
configure_file(${qmcpack_SOURCE_DIR}/src/qmcpack.settings ${qmcpack_BINARY_DIR}/bin/qmcpack.settings)
install(FILES ${qmcpack_BINARY_DIR}/bin/qmcpack.settings DESTINATION bin)
#-------------------------------------------------------------------
# FLAGS at the project level
#-------------------------------------------------------------------
#this might be redundant but maybe not in all CMake versions.
string(TOUPPER "${CMAKE_BUILD_TYPE}" THIS_CONFIG)
foreach(lang IN ITEMS C CXX)
set(PROJECT_CMAKE_${lang}_FLAGS ${CMAKE_${lang}_FLAGS})
#pre 3.0 cmake does not have string CONCAT
set(TMP_PROJECT_CMAKE_${lang}_FLAGS "${PROJECT_CMAKE_${lang}_FLAGS} ${CMAKE_${lang}_FLAGS_${THIS_CONFIG}}")
message("Project ${lang}_FLAGS: ${TMP_PROJECT_CMAKE_${lang}_FLAGS}")