Split lines with many copyright years
[alexxy/gromacs.git] / src / gromacs / gpu_utils / ocl_compiler.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 Declare infrastructure for OpenCL JIT compilation
38  *
39  *  \author Dimitrios Karkoulis <dimitris.karkoulis@gmail.com>
40  *  \author Anca Hamuraru <anca@streamcomputing.eu>
41  *  \author Teemu Virolainen <teemu@streamcomputing.eu>
42  *  \author Mark Abraham <mark.j.abraham@gmail.com>
43  *  \inlibraryapi
44  */
45 #ifndef GMX_GPU_UTILS_OCL_COMPILER_H
46 #define GMX_GPU_UTILS_OCL_COMPILER_H
47
48 #include <string>
49
50 #include "gromacs/gpu_utils/oclutils.h"
51
52 namespace gmx
53 {
54 namespace ocl
55 {
56
57 /*! \brief Get the device-specific warp size
58  *
59  *  This is platform implementation dependent and seems to only work on the Nvidia and AMD
60  * platforms! Nvidia reports 32, AMD for GPU 64. Intel seems to report 16, but that is not correct,
61  *  as it execution width can be between 8-32 and it's picked per-kernel at compile-time.
62  *  Therefore, for Intel it should actually be queried separately for each kernel (Redmine #2520).
63  *
64  *  \param  context   Current OpenCL context
65  *  \param  deviceId OpenCL device with the context
66  *  \return cl_int value of the warp size
67  *
68  * \throws InternalError if an OpenCL error was encountered
69  */
70 size_t getDeviceWarpSize(cl_context context, cl_device_id deviceId);
71
72
73 /*! \brief Get the kernel-specific warp size
74  *
75  *  \param  kernel   THe OpenCL kernel object
76  *  \param  deviceId OpenCL device for which the kernel warp size is queried
77  *  \return cl_int value of the warp size
78  *
79  * \throws InternalError if an OpenCL error was encountered
80  */
81 size_t getKernelWarpSize(cl_kernel kernel, cl_device_id deviceId);
82
83 /*! \brief Compile the specified kernel for the context and device.
84  *
85  * \param[out] fplog                 Open file pointer for log output
86  * \param[in]  kernelRelativePath    Relative path to the kernel in the source tree,
87  *                                   e.g. "src/gromacs/mdlib/nbnxn_ocl" for NB kernels.
88  * \param[in]  kernelBaseFilename    The name of the kernel source file to compile, e.g.
89  * "nbnxn_ocl_kernels.cl" \param[in]  extraDefines          Preprocessor defines required by the
90  * calling code, e.g. for configuring the kernels \param[in]  context               OpenCL context
91  * on the device to compile for \param[in]  deviceId              OpenCL device id of the device to
92  * compile for \param[in]  deviceVendorId        Enumerator of the device vendor to compile for
93  *
94  * \returns The compiled OpenCL program
95  *
96  * \todo Consider whether we can parallelize the compilation of all
97  * the kernels by compiling them in separate programs - but since the
98  * resulting programs can't refer to each other, that might lead to
99  * bloat of util code?
100  *
101  * \throws std::bad_alloc  if out of memory.
102  *         FileIOError     if a file I/O error prevents returning a valid compiled program.
103  *         InternalError   if an OpenCL API error prevents returning a valid compiled program. */
104 cl_program compileProgram(FILE*              fplog,
105                           const std::string& kernelRelativePath,
106                           const std::string& kernelBaseFilename,
107                           const std::string& extraDefines,
108                           cl_context         context,
109                           cl_device_id       deviceId,
110                           ocl_vendor_id_t    deviceVendorId);
111
112 } // namespace ocl
113 } // namespace gmx
114
115 #endif