8c8020efaaf75f03d0c840df9dffac644177c592
[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, 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 #include "gromacs/utility/enumerationhelpers.h"
59
60 //! Constant used to help minimize preprocessed code
61 static constexpr bool c_binarySupportsGpus = (GMX_GPU != 0);
62
63 //! Possible results of the GPU detection/check.
64 enum class DeviceStatus : int
65 {
66     //! The device is compatible
67     Compatible = 0,
68     //! Device does not exist
69     Nonexistent = 1,
70     //! Device is not compatible
71     Incompatible = 2,
72     //! OpenCL device has incompatible cluster size for non-bonded kernels.
73     IncompatibleClusterSize = 3,
74     /*! \brief An error occurred he functionality checks.
75      * That indicates malfunctioning of the device, driver, or incompatible driver/runtime.
76      */
77     NonFunctional = 4,
78     /*! \brief CUDA devices are busy or unavailable.
79      * typically due to use of \p cudaComputeModeExclusive, \p cudaComputeModeProhibited modes.
80      */
81     Unavailable = 5,
82     //! Enumeration size
83     Count = 6
84 };
85
86 /*! \brief Names of the GPU detection/check results
87  *
88  * Check-source wants to warn about the use of a symbol name that would
89  * require an inclusion of config.h. However the use is in a comment, so that
90  * is a false warning. So C-style string concatenation is used to fool the
91  * naive parser in check-source. That needs a clang-format suppression
92  * in order to look reasonable. Also clang-tidy wants to suggest that a comma is
93  * missing, so that is suppressed.
94  */
95 static const gmx::EnumerationArray<DeviceStatus, const char*> c_deviceStateString = {
96     "compatible", "nonexistent", "incompatible",
97     // clang-format off
98     // NOLINTNEXTLINE(bugprone-suspicious-missing-comma)
99     "incompatible (please recompile with correct GMX" "_OPENCL_NB_CLUSTER_SIZE of 4)",
100     // clang-format on
101     "non-functional", "unavailable"
102 };
103
104 //! Device vendors
105 enum class DeviceVendor : int
106 {
107     //! No data
108     Unknown = 0,
109     //! NVIDIA
110     Nvidia = 1,
111     //! Advanced Micro Devices
112     Amd = 2,
113     //! Intel
114     Intel = 3,
115     //! Enumeration size
116     Count = 4
117 };
118
119
120 /*! \libinternal \brief Platform-dependent device information.
121  *
122  * The device information is queried and set at detection and contains
123  * both information about the device/hardware returned by the runtime as well
124  * as additional data like support status.
125  */
126 struct DeviceInformation
127 {
128     //! Device status.
129     DeviceStatus status;
130     //! ID of the device.
131     int id;
132
133 #if GMX_GPU_CUDA
134     //! CUDA device properties.
135     cudaDeviceProp prop;
136 #elif GMX_GPU_OPENCL
137     cl_platform_id oclPlatformId;       //!< OpenCL Platform ID.
138     cl_device_id   oclDeviceId;         //!< OpenCL Device ID.
139     char           device_name[256];    //!< Device name.
140     char           device_version[256]; //!< Device version.
141     char           vendorName[256];     //!< Device vendor name.
142     int            compute_units;       //!< Number of compute units.
143     int            adress_bits;         //!< Number of address bits the device is capable of.
144     DeviceVendor   deviceVendor;        //!< Device vendor.
145     size_t         maxWorkItemSizes[3]; //!< Workgroup size limits (CL_DEVICE_MAX_WORK_ITEM_SIZES).
146     size_t         maxWorkGroupSize;    //!< Workgroup total size limit (CL_DEVICE_MAX_WORK_GROUP_SIZE).
147 #endif
148 };
149
150 #endif // GMX_HARDWARE_DEVICE_INFORMATION_H