Move the PmePPCommGpu initialization from forcerec to runner
[alexxy/gromacs.git] / admin / builds / gromacs.py
1 #
2 # This file is part of the GROMACS molecular simulation package.
3 #
4 # Copyright (c) 2015,2016,2017,2018,2019,2020, by the GROMACS development team.
5 # Copyright (c) 2020, by the GROMACS development team, led by
6 # Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
7 # and including many others, as listed in the AUTHORS file in the
8 # top-level source directory and at http://www.gromacs.org.
9 #
10 # GROMACS is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU Lesser General Public License
12 # as published by the Free Software Foundation; either version 2.1
13 # of the License, or (at your option) any later version.
14 #
15 # GROMACS is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 # Lesser General Public License for more details.
19 #
20 # You should have received a copy of the GNU Lesser General Public
21 # License along with GROMACS; if not, see
22 # http://www.gnu.org/licenses, or write to the Free Software Foundation,
23 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
24 #
25 # If you want to redistribute modifications to GROMACS, please
26 # consider that scientific software is very special. Version
27 # control is crucial - bugs must be traceable. We will be happy to
28 # consider code for inclusion in the official distribution, but
29 # derived work must not be called official GROMACS. Details are found
30 # in the README & COPYING files - if they are missing, get the
31 # official version at http://www.gromacs.org.
32 #
33 # To help us fund GROMACS development, we humbly ask that you cite
34 # the research papers on the package. Check out http://www.gromacs.org.
35
36 import os.path
37
38 # Policy global variables
39 use_stdlib_through_env_vars = False
40
41 # These are accessible later in the script, just like other declared
42 # options, via e.g. context.opts.release.  Keep these in alphabetical
43 # order for more convenient rebasing
44 extra_options = {
45     'asan': Option.simple,
46     'buildfftw': Option.simple,
47     'clang_cuda': Option.bool,
48     'double': Option.simple,
49     'fftpack': Option.simple,
50     'gpu_id': Option.string,
51     'hwloc': Option.bool,
52     'mdrun-only': Option.simple,
53     'mkl': Option.simple,
54     'mpiinplace': Option.bool,
55     'npme': Option.string,
56     'nranks': Option.string,
57     'openmp': Option.bool,
58     'reference': Option.simple,
59     'release': Option.simple,
60     'release-with-assert': Option.simple,
61     'release-with-debug-info': Option.simple,
62     'static': Option.simple,
63     'thread-mpi': Option.bool,
64     'tng' : Option.bool,
65     # The following options cater for testing code in Jenkins that is
66     # currently behind feature flags in master branch.
67     'gpubufferops' : Option.bool,
68     'gpucomm': Option.bool,
69     'gpuupdate': Option.bool,
70 }
71
72 extra_projects = [Project.REGRESSIONTESTS]
73
74 def do_build(context):
75     cmake_opts = dict()
76     cmake_opts['GMX_COMPILER_WARNINGS'] = 'ON'
77     cmake_opts['GMX_DEFAULT_SUFFIX'] = 'OFF'
78     cmake_opts['CMAKE_BUILD_TYPE'] = 'Debug'
79     cmake_opts['GMX_USE_RDTSCP'] = 'DETECT'
80
81     if not context.opts.msvc and not context.opts.mdrun_only and not context.opts.static:
82         cmake_opts['GMXAPI'] = 'ON'
83
84     if context.opts.reference:
85         cmake_opts['CMAKE_BUILD_TYPE'] = 'Reference'
86     elif context.opts['release']:
87         cmake_opts['CMAKE_BUILD_TYPE'] = 'Release'
88     elif context.opts['release-with-assert']:
89         cmake_opts['CMAKE_BUILD_TYPE'] = 'RelWithAssert'
90     elif context.opts['release-with-debug-info']:
91         cmake_opts['CMAKE_BUILD_TYPE'] = 'RelWithDebInfo'
92     elif context.opts.asan:
93         cmake_opts['CMAKE_BUILD_TYPE'] = 'ASAN'
94     elif context.opts.tsan:
95         cmake_opts['CMAKE_BUILD_TYPE'] = 'TSAN'
96
97     if context.opts.static:
98         cmake_opts['BUILD_SHARED_LIBS'] = 'OFF'
99
100     if context.opts.phi:
101         cmake_opts['CMAKE_TOOLCHAIN_FILE'] = 'Platform/XeonPhi'
102
103     if context.opts.double:
104         cmake_opts['GMX_DOUBLE'] = 'ON'
105
106     if context.opts.simd is None:
107         cmake_opts['GMX_SIMD'] = 'None'
108     else:
109         cmake_opts['GMX_SIMD'] = context.opts.simd
110     if context.opts.cuda or context.opts.opencl:
111         cmake_opts['GMX_GPU'] = 'ON'
112         if context.opts.opencl:
113             context.env.set_env_var('CUDA_PATH', context.env.cuda_root)
114             cmake_opts['GMX_USE_OPENCL'] = 'ON'
115         else:
116             cmake_opts['CUDA_TOOLKIT_ROOT_DIR'] = context.env.cuda_root
117             if context.opts.clang_cuda:
118                 cmake_opts['GMX_CLANG_CUDA'] = 'ON'
119             else:
120                 cmake_opts['CUDA_HOST_COMPILER'] = context.env.cuda_host_compiler
121     else:
122         cmake_opts['GMX_GPU'] = 'OFF'
123     if context.opts.thread_mpi is False:
124         cmake_opts['GMX_THREAD_MPI'] = 'OFF'
125     if context.opts.mpi:
126         cmake_opts['GMX_MPI'] = 'ON'
127     if context.opts.mpiinplace is False:
128         cmake_opts['GMX_MPI_IN_PLACE'] = 'OFF'
129     if context.opts.openmp is False:
130         cmake_opts['GMX_OPENMP'] = 'OFF'
131     if context.opts.tng is False:
132         cmake_opts['GMX_USE_TNG'] = 'OFF'
133
134     if context.opts.mkl:
135         cmake_opts['GMX_FFT_LIBRARY'] = 'mkl'
136     elif context.opts.fftpack:
137         cmake_opts['GMX_FFT_LIBRARY'] = 'fftpack'
138     elif context.opts.buildfftw:
139         cmake_opts['GMX_BUILD_OWN_FFTW'] = 'ON'
140         cmake_opts['GMX_BUILD_OWN_FFTW_URL'] = 'ftp://ftp.gromacs.org/misc/fftw-3.3.8.tar.gz'
141         cmake_opts['GMX_BUILD_OWN_FFTW_MD5'] = '8aac833c943d8e90d51b697b27d4384d'
142     if context.opts.mkl or context.opts.atlas or context.opts.armpl:
143         cmake_opts['GMX_EXTERNAL_BLAS'] = 'ON'
144         cmake_opts['GMX_EXTERNAL_LAPACK'] = 'ON'
145     if context.opts.clFFT:
146         cmake_opts['GMX_EXTERNAL_CLFFT'] = 'ON'
147         cmake_opts['clFFT_ROOT'] = context.env.clFFT_root
148
149     if context.opts.armpl:
150         cmake_opts['FFTWF_LIBRARY']     = os.path.join(context.env.armpl_dir, 'lib/libarmpl_lp64.so')
151         cmake_opts['FFTWF_INCLUDE_DIR'] = os.path.join(context.env.armpl_dir, 'include')
152         cmake_opts['GMX_BLAS_USER']     = os.path.join(context.env.armpl_dir, 'lib/libarmpl_lp64.so')
153         cmake_opts['GMX_LAPACK_USER']   = os.path.join(context.env.armpl_dir, 'lib/libarmpl_lp64.so')
154
155     if context.opts.hwloc is False:
156         cmake_opts['GMX_HWLOC'] = 'OFF'
157     elif context.opts.hwloc is True:
158         cmake_opts['GMX_HWLOC'] = 'ON'
159     else:
160         cmake_opts['GMX_HWLOC'] = 'AUTO'
161
162     if context.opts.tng is False:
163         cmake_opts['GMX_USE_TNG'] = 'OFF'
164
165     if context.opts.x11:
166         cmake_opts['GMX_X11'] = 'ON'
167
168     if context.opts.tidy:
169         cmake_opts['GMX_CLANG_TIDY'] = 'ON'
170         cmake_opts['CLANG_TIDY'] = context.env.cxx_compiler.replace("clang++", "clang-tidy")
171
172     # At least hwloc on Jenkins produces a massive amount of reports about
173     # memory leaks, which cannot be reasonably suppressed because ASAN cannot
174     # produce a reasonable stack trace for them.
175     if context.opts.asan:
176         cmake_opts['GMX_HWLOC'] = 'OFF'
177
178     if context.opts.gpubufferops:
179         context.env.set_env_var('GMX_USE_GPU_BUFFER_OPS', "1")
180
181     # GPU comm flag enables both DD and PP-PME comm as well as buffer ops (hard dependency)
182     if context.opts.gpucomm:
183         context.env.set_env_var('GMX_USE_GPU_BUFFER_OPS', "1")
184         context.env.set_env_var('GMX_GPU_DD_COMMS', "1")
185         context.env.set_env_var('GMX_GPU_PME_PP_COMMS', "1")
186
187     # GPU update flag enables GPU update+constraints as well as buffer ops (dependency)
188     if context.opts.gpuupdate:
189         context.env.set_env_var('GMX_FORCE_UPDATE_DEFAULT_GPU', "1")
190         context.env.set_env_var('GMX_GPU_DD_COMMS', "1")
191         context.env.set_env_var('GMX_GPU_PME_PP_COMMS', "1")
192
193     regressiontests_path = context.workspace.get_project_dir(Project.REGRESSIONTESTS)
194
195     if context.job_type == JobType.RELEASE:
196         cmake_opts['REGRESSIONTEST_PATH'] = regressiontests_path
197     else:
198         if context.opts.mdrun_only:
199             cmake_opts['GMX_BUILD_MDRUN_ONLY'] = 'ON'
200
201     # The build configuration has constructed the environment of the
202     # context so that a particular c++ standard library can be used,
203     # which may come from a different installation of gcc. Here, we
204     # tell CMake how to react to this.
205     #
206     # TODO Once gerrit 9051 and 9053 are both submitted on master,
207     # remove the hasattr part of the predicate, which will then be
208     # redundant.
209     if hasattr(context.env, 'gcc_exe') and context.env.gcc_exe is not None:
210         cmake_opts['GMX_GPLUSPLUS_PATH'] = context.env.gcc_exe
211         # TODO are these needed?
212         # gcc_exe_dirname = os.path.dirname(self.gcc_exe)
213         # gcc_toolchain_path = os.path.join(gcc_exe_dirname, '..')
214         # format_for_linker_flags="-Wl,-rpath,{gcctoolchain}/lib64 -L{gcctoolchain}/lib64"
215         # cmake_opts['CMAKE_CXX_LINK_FLAGS'] = format_for_linker_flags.format(gcctoolchain=gcc_toolchain_path)
216
217     context.env.set_env_var('GMX_NO_TERM', '1')
218
219     context.run_cmake(cmake_opts)
220     context.build_target(target=None, keep_going=True)
221
222     # TODO: Consider if it would be better to split this into a separate build
223     # script, since it is somewhat different, even though it benefits from some
224     # of the same build options.
225     if context.job_type == JobType.RELEASE:
226         context.build_target(target='check', keep_going=True)
227         context.build_target(target='install')
228         if context.opts.mdrun_only:
229             context.workspace.clean_build_dir()
230             cmake_opts['REGRESSIONTEST_PATH'] = None
231             cmake_opts['GMX_BUILD_MDRUN_ONLY'] = 'ON'
232             context.run_cmake(cmake_opts)
233             context.build_target(target=None, keep_going=True)
234             context.build_target(target='check', keep_going=True)
235             context.build_target(target='install')
236         gmxrc_cmd = '. ' + os.path.join(context.workspace.install_dir, 'bin', 'GMXRC')
237         context.env.run_env_script(gmxrc_cmd)
238         cmd = [os.path.join(regressiontests_path, 'gmxtest.pl'), '-nosuffix', 'all']
239         if context.opts.mpi:
240             cmd += ['-np', '1']
241         if context.opts.double:
242             cmd += ['-double']
243         if context.opts.mdrun_only:
244             cmd += ['-mdrun', 'mdrun']
245         context.run_cmd(cmd, failure_message='Regression tests failed to execute')
246         # TODO: Add testing for building the template.
247         # TODO: Generalize the machinery here such that it can easily be used
248         # also for non-release builds.
249     else:
250         # run OpenCL offline compile tests on clang tidy builds
251         if (context.opts.tidy and context.opts.opencl):
252             context.build_target(target='ocl_nbnxm_kernels')
253             context.build_target(target='ocl_pme_kernels')
254
255         context.build_target(target='tests', keep_going=True)
256
257         context.run_ctest(args=['--output-on-failure', '--label-exclude', 'SlowTest'], memcheck=context.opts.asan)
258
259         context.build_target(target='install')
260         # TODO: Consider what could be tested about the installed binaries.
261
262         if not context.opts.mdrun_only:
263             context.env.prepend_path_env(os.path.join(context.workspace.build_dir, 'bin'))
264             context.chdir(regressiontests_path)
265
266             use_tmpi = not context.opts.mpi and context.opts.thread_mpi is not False
267
268             cmd = 'perl gmxtest.pl -mpirun mpirun -xml -nosuffix all'
269
270             # setting this stuff below is just a temporary solution,
271             # it should all be passed as a proper the runconf from outside
272             # The whole mechanism should be rethought in #1587.
273             if context.opts.phi:
274                 cmd += ' -ntomp 28'
275             elif context.opts.openmp:
276                 # OpenMP should always work when compiled in! Currently not set if
277                 # not explicitly set
278                 cmd += ' -ntomp 2'
279
280             if context.opts.gpuhw == Gpuhw.NONE:
281                 context.env.set_env_var('GMX_DISABLE_GPU_DETECTION', '1')
282
283             if context.opts.gpu_id:
284                 cmd += ' -gpu_id ' + context.opts.gpu_id
285
286             if context.opts.nranks:
287                 nranks = context.opts.nranks
288             else:
289                 nranks = '2'
290
291             if context.opts.npme:
292                 cmd += ' -npme ' + context.opts.npme
293
294             if context.opts.mpi:
295                 cmd += ' -np ' + nranks
296             elif use_tmpi:
297                 cmd += ' -nt ' + nranks
298             if context.opts.double:
299                 cmd += ' -double'
300             if context.opts.asan:
301                 context.env.set_env_var('ASAN_OPTIONS', 'detect_leaks=0')
302             context.run_cmd(cmd, shell=True, failure_message='Regression tests failed to execute')