Update mdrun message to reflect that Cuda CC>=3.5 is supported.
[alexxy/gromacs.git] / src / gromacs / hardware / device_information.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2012,2013,2014,2015,2016, by the GROMACS development team.
5  * Copyright (c) 2017,2018,2019,2020,2021, 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 /*! \libinternal \file
37  *  \brief Declares the GPU information structure and its helpers
38  *
39  *  \author Anca Hamuraru <anca@streamcomputing.eu>
40  *  \author Dimitrios Karkoulis <dimitris.karkoulis@gmail.com>
41  *  \author Teemu Virolainen <teemu@streamcomputing.eu>
42  *  \author Mark Abraham <mark.j.abraham@gmail.com>
43  *  \author Szilárd Páll <pall.szilard@gmail.com>
44  *  \author Artem Zhmurov <zhmurov@gmail.com>
45  */
46 #ifndef GMX_HARDWARE_DEVICE_INFORMATION_H
47 #define GMX_HARDWARE_DEVICE_INFORMATION_H
48
49 #include "config.h"
50
51 #if GMX_GPU_CUDA
52 #    include <cuda_runtime.h>
53 #endif
54
55 #if GMX_GPU_OPENCL
56 #    include "gromacs/gpu_utils/gmxopencl.h"
57 #endif
58
59 #if GMX_GPU_SYCL
60 #    include "gromacs/gpu_utils/gmxsycl.h"
61 #endif
62
63 #include "gromacs/utility/enumerationhelpers.h"
64
65 //! Constant used to help minimize preprocessed code
66 static constexpr bool c_binarySupportsGpus = (GMX_GPU != 0);
67 //! Whether \ref DeviceInformation can be serialized for sending via MPI.
68 static constexpr bool c_canSerializeDeviceInformation =
69         (!GMX_GPU_OPENCL && !GMX_GPU_SYCL); /*NOLINT(misc-redundant-expression)*/
70
71 //! Possible results of the GPU detection/check.
72 enum class DeviceStatus : int
73 {
74     //! The device is compatible
75     Compatible = 0,
76     //! Device does not exist
77     Nonexistent = 1,
78     //! Device is not compatible
79     Incompatible = 2,
80     //! OpenCL device has incompatible cluster size for non-bonded kernels.
81     IncompatibleClusterSize = 3,
82     //! There are known issues with OpenCL on NVIDIA Volta and newer.
83     IncompatibleNvidiaVolta = 4,
84     /*! \brief The device originates from non-recommended SYCL backend.
85      * The device might work by itself, but to simplify device allocation, it is marked as incompatible.
86      * */
87     NotPreferredBackend = 5,
88     /*! \brief An error occurred during the functionality checks.
89      * That indicates malfunctioning of the device, driver, or incompatible driver/runtime.
90      */
91     NonFunctional = 6,
92     /*! \brief CUDA devices are busy or unavailable.
93      * typically due to use of \p cudaComputeModeExclusive, \p cudaComputeModeProhibited modes.
94      */
95     Unavailable = 7,
96     //! Enumeration size
97     Count = 8
98 };
99
100 /*! \brief Names of the GPU detection/check results
101  *
102  * Check-source wants to warn about the use of a symbol name that would
103  * require an inclusion of config.h. However the use is in a comment, so that
104  * is a false warning. So C-style string concatenation is used to fool the
105  * naive parser in check-source. That needs a clang-format suppression
106  * in order to look reasonable. Also clang-tidy wants to suggest that a comma is
107  * missing, so that is suppressed.
108  */
109 static const gmx::EnumerationArray<DeviceStatus, const char*> c_deviceStateString = {
110     "compatible",
111     "nonexistent",
112     "incompatible",
113     // clang-format off
114     // NOLINTNEXTLINE(bugprone-suspicious-missing-comma)
115     "incompatible (please recompile with correct GMX" "_GPU_NB_CLUSTER_SIZE of 4)",
116     // clang-format on
117     "incompatible (please use CUDA build for NVIDIA Volta GPUs or newer)",
118     "not recommended (please use SYCL_DEVICE_FILTER to limit visibility to a single backend)",
119     "non-functional",
120     "unavailable"
121 };
122
123 //! Device vendors
124 enum class DeviceVendor : int
125 {
126     //! No data
127     Unknown = 0,
128     //! NVIDIA
129     Nvidia = 1,
130     //! Advanced Micro Devices
131     Amd = 2,
132     //! Intel
133     Intel = 3,
134     //! Enumeration size
135     Count = 4
136 };
137
138
139 /*! \libinternal \brief Platform-dependent device information.
140  *
141  * The device information is queried and set at detection and contains
142  * both information about the device/hardware returned by the runtime as well
143  * as additional data like support status.
144  */
145 struct DeviceInformation
146 {
147     //! Device status.
148     DeviceStatus status;
149     //! ID of the device.
150     int id;
151     //! Device vendor.
152     DeviceVendor deviceVendor;
153 #if GMX_GPU_CUDA
154     //! CUDA device properties.
155     cudaDeviceProp prop;
156 #elif GMX_GPU_OPENCL
157     cl_platform_id oclPlatformId;       //!< OpenCL Platform ID.
158     cl_device_id   oclDeviceId;         //!< OpenCL Device ID.
159     char           device_name[256];    //!< Device name.
160     char           device_version[256]; //!< Device version.
161     char           vendorName[256];     //!< Device vendor name.
162     int            compute_units;       //!< Number of compute units.
163     int            adress_bits;         //!< Number of address bits the device is capable of.
164     size_t         maxWorkItemSizes[3]; //!< Workgroup size limits (CL_DEVICE_MAX_WORK_ITEM_SIZES).
165     size_t         maxWorkGroupSize;    //!< Workgroup total size limit (CL_DEVICE_MAX_WORK_GROUP_SIZE).
166 #elif GMX_GPU_SYCL
167     cl::sycl::device syclDevice;
168 #endif
169 };
170
171 #endif // GMX_HARDWARE_DEVICE_INFORMATION_H