d9116a3a72f5450f0cb2675f6155a44f6199092f
[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) 2018,2019,2020, by the GROMACS development team, led by
5  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6  * and including many others, as listed in the AUTHORS file in the
7  * top-level source directory and at http://www.gromacs.org.
8  *
9  * GROMACS is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public License
11  * as published by the Free Software Foundation; either version 2.1
12  * of the License, or (at your option) any later version.
13  *
14  * GROMACS is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with GROMACS; if not, see
21  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
23  *
24  * If you want to redistribute modifications to GROMACS, please
25  * consider that scientific software is very special. Version
26  * control is crucial - bugs must be traceable. We will be happy to
27  * consider code for inclusion in the official distribution, but
28  * derived work must not be called official GROMACS. Details are found
29  * in the README & COPYING files - if they are missing, get the
30  * official version at http://www.gromacs.org.
31  *
32  * To help us fund GROMACS development, we humbly ask that you cite
33  * the research papers on the package. Check out http://www.gromacs.org.
34  */
35 /*! \libinternal \file
36  *  \brief Declares the GPU type traits for non-GPU builds.
37  *
38  *  \author Mark Abraham <mark.j.abraham@gmail.com>
39  *  \author Artem Zhmurov <zhmurov@gmail.com>
40  *
41  * \inlibraryapi
42  * \ingroup module_hardware
43  */
44 #ifndef GMX_HARDWARE_DEVICE_INFORMATION_H
45 #define GMX_HARDWARE_DEVICE_INFORMATION_H
46
47 #include "config.h"
48
49 #if GMX_GPU_CUDA
50 #    include <cuda_runtime.h>
51 #endif
52
53 #if GMX_GPU_OPENCL
54 #    include "gromacs/gpu_utils/gmxopencl.h"
55 #endif
56 #include "gromacs/utility/enumerationhelpers.h"
57
58 //! Constant used to help minimize preprocessed code
59 static constexpr bool c_binarySupportsGpus = (GMX_GPU != 0);
60
61 //! Possible results of the GPU detection/check.
62 enum class DeviceStatus : int
63 {
64     //! The device is compatible
65     Compatible = 0,
66     //! Device does not exist
67     Nonexistent = 1,
68     //! Device is not compatible
69     Incompatible = 2,
70     //! OpenCL device has incompatible cluster size for non-bonded kernels.
71     IncompatibleClusterSize = 3,
72     /*! \brief An error occurred he functionality checks.
73      * That indicates malfunctioning of the device, driver, or incompatible driver/runtime.
74      */
75     NonFunctional = 4,
76     /*! \brief CUDA devices are busy or unavailable.
77      * typically due to use of \p cudaComputeModeExclusive, \p cudaComputeModeProhibited modes.
78      */
79     Unavailable = 5,
80     //! Enumeration size
81     Count = 6
82 };
83
84 /*! \brief Names of the GPU detection/check results
85  *
86  * Check-source wants to warn about the use of a symbol name that would
87  * require an inclusion of config.h. However the use is in a comment, so that
88  * is a false warning. So C-style string concatenation is used to fool the
89  * naive parser in check-source. That needs a clang-format suppression
90  * in order to look reasonable. Also clang-tidy wants to suggest that a comma is
91  * missing, so that is suppressed.
92  */
93 static const gmx::EnumerationArray<DeviceStatus, const char*> c_deviceStateString = {
94     "compatible", "nonexistent", "incompatible",
95     // clang-format off
96     // NOLINTNEXTLINE(bugprone-suspicious-missing-comma)
97     "incompatible (please recompile with correct GMX" "_OPENCL_NB_CLUSTER_SIZE of 4)",
98     // clang-format on
99     "non-functional", "unavailable"
100 };
101
102 //! Device vendors
103 enum class DeviceVendor : int
104 {
105     //! No data
106     Unknown = 0,
107     //! NVIDIA
108     Nvidia = 1,
109     //! Advanced Micro Devices
110     Amd = 2,
111     //! Intel
112     Intel = 3,
113     //! Enumeration size
114     Count = 4
115 };
116
117
118 /*! \libinternal \brief Platform-dependent device information.
119  *
120  * The device information is queried and set at detection and contains
121  * both information about the device/hardware returned by the runtime as well
122  * as additional data like support status.
123  */
124 struct DeviceInformation
125 {
126     //! Device status.
127     DeviceStatus stat;
128     //! ID of the device.
129     int id;
130
131 #if GMX_GPU_CUDA
132     //! CUDA device properties.
133     cudaDeviceProp prop;
134 #elif GMX_GPU_OPENCL
135     cl_platform_id oclPlatformId;       //!< OpenCL Platform ID.
136     cl_device_id   oclDeviceId;         //!< OpenCL Device ID.
137     char           device_name[256];    //!< Device name.
138     char           device_version[256]; //!< Device version.
139     char           vendorName[256];     //!< Device vendor name.
140     int            compute_units;       //!< Number of compute units.
141     int            adress_bits;         //!< Number of address bits the device is capable of.
142     DeviceVendor   deviceVendor;        //!< Device vendor.
143     size_t         maxWorkItemSizes[3]; //!< Workgroup size limits (CL_DEVICE_MAX_WORK_ITEM_SIZES).
144     size_t         maxWorkGroupSize;    //!< Workgroup total size limit (CL_DEVICE_MAX_WORK_GROUP_SIZE).
145 #endif
146 };
147
148 #endif // GMX_HARDWARE_DEVICE_INFORMATION_H