Add SYCL compiler and MKL versions
[alexxy/gromacs.git] / src / gromacs / utility / binaryinformation.cpp
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5  * Copyright (c) 2001-2004, The GROMACS development team.
6  * Copyright (c) 2013,2014,2015,2016,2017 by the GROMACS development team.
7  * Copyright (c) 2018,2019,2020,2021, by the GROMACS development team, led by
8  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
9  * and including many others, as listed in the AUTHORS file in the
10  * top-level source directory and at http://www.gromacs.org.
11  *
12  * GROMACS is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU Lesser General Public License
14  * as published by the Free Software Foundation; either version 2.1
15  * of the License, or (at your option) any later version.
16  *
17  * GROMACS is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20  * Lesser General Public License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public
23  * License along with GROMACS; if not, see
24  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
26  *
27  * If you want to redistribute modifications to GROMACS, please
28  * consider that scientific software is very special. Version
29  * control is crucial - bugs must be traceable. We will be happy to
30  * consider code for inclusion in the official distribution, but
31  * derived work must not be called official GROMACS. Details are found
32  * in the README & COPYING files - if they are missing, get the
33  * official version at http://www.gromacs.org.
34  *
35  * To help us fund GROMACS development, we humbly ask that you cite
36  * the research papers on the package. Check out http://www.gromacs.org.
37  */
38 /*! \internal \file
39  * \brief Implements functionality for printing information about the
40  * currently running binary
41  *
42  * \ingroup module_utility
43  */
44 #include "gmxpre.h"
45
46 #include "binaryinformation.h"
47
48 #include "config.h"
49
50 #if GMX_FFT_FFTW3 || GMX_FFT_ARMPL_FFTW3
51 // Needed for construction of the FFT library description string
52 #    include <fftw3.h>
53 #endif
54
55 #if HAVE_LIBMKL
56 #    include <mkl.h>
57 #endif
58
59 #if HAVE_EXTRAE
60 #    include <extrae_user_events.h>
61 #endif
62
63 #if GMX_USE_HWLOC
64 #    include <hwloc.h>
65 #endif
66
67 #include <cstdio>
68 #include <cstdlib>
69 #include <cstring>
70
71 #include <algorithm>
72 #include <array>
73 #include <string>
74
75 /* This file is completely threadsafe - keep it that way! */
76
77 #include "buildinfo.h"
78 #include "gromacs/utility/arraysize.h"
79 #include "gromacs/utility/baseversion.h"
80 #include "gromacs/utility/exceptions.h"
81 #include "gromacs/utility/gmxassert.h"
82 #include "gromacs/utility/path.h"
83 #include "gromacs/utility/programcontext.h"
84 #include "gromacs/utility/stringutil.h"
85 #include "gromacs/utility/sysinfo.h"
86 #include "gromacs/utility/textwriter.h"
87
88 #include "cuda_version_information.h"
89 #include "sycl_version_information.h"
90
91 namespace
92 {
93
94 using gmx::formatString;
95
96 //! \cond Doxygen does not need to care about most of this stuff, and the macro usage is painful to document
97
98 int centeringOffset(int width, int length)
99 {
100     return std::max(width - length, 0) / 2;
101 }
102
103 std::string formatCentered(int width, const char* text)
104 {
105     const int offset = centeringOffset(width, std::strlen(text));
106     return formatString("%*s%s", offset, "", text);
107 }
108
109 void printCopyright(gmx::TextWriter* writer)
110 {
111     // Contributors sorted alphabetically by last name
112     static const char* const Contributors[]  = { "Andrey Alekseenko",
113                                                 "Emile Apol",
114                                                 "Rossen Apostolov",
115                                                 "Paul Bauer",
116                                                 "Herman J.C. Berendsen",
117                                                 "Par Bjelkmar",
118                                                 "Christian Blau",
119                                                 "Viacheslav Bolnykh",
120                                                 "Kevin Boyd",
121                                                 "Aldert van Buuren",
122                                                 "Rudi van Drunen",
123                                                 "Anton Feenstra",
124                                                 "Gaurav Garg",
125                                                 "Gilles Gouaillardet",
126                                                 "Alan Gray",
127                                                 "Gerrit Groenhof",
128                                                 "Anca Hamuraru",
129                                                 "Vincent Hindriksen",
130                                                 "M. Eric Irrgang",
131                                                 "Aleksei Iupinov",
132                                                 "Christoph Junghans",
133                                                 "Joe Jordan",
134                                                 "Dimitrios Karkoulis",
135                                                 "Peter Kasson",
136                                                 "Jiri Kraus",
137                                                 "Carsten Kutzner",
138                                                 "Per Larsson",
139                                                 "Justin A. Lemkul",
140                                                 "Viveca Lindahl",
141                                                 "Magnus Lundborg",
142                                                 "Erik Marklund",
143                                                 "Pascal Merz",
144                                                 "Pieter Meulenhoff",
145                                                 "Teemu Murtola",
146                                                 "Szilard Pall",
147                                                 "Sander Pronk",
148                                                 "Roland Schulz",
149                                                 "Michael Shirts",
150                                                 "Alexey Shvetsov",
151                                                 "Alfons Sijbers",
152                                                 "Peter Tieleman",
153                                                 "Jon Vincent",
154                                                 "Teemu Virolainen",
155                                                 "Christian Wennberg",
156                                                 "Maarten Wolf",
157                                                 "Artem Zhmurov" };
158     static const char* const CopyrightText[] = {
159         "Copyright (c) 1991-2000, University of Groningen, The Netherlands.",
160         "Copyright (c) 2001-2019, The GROMACS development team at",
161         "Uppsala University, Stockholm University and",
162         "the Royal Institute of Technology, Sweden.",
163         "check out http://www.gromacs.org for more information."
164     };
165
166 #define NCONTRIBUTORS static_cast<int>(asize(Contributors))
167 #define NCR static_cast<int>(asize(CopyrightText))
168
169     // TODO a centering behaviour of TextWriter could be useful here
170     writer->writeLine(formatCentered(78, "GROMACS is written by:"));
171     for (int i = 0; i < NCONTRIBUTORS;)
172     {
173         for (int j = 0; j < 3 && i < NCONTRIBUTORS; ++j, ++i)
174         {
175             const int            width = 26;
176             std::array<char, 30> buf;
177             const int            offset = centeringOffset(width, strlen(Contributors[i]));
178             GMX_RELEASE_ASSERT(static_cast<int>(strlen(Contributors[i])) + offset < gmx::ssize(buf),
179                                "Formatting buffer is not long enough");
180             std::fill(buf.begin(), buf.begin() + offset, ' ');
181             std::strncpy(buf.data() + offset, Contributors[i], gmx::ssize(buf) - offset);
182             writer->writeString(formatString(" %-*s", width, buf.data()));
183         }
184         writer->ensureLineBreak();
185     }
186     writer->writeLine(formatCentered(78, "and the project leaders:"));
187     writer->writeLine(
188             formatCentered(78, "Mark Abraham, Berk Hess, Erik Lindahl, and David van der Spoel"));
189     writer->ensureEmptyLine();
190     for (int i = 0; i < NCR; ++i)
191     {
192         writer->writeLine(CopyrightText[i]);
193     }
194     writer->ensureEmptyLine();
195
196     // Folding At Home has different licence to allow digital
197     // signatures in GROMACS, so does not need to show the normal
198     // license statement.
199     if (!GMX_FAHCORE)
200     {
201         writer->writeLine("GROMACS is free software; you can redistribute it and/or modify it");
202         writer->writeLine("under the terms of the GNU Lesser General Public License");
203         writer->writeLine("as published by the Free Software Foundation; either version 2.1");
204         writer->writeLine("of the License, or (at your option) any later version.");
205     }
206 }
207
208 //! Construct a string that describes the library that provides CPU FFT support to this build
209 const char* getCpuFftDescriptionString()
210 {
211 // Define the FFT description string
212 #if GMX_FFT_FFTW3 || GMX_FFT_ARMPL_FFTW3
213 #    if GMX_NATIVE_WINDOWS
214     // Don't buy trouble
215     return "fftw3";
216 #    else
217     // Use the version string provided by libfftw3
218 #        if GMX_DOUBLE
219     return fftw_version;
220 #        else
221     return fftwf_version;
222 #        endif
223 #    endif
224 #endif
225 #if GMX_FFT_MKL
226     return "Intel MKL";
227 #endif
228 #if GMX_FFT_FFTPACK
229     return "fftpack (built-in)";
230 #endif
231 };
232
233 //! Construct a string that describes the library that provides GPU FFT support to this build
234 const char* getGpuFftDescriptionString()
235 {
236     if (GMX_GPU)
237     {
238         if (GMX_GPU_CUDA)
239         {
240             return "cuFFT";
241         }
242         else if (GMX_GPU_OPENCL)
243         {
244             return "clFFT";
245         }
246         else if (GMX_GPU_SYCL)
247         {
248             return "unknown";
249         }
250         else
251         {
252             GMX_RELEASE_ASSERT(false, "Unknown GPU configuration");
253             return "impossible";
254         }
255     }
256     else
257     {
258         return "none";
259     }
260 };
261
262 void gmx_print_version_info(gmx::TextWriter* writer)
263 {
264     writer->writeLine(formatString("GROMACS version:    %s", gmx_version()));
265     const char* const git_hash = gmx_version_git_full_hash();
266     if (git_hash[0] != '\0')
267     {
268         writer->writeLine(formatString("GIT SHA1 hash:      %s", git_hash));
269     }
270     const char* const base_hash = gmx_version_git_central_base_hash();
271     if (base_hash[0] != '\0')
272     {
273         writer->writeLine(formatString("Branched from:      %s", base_hash));
274     }
275     const char* const releaseSourceChecksum = gmxReleaseSourceChecksum();
276     const char* const currentSourceChecksum = gmxCurrentSourceChecksum();
277     if (releaseSourceChecksum[0] != '\0')
278     {
279         if (std::strcmp(releaseSourceChecksum, "NoChecksumFile") == 0)
280         {
281             writer->writeLine(formatString(
282                     "The source code this program was compiled from has not been verified because "
283                     "the reference checksum was missing during compilation. This means you have an "
284                     "incomplete GROMACS distribution, please make sure to download an intact "
285                     "source distribution and compile that before proceeding."));
286             writer->writeLine(formatString("Computed checksum: %s", currentSourceChecksum));
287         }
288         else if (std::strcmp(releaseSourceChecksum, "NoPythonAvailable") == 0)
289         {
290             writer->writeLine(
291                     formatString("Build source could not be verified, because the checksum could "
292                                  "not be computed."));
293         }
294         else if (std::strcmp(releaseSourceChecksum, currentSourceChecksum) != 0)
295         {
296             writer->writeLine(formatString(
297                     "This program has been built from source code that has been altered and does "
298                     "not match the code released as part of the official GROMACS version %s. If "
299                     "you did not intend to use an altered GROMACS version, make sure to download "
300                     "an intact source distribution and compile that before proceeding.",
301                     gmx_version()));
302             writer->writeLine(formatString(
303                     "If you have modified the source code, you are strongly encouraged to set your "
304                     "custom version suffix (using -DGMX_VERSION_STRING_OF_FORK) which will can "
305                     "help later with scientific reproducibility but also when reporting bugs."));
306             writer->writeLine(formatString("Release checksum: %s", releaseSourceChecksum));
307             writer->writeLine(formatString("Computed checksum: %s", currentSourceChecksum));
308         }
309         else
310         {
311             writer->writeLine(formatString("Verified release checksum is %s", releaseSourceChecksum));
312         }
313     }
314
315
316 #if GMX_DOUBLE
317     writer->writeLine("Precision:          double");
318 #else
319     writer->writeLine("Precision:          mixed");
320 #endif
321     writer->writeLine(formatString("Memory model:       %u bit", static_cast<unsigned>(8 * sizeof(void*))));
322
323 #if GMX_THREAD_MPI
324     writer->writeLine("MPI library:        thread_mpi");
325 #elif GMX_MPI
326 #    if HAVE_CUDA_AWARE_MPI
327     writer->writeLine("MPI library:        MPI (CUDA-aware)");
328 #    else
329     writer->writeLine("MPI library:        MPI");
330 #    endif
331 #else
332     writer->writeLine("MPI library:        none");
333 #endif
334 #if GMX_OPENMP
335     writer->writeLine(formatString("OpenMP support:     enabled (GMX_OPENMP_MAX_THREADS = %d)",
336                                    GMX_OPENMP_MAX_THREADS));
337 #else
338     writer->writeLine("OpenMP support:     disabled");
339 #endif
340     writer->writeLine(formatString("GPU support:        %s", getGpuImplementationString()));
341     writer->writeLine(formatString("SIMD instructions:  %s", GMX_SIMD_STRING));
342     writer->writeLine(formatString("CPU FFT library:    %s", getCpuFftDescriptionString()));
343     writer->writeLine(formatString("GPU FFT library:    %s", getGpuFftDescriptionString()));
344 #if GMX_TARGET_X86
345     writer->writeLine(formatString("RDTSCP usage:       %s", GMX_USE_RDTSCP ? "enabled" : "disabled"));
346 #endif
347 #if GMX_USE_TNG
348     writer->writeLine("TNG support:        enabled");
349 #else
350     writer->writeLine("TNG support:        disabled");
351 #endif
352 #if GMX_USE_HWLOC
353     writer->writeLine(formatString("Hwloc support:      hwloc-%s", HWLOC_VERSION));
354 #else
355     writer->writeLine("Hwloc support:      disabled");
356 #endif
357 #if HAVE_EXTRAE
358     unsigned major, minor, revision;
359     Extrae_get_version(&major, &minor, &revision);
360     writer->writeLine(formatString(
361             "Tracing support:    enabled. Using Extrae-%d.%d.%d", major, minor, revision));
362 #else
363     writer->writeLine("Tracing support:    disabled");
364 #endif
365
366
367     /* TODO: The below strings can be quite long, so it would be nice to wrap
368      * them. Can wait for later, as the master branch has ready code to do all
369      * that. */
370     writer->writeLine(formatString("C compiler:         %s", BUILD_C_COMPILER));
371     writer->writeLine(formatString(
372             "C compiler flags:   %s %s", BUILD_CFLAGS, CMAKE_BUILD_CONFIGURATION_C_FLAGS));
373     writer->writeLine(formatString("C++ compiler:       %s", BUILD_CXX_COMPILER));
374     writer->writeLine(formatString(
375             "C++ compiler flags: %s %s", BUILD_CXXFLAGS, CMAKE_BUILD_CONFIGURATION_CXX_FLAGS));
376 #if HAVE_LIBMKL
377     /* MKL might be used for LAPACK/BLAS even if FFTs use FFTW, so keep it separate */
378     writer->writeLine(formatString(
379             "Intel MKL version:  %d.%d.%d", __INTEL_MKL__, __INTEL_MKL_MINOR__, __INTEL_MKL_UPDATE__));
380 #endif
381 #if GMX_GPU_OPENCL
382     writer->writeLine(formatString("OpenCL include dir: %s", OPENCL_INCLUDE_DIR));
383     writer->writeLine(formatString("OpenCL library:     %s", OPENCL_LIBRARY));
384     writer->writeLine(formatString("OpenCL version:     %s", OPENCL_VERSION_STRING));
385 #endif
386 #if GMX_GPU_CUDA
387     writer->writeLine(formatString("CUDA compiler:      %s", CUDA_COMPILER_INFO));
388     writer->writeLine(formatString(
389             "CUDA compiler flags:%s %s", CUDA_COMPILER_FLAGS, CMAKE_BUILD_CONFIGURATION_CXX_FLAGS));
390     writer->writeLine("CUDA driver:        " + gmx::getCudaDriverVersionString());
391     writer->writeLine("CUDA runtime:       " + gmx::getCudaRuntimeVersionString());
392 #endif
393 #if GMX_SYCL_DPCPP
394     writer->writeLine(formatString("SYCL DPC++ flags:   %s", SYCL_DPCPP_COMPILER_FLAGS));
395     writer->writeLine("SYCL DPC++ version: " + gmx::getSyclCompilerVersion());
396 #endif
397 #if GMX_SYCL_HIPSYCL
398     writer->writeLine(formatString("hipSYCL launcher:   %s", SYCL_HIPSYCL_COMPILER_LAUNCHER));
399     writer->writeLine(formatString("hipSYCL flags:      %s", SYCL_HIPSYCL_COMPILER_FLAGS));
400     writer->writeLine(formatString("hipSYCL targets:    %s", SYCL_HIPSYCL_TARGETS));
401     writer->writeLine("hipSYCL version:    " + gmx::getSyclCompilerVersion());
402 #endif
403 }
404
405 //! \endcond
406
407 } // namespace
408
409 namespace gmx
410 {
411
412 BinaryInformationSettings::BinaryInformationSettings() :
413     bExtendedInfo_(false),
414     bCopyright_(false),
415     bProcessId_(false),
416     bGeneratedByHeader_(false),
417     prefix_(""),
418     suffix_("")
419 {
420 }
421
422 void printBinaryInformation(FILE* fp, const IProgramContext& programContext)
423 {
424     TextWriter writer(fp);
425     printBinaryInformation(&writer, programContext, BinaryInformationSettings());
426 }
427
428 void printBinaryInformation(FILE*                            fp,
429                             const IProgramContext&           programContext,
430                             const BinaryInformationSettings& settings)
431 {
432     try
433     {
434         TextWriter writer(fp);
435         printBinaryInformation(&writer, programContext, settings);
436     }
437     GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR
438 }
439
440 void printBinaryInformation(TextWriter*                      writer,
441                             const IProgramContext&           programContext,
442                             const BinaryInformationSettings& settings)
443 {
444     // TODO Perhaps the writer could be configured with the prefix and
445     // suffix strings from the settings?
446     const char* prefix          = settings.prefix_;
447     const char* suffix          = settings.suffix_;
448     const char* precisionString = "";
449 #if GMX_DOUBLE
450     precisionString = " (double precision)";
451 #endif
452     const char* const name = programContext.displayName();
453     if (settings.bGeneratedByHeader_)
454     {
455         writer->writeLine(formatString("%sCreated by:%s", prefix, suffix));
456     }
457     // TODO: It would be nice to know here whether we are really running a
458     // Gromacs binary or some other binary that is calling Gromacs; we
459     // could then print "%s is part of GROMACS" or some alternative text.
460     std::string title = formatString(":-) GROMACS - %s, %s%s (-:", name, gmx_version(), precisionString);
461     const int indent =
462             centeringOffset(78 - std::strlen(prefix) - std::strlen(suffix), title.length()) + 1;
463     writer->writeLine(formatString("%s%*c%s%s", prefix, indent, ' ', title.c_str(), suffix));
464     writer->writeLine(formatString("%s%s", prefix, suffix));
465     if (settings.bCopyright_)
466     {
467         GMX_RELEASE_ASSERT(prefix[0] == '\0' && suffix[0] == '\0',
468                            "Prefix/suffix not supported with copyright");
469         printCopyright(writer);
470         writer->ensureEmptyLine();
471         // This line is printed again after the copyright notice to make it
472         // appear together with all the other information, so that it is not
473         // necessary to read stuff above the copyright notice.
474         // The line above the copyright notice puts the copyright notice is
475         // context, though.
476         writer->writeLine(formatString(
477                 "%sGROMACS:      %s, version %s%s%s", prefix, name, gmx_version(), precisionString, suffix));
478     }
479     const char* const binaryPath = programContext.fullBinaryPath();
480     if (!gmx::isNullOrEmpty(binaryPath))
481     {
482         writer->writeLine(formatString("%sExecutable:   %s%s", prefix, binaryPath, suffix));
483     }
484     const gmx::InstallationPrefixInfo installPrefix = programContext.installationPrefix();
485     if (!gmx::isNullOrEmpty(installPrefix.path))
486     {
487         writer->writeLine(formatString("%sData prefix:  %s%s%s",
488                                        prefix,
489                                        installPrefix.path,
490                                        installPrefix.bSourceLayout ? " (source tree)" : "",
491                                        suffix));
492     }
493     const std::string workingDir = Path::getWorkingDirectory();
494     if (!workingDir.empty())
495     {
496         writer->writeLine(formatString("%sWorking dir:  %s%s", prefix, workingDir.c_str(), suffix));
497     }
498     if (settings.bProcessId_)
499     {
500         writer->writeLine(formatString("%sProcess ID:   %d%s", prefix, gmx_getpid(), suffix));
501     }
502     const char* const commandLine = programContext.commandLine();
503     if (!gmx::isNullOrEmpty(commandLine))
504     {
505         writer->writeLine(formatString(
506                 "%sCommand line:%s\n%s  %s%s", prefix, suffix, prefix, commandLine, suffix));
507     }
508     if (settings.bExtendedInfo_)
509     {
510         GMX_RELEASE_ASSERT(prefix[0] == '\0' && suffix[0] == '\0',
511                            "Prefix/suffix not supported with extended info");
512         writer->ensureEmptyLine();
513         gmx_print_version_info(writer);
514     }
515 }
516
517 } // namespace gmx