forked from rraju1/cmake-buildscripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PMEMDCompilerFlags.cmake
325 lines (247 loc) · 10.2 KB
/
PMEMDCompilerFlags.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
#File which sets special compiler flags for PMEMD
#Often little configuration things are done in the subdir CMakeLists, but since the logic is so complicated I wanted to do this here in the root folder
#Configuration for Intel's MIC processors.
option(MIC "Build for Intel Many Integrated Core processors (Xeon Phi and Knight's Landing)." FALSE)
set(MIC_TYPE "PHI" CACHE STRING "Type of MIC to build. Options: PHI, PHI_OFFLOAD, KNIGHTS_LANDING, KNIGHTS_LANDING_SPDP. Only does anything if MIC is enabled.")
validate_configuration_enum(MIC_TYPE PHI PHI_OFFLOAD KNIGHTS_LANDING KNIGHTS_LANDING_SPDP)
#NOTE: in the configure script, MIC_PHI is called mic, and MIC_KL is called mic2
set(MIC_PHI FALSE)
set(MIC_KL FALSE)
if(MIC AND ${MIC_TYPE} MATCHES "PHI.*")
set(MIC_PHI TRUE)
elseif(MIC)
set(MIC_KL FALSE)
endif()
#-------------------------------------------------------------------------------
# Set default flags.
#-------------------------------------------------------------------------------
set(PMEMD_C_DEFINITIONS "")
set(PMEMD_F_DEFINITIONS "")
set(PMEMD_CFLAGS "")
set(PMEMD_FFLAGS "")
set(PMEMD_NO_OPT_CFLAGS -O0 -g)
set(PMEMD_NO_OPT_FFLAGS -O0 -g)
set(PMEMD_NO_OPT_CXXFLAGS -O0 -g)
set(EMIL_MIC_DEFS "")
set(EMIL_MIC_FLAGS "")
#-------------------------------------------------------------------------------
# CUDA precisions
# For each value in theis variable, the CUDA code will be built again with use_<value> defined,
# and a new pmemd.<value> executable will be created
#-------------------------------------------------------------------------------
set(PMEMD_CUDA_PRECISIONS SPFP DPFP SPXP)
#precision of pmemd which gets installed as pmemd.cuda
set(PMEMD_DEFAULT_PRECISION SPFP)
#-------------------------------------------------------------------------------
# Optimization flag configuration
#-------------------------------------------------------------------------------
if(${CMAKE_C_COMPILER_ID} STREQUAL "Intel")
if(MIC_PHI AND ${CMAKE_C_COMPILER_ID} VERSION_LESS 12)
message(FATAL_ERROR "Building for Xeon Phi requires Intel Compiler Suite v12 or later.")
endif()
# RCW Removed 10/5/2010 - Causes issues building in parallel since -fast always implies -static.
#pmemd_foptflags='-fast'
#pmemd_coptflags='-fast'
# BPR: Note: -fast implies the use of these flags:
#
# Intel 11
# --------
# Mac: -ipo -O3 -mdynamic-no-pic -no-prec-div -static -xHost
# IA-64 Linux: -ipo -O3 -static
# IA-32/Intel-64 Linux: -ipo -O3 -no-prec-div -static -xHost
#
# Intel 10
# --------
# Mac: -ipo -O3 -mdynamic-no-pic -no-prec-div -static -xP (ifort),
# -ipo -O3 -mdynamic-no-pic -no-prec-div (icc)
# IA-64 Linux: -ipo -O3 -static
# IA-32/Intel-64 Linux: -ipo -O3 -no-prec-div -static -xP
if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
set(PMEMD_CFLAGS -O3 -mdynamic-no-pic -no-prec-div)
# -ipo (multi-file Interprocedural Optimizations optimizations) causes issues with
# CUDA c code linking. Leave at a single-file IPO for the moment MJW
if(CUDA)
list(APPEND PMEMD_CFLAGS -ip)
else()
list(APPEND PMEMD_CFLAGS -ipo)
endif()
if(${CMAKE_C_COMPILER_VERSION} VERSION_GREATER 11 OR ${CMAKE_C_COMPILER_VERSION} VERSION_EQUAL 11)
list(APPEND PMEMD_CFLAGS -xHost)
endif()
else()
set(PMEMD_CFLAGS -ip -O3 -no-prec-div)
if(MIC AND (${MIC_TYPE} STREQUAL "PHI_OFFLOAD"))
list(APPEND PMEMD_CFLAGS -xHost)
elseif(NOT MIC_PHI)
if(${CMAKE_C_COMPILER_VERSION} VERSION_GREATER 11 OR ${CMAKE_C_COMPILER_VERSION} VERSION_EQUAL 11)
if(SSE)
if(NOT "${SSE_TYPES}" STREQUAL "")
list(APPEND PMEMD_CFLAGS "-ax${SSE_TYPES}")
else()
list(APPEND PMEMD_CFLAGS -xHost)
endif()
endif()
else()
if(SSE)
list(APPEND PMEMD_CFLAGS -axSTPW)
endif()
endif()
endif()
endif()
if(MIC_PHI)
list(APPEND PMEMD_CFLAGS -mmic)
elseif(MIC_KL)
if(INTELMPI AND OPENMP)
list(APPEND PMEMD_C_DEFINITIONS MIC2)
if(${CMAKE_C_COMPILER_VERSION} VERSION_GREATER 12 AND ${CMAKE_C_COMPILER_VERSION} VERSION_LESS 16)
list(APPEND PMEMD_CFLAGS -openmp-simd)
else()
list(APPEND PMEMD_CFLAGS -qopenmp-simd)
endif()
if(${MIC_TYPE} STREQUAL "KNIGHTS_LANDING_SPDP")
list(APPEND PMEMD_C_DEFINITIONS pmemd_SPDP)
if(NOT mkl_ENABLED)
message(FATAL_ERROR "Cannot use KNIGHTS_LANDING_SPDP optimizations without Intel MPI, Intel OpenMP, and Intel MKL on. Please enable it, or turn off SPDP!")
endif()
else()
list(APPEND PMEMD_C_DEFINITIONS pmemd_DPDP)
endif()
else()
message(FATAL_ERROR "Cannot use MIC2 optimizations without Intel MPI & OpenMP on. Pleas pass -DOPENMP=TRUE -DMPI=TRUE and provide an intel MPI library.")
endif()
endif()
if(MIC_PHI AND (${MIC_TYPE} STREQUAL "PHI_OFFLOAD"))
list(APPEND PMEMD_C_DEFINITIONS MIC_offload)
list(APPEND PMEMD_CFLAGS -opt-streaming-cache-evict=0 -fimf-domain-exclusion=15)
endif()
else()
#use regular compiler optimization flags
set(PMEMD_CFLAGS ${OPT_CFLAGS})
endif()
#Fortran
#---------------------------------------------------------------------------------------------------------------------------------------------------------------------
#this tree mirrors the C tree very closely, with only minor differences
if("${CMAKE_Fortran_COMPILER_ID}" STREQUAL "Intel")
if(MIC_PHI AND "${CMAKE_Fortran_COMPILER_VERSION}" VERSION_LESS 12)
message(FATAL_ERROR "Building for Xeon Phi requires Intel Compiler Suite v12 or later.")
endif()
if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
set(PMEMD_FFLAGS -O3 -mdynamic-no-pic -no-prec-div)
# -ipo (multi-file Interprocedural Optimizations optimizations) causes issues with
# CUDA c code linking. Leave at a single-file IPO for the moment MJW
if(CUDA)
list(APPEND PMEMD_FFLAGS -ip)
else()
list(APPEND PMEMD_FFLAGS -ipo)
endif()
if("${CMAKE_Fortran_COMPILER_VERSION}" VERSION_GREATER 11 OR ${CMAKE_Fortran_COMPILER_VERSION} VERSION_EQUAL 11)
list(APPEND PMEMD_FFLAGS -xHost)
endif()
else()
set(PMEMD_FFLAGS -ip -O3 -no-prec-div)
if(MIC AND (${MIC_TYPE} STREQUAL "PHI_OFFLOAD"))
list(APPEND PMEMD_FFLAGS -xHost)
elseif(NOT MIC_PHI)
if("${CMAKE_Fortran_COMPILER_VERSION}" VERSION_GREATER 11 OR ${CMAKE_Fortran_COMPILER_VERSION} VERSION_EQUAL 11)
if(SSE)
if(NOT "${SSE_TYPES}" STREQUAL "")
list(APPEND PMEMD_FFLAGS "-ax${SSE_TYPES}")
else()
list(APPEND PMEMD_FFLAGS -xHost)
endif()
endif()
else()
if(SSE)
list(APPEND PMEMD_FFLAGS -axSTPW)
endif()
endif()
endif()
endif()
if(MIC_PHI)
list(APPEND PMEMD_FFLAGS -mmic)
elseif(MIC_KL)
if(INTELMPI AND OPENMP)
list(APPEND PMEMD_F_DEFINITIONS MIC2)
if("${CMAKE_Fortran_COMPILER_VERSION}" VERSION_GREATER 12 AND ${CMAKE_Fortran_COMPILER_VERSION} VERSION_LESS 16)
list(APPEND PMEMD_FFLAGS -openmp-simd)
else()
list(APPEND PMEMD_FFLAGS -qopenmp-simd)
endif()
if(${MIC_TYPE} STREQUAL "KNIGHTS_LANDING_SPDP")
list(APPEND PMEMD_F_DEFINITIONS pmemd_SPDP faster_MIC2)
if(NOT mkl_ENABLED)
message(FATAL_ERROR "Cannot use KNIGHTS_LANDING_SPDP optimizations without Intel MPI, Intel OpenMP, and Intel MKL on. Please enable it, or turn off SPDP!")
endif()
else()
list(APPEND PMEMD_F_DEFINITIONS pmemd_DPDP)
endif()
else()
message(FATAL_ERROR "Cannot use MIC2 optimizations without Intel MPI & OpenMP on. Please pass -DOPENMP=TRUE -DMPI=TRUE and provide an intel MPI library.")
endif()
endif()
if(MIC_PHI AND (${MIC_TYPE} STREQUAL "PHI_OFFLOAD"))
list(APPEND PMEMD_F_DEFINITIONS MIC_offload)
list(APPEND PMEMD_FFLAGS -opt-streaming-cache-evict=0 -fimf-domain-exclusion=15 -align array64byte)
endif()
elseif("${CMAKE_Fortran_COMPILER_ID}" STREQUAL PGI)
set(PMEMD_FFLAGS -O4 -fastsse -Munroll -Mnoframe -Mscalarsse -Mvect=sse -Mcache_align)
else()
#use regular compiler flags
set(PMEMD_FFLAGS ${OPT_FFLAGS})
endif()
#C++
#---------------------------------------------------------------------------------------------------------------------------------------------------------------------
#Configure EMIL CXXFLAGS
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
if(MIC_PHI AND ${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 12)
message(FATAL_ERROR "Building for Xeon Phi requires Intel Compiler Suite v12 or later.")
endif()
if(MIC)
list(APPEND EMIL_MIC_FLAGS -mmic)
if(MIC_PHI AND (${MIC_TYPE} STREQUAL "PHI_OFFLOAD"))
list(APPEND EMIL_MIC_DEFS MIC_offload)
list(APPEND EMIL_MIC_FLAGS -opt-streaming-cache-evict=0 -fimf-domain-exclusion=15)
endif()
endif()
endif()
if("${CMAKE_Fortran_COMPILER_ID}" STREQUAL "GNU" AND "${CMAKE_Fortran_COMPILER_VERSION}" VERSION_EQUAL 5)
# compile pmemd prmtop_dat at lower optimization for buggy gnu 5.x: see bug 303.
set(PMEMD_GNU_BUG_303 TRUE)
else()
set(PMEMD_GNU_BUG_303 FALSE)
endif()
# use debugging flags in debug configuration
if(NOT OPTIMIZE)
set(PMEMD_CFLAGS ${PMEMD_NO_OPT_CFLAGS})
set(PMEMD_FFLAGS ${PMEMD_NO_OPT_FFLAGS})
endif()
# create non-list versions for PROPERTY COMPILE_FLAGS
list_to_space_separated(PMEMD_CFLAGS_SPC ${PMEMD_CFLAGS})
list_to_space_separated(PMEMD_FFLAGS_SPC ${PMEMD_FFLAGS})
#-------------------------------------------------------------------------------
# CUDA configuration
#-------------------------------------------------------------------------------
option(GTI "Use GTI version of pmemd.cuda instead of AFE version" TRUE)
if(CUDA)
set(PMEMD_NVCC_FLAGS -use_fast_math -O3)
set(PMEMD_CUDA_DEFINES -DCUDA)
if(GTI)
list(APPEND PMEMD_CUDA_DEFINES -DGTI)
message(STATUS "Building the GTI version of pmemd.cuda")
else()
message(STATUS "Building the AFE version of pmemd.cuda")
endif()
list(APPEND PMEMD_NVCC_FLAGS -rdc=true --std c++11)
if(MPI)
list(APPEND PMEMD_NVCC_FLAGS -DMPICH_IGNORE_CXX_SEEK)
endif()
endif()
#-------------------------------------------------------------------------------
# MKL configuration
#-------------------------------------------------------------------------------
# tell PMEMD to use MKL if it's installed
if(mkl_ENABLED)
list(APPEND PMEMD_F_DEFINITIONS FFTW_FFT MKL_FFTW_FFT)
else()
list(APPEND PMEMD_F_DEFINITIONS PUBFFT)
endif()