Update instructions in containers.rst
[gromacs.git] / src / gromacs / gpu_utils / ocl_compiler.h
blob00baec0f0689cd1241fdaf4d89543586603b53cb
1 /*
2 * This file is part of the GROMACS molecular simulation package.
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.
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.
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.
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.
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.
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.
36 /*! \libinternal \file
37 * \brief Declare infrastructure for OpenCL JIT compilation
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
45 #ifndef GMX_GPU_UTILS_OCL_COMPILER_H
46 #define GMX_GPU_UTILS_OCL_COMPILER_H
48 #include <string>
50 #include "gromacs/gpu_utils/oclutils.h"
51 #include "gromacs/hardware/device_information.h"
53 namespace gmx
55 namespace ocl
58 /*! \brief Get the device-specific warp size
60 * This is platform implementation dependent and seems to only work on the Nvidia and AMD
61 * platforms! Nvidia reports 32, AMD for GPU 64. Intel seems to report 16, but that is not correct,
62 * as it execution width can be between 8-32 and it's picked per-kernel at compile-time.
63 * Therefore, for Intel it should actually be queried separately for each kernel (Issue #2520).
65 * \param context Current OpenCL context
66 * \param deviceId OpenCL device with the context
67 * \return cl_int value of the warp size
69 * \throws InternalError if an OpenCL error was encountered
71 size_t getDeviceWarpSize(cl_context context, cl_device_id deviceId);
74 /*! \brief Get the kernel-specific warp size
76 * \param kernel THe OpenCL kernel object
77 * \param deviceId OpenCL device for which the kernel warp size is queried
78 * \return cl_int value of the warp size
80 * \throws InternalError if an OpenCL error was encountered
82 size_t getKernelWarpSize(cl_kernel kernel, cl_device_id deviceId);
84 /*! \brief Compile the specified kernel for the context and device.
86 * \param[out] fplog Open file pointer for log output
87 * \param[in] kernelRelativePath Relative path to the kernel in the source tree,
88 * e.g. "src/gromacs/mdlib/nbnxn_ocl" for NB kernels.
89 * \param[in] kernelBaseFilename The name of the kernel source file to compile, e.g.
90 * "nbnxn_ocl_kernels.cl"
91 * \param[in] extraDefines Preprocessor defines required by the calling code,
92 * e.g. for configuring the kernels
93 * \param[in] context OpenCL context on the device to compile for
94 * \param[in] deviceId OpenCL device id of the device to compile for
95 * \param[in] deviceVendor Enumerator of the device vendor to compile for
97 * \returns The compiled OpenCL program
99 * \todo Consider whether we can parallelize the compilation of all
100 * the kernels by compiling them in separate programs - but since the
101 * resulting programs can't refer to each other, that might lead to
102 * bloat of util code?
104 * \throws std::bad_alloc if out of memory.
105 * FileIOError if a file I/O error prevents returning a valid compiled program.
106 * InternalError if an OpenCL API error prevents returning a valid compiled program. */
107 cl_program compileProgram(FILE* fplog,
108 const std::string& kernelRelativePath,
109 const std::string& kernelBaseFilename,
110 const std::string& extraDefines,
111 cl_context context,
112 cl_device_id deviceId,
113 DeviceVendor deviceVendor);
115 } // namespace ocl
116 } // namespace gmx
118 #endif