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.
37 * \brief Define OpenCL implementation of nbnxm_gpu_data_mgmt.h
39 * \author Anca Hamuraru <anca@streamcomputing.eu>
40 * \author Dimitrios Karkoulis <dimitris.karkoulis@gmail.com>
41 * \author Teemu Virolainen <teemu@streamcomputing.eu>
42 * \author Szilárd Páll <pall.szilard@gmail.com>
43 * \ingroup module_nbnxm
55 #include "gromacs/gpu_utils/device_stream_manager.h"
56 #include "gromacs/gpu_utils/oclutils.h"
57 #include "gromacs/hardware/device_information.h"
58 #include "gromacs/hardware/device_management.h"
59 #include "gromacs/math/vectypes.h"
60 #include "gromacs/mdlib/force_flags.h"
61 #include "gromacs/mdtypes/interaction_const.h"
62 #include "gromacs/mdtypes/md_enums.h"
63 #include "gromacs/nbnxm/atomdata.h"
64 #include "gromacs/nbnxm/gpu_data_mgmt.h"
65 #include "gromacs/nbnxm/gpu_jit_support.h"
66 #include "gromacs/nbnxm/nbnxm.h"
67 #include "gromacs/nbnxm/nbnxm_gpu.h"
68 #include "gromacs/nbnxm/nbnxm_gpu_data_mgmt.h"
69 #include "gromacs/nbnxm/pairlistsets.h"
70 #include "gromacs/pbcutil/ishift.h"
71 #include "gromacs/timing/gpu_timing.h"
72 #include "gromacs/utility/cstringutil.h"
73 #include "gromacs/utility/fatalerror.h"
74 #include "gromacs/utility/gmxassert.h"
75 #include "gromacs/utility/real.h"
76 #include "gromacs/utility/smalloc.h"
78 #include "nbnxm_ocl_types.h"
83 /*! \brief Copies of values from cl_driver_diagnostics_intel.h,
84 * which isn't guaranteed to be available. */
86 #define CL_CONTEXT_SHOW_DIAGNOSTICS_INTEL 0x4106
87 #define CL_CONTEXT_DIAGNOSTICS_LEVEL_GOOD_INTEL 0x1
88 #define CL_CONTEXT_DIAGNOSTICS_LEVEL_BAD_INTEL 0x2
89 #define CL_CONTEXT_DIAGNOSTICS_LEVEL_NEUTRAL_INTEL 0x4
92 /*! \brief This parameter should be determined heuristically from the
93 * kernel execution times
95 * This value is best for small systems on a single AMD Radeon R9 290X
96 * (and about 5% faster than 40, which is the default for CUDA
97 * devices). Larger simulation systems were quite insensitive to the
98 * value of this parameter.
100 static unsigned int gpu_min_ci_balanced_factor = 50;
103 /*! \brief Initializes the atomdata structure first time, it only gets filled at
106 static void init_atomdata_first(cl_atomdata_t* ad, int ntypes, const DeviceContext& deviceContext)
110 allocateDeviceBuffer(&ad->shift_vec, SHIFTS * DIM, deviceContext);
111 ad->bShiftVecUploaded = CL_FALSE;
113 allocateDeviceBuffer(&ad->fshift, SHIFTS * DIM, deviceContext);
114 allocateDeviceBuffer(&ad->e_lj, 1, deviceContext);
115 allocateDeviceBuffer(&ad->e_el, 1, deviceContext);
117 /* initialize to nullptr pointers to data that is not allocated here and will
118 need reallocation in nbnxn_gpu_init_atomdata */
122 /* size -1 indicates that the respective array hasn't been initialized yet */
127 /*! \brief Returns the kinds of electrostatics and Vdw OpenCL
128 * kernels that will be used.
130 * Respectively, these values are from enum eelOcl and enum
132 static void map_interaction_types_to_gpu_kernel_flavors(const interaction_const_t* ic,
137 if (ic->vdwtype == evdwCUT)
139 switch (ic->vdw_modifier)
142 case eintmodPOTSHIFT:
145 case ljcrNONE: *gpu_vdwtype = evdwTypeCUT; break;
146 case ljcrGEOM: *gpu_vdwtype = evdwTypeCUTCOMBGEOM; break;
147 case ljcrLB: *gpu_vdwtype = evdwTypeCUTCOMBLB; break;
150 "The requested LJ combination rule is not implemented in the "
151 "OpenCL GPU accelerated kernels!");
154 case eintmodFORCESWITCH: *gpu_vdwtype = evdwTypeFSWITCH; break;
155 case eintmodPOTSWITCH: *gpu_vdwtype = evdwTypePSWITCH; break;
158 "The requested VdW interaction modifier is not implemented in the GPU "
159 "accelerated kernels!");
162 else if (ic->vdwtype == evdwPME)
164 if (ic->ljpme_comb_rule == ljcrGEOM)
166 *gpu_vdwtype = evdwTypeEWALDGEOM;
170 *gpu_vdwtype = evdwTypeEWALDLB;
175 gmx_incons("The requested VdW type is not implemented in the GPU accelerated kernels!");
178 if (ic->eeltype == eelCUT)
180 *gpu_eeltype = eelTypeCUT;
182 else if (EEL_RF(ic->eeltype))
184 *gpu_eeltype = eelTypeRF;
186 else if ((EEL_PME(ic->eeltype) || ic->eeltype == eelEWALD))
188 *gpu_eeltype = nbnxn_gpu_pick_ewald_kernel_type(*ic);
192 /* Shouldn't happen, as this is checked when choosing Verlet-scheme */
194 "The requested electrostatics type is not implemented in the GPU accelerated "
199 /*! \brief Initializes the nonbonded parameter data structure.
201 static void init_nbparam(NBParamGpu* nbp,
202 const interaction_const_t* ic,
203 const PairlistParams& listParams,
204 const nbnxn_atomdata_t::Params& nbatParams,
205 const DeviceContext& deviceContext)
207 set_cutoff_parameters(nbp, ic, listParams);
209 map_interaction_types_to_gpu_kernel_flavors(ic, nbatParams.comb_rule, &(nbp->eeltype), &(nbp->vdwtype));
211 if (ic->vdwtype == evdwPME)
213 if (ic->ljpme_comb_rule == ljcrGEOM)
215 GMX_ASSERT(nbatParams.comb_rule == ljcrGEOM, "Combination rule mismatch!");
219 GMX_ASSERT(nbatParams.comb_rule == ljcrLB, "Combination rule mismatch!");
222 /* generate table for PME */
223 nbp->coulomb_tab = nullptr;
224 if (nbp->eeltype == eelTypeEWALD_TAB || nbp->eeltype == eelTypeEWALD_TAB_TWIN)
226 GMX_RELEASE_ASSERT(ic->coulombEwaldTables, "Need valid Coulomb Ewald correction tables");
227 init_ewald_coulomb_force_table(*ic->coulombEwaldTables, nbp, deviceContext);
231 allocateDeviceBuffer(&nbp->coulomb_tab, 1, deviceContext);
234 const int nnbfp = 2 * nbatParams.numTypes * nbatParams.numTypes;
235 const int nnbfp_comb = 2 * nbatParams.numTypes;
238 /* set up LJ parameter lookup table */
239 DeviceBuffer<real> nbfp;
240 initParamLookupTable(&nbfp, nullptr, nbatParams.nbfp.data(), nnbfp, deviceContext);
243 if (ic->vdwtype == evdwPME)
245 DeviceBuffer<float> nbfp_comb;
246 initParamLookupTable(&nbfp_comb, nullptr, nbatParams.nbfp_comb.data(), nnbfp_comb, deviceContext);
247 nbp->nbfp_comb = nbfp_comb;
252 /*! \brief Initializes the OpenCL kernel pointers of the nbnxn_ocl_ptr_t input data structure. */
253 static cl_kernel nbnxn_gpu_create_kernel(NbnxmGpu* nb, const char* kernel_name)
258 kernel = clCreateKernel(nb->dev_rundata->program, kernel_name, &cl_error);
259 if (CL_SUCCESS != cl_error)
261 gmx_fatal(FARGS, "Failed to create kernel '%s' for GPU #%s: OpenCL error %d", kernel_name,
262 nb->deviceContext_->deviceInfo().device_name, cl_error);
268 /*! \brief Clears nonbonded shift force output array and energy outputs on the GPU.
270 static void nbnxn_ocl_clear_e_fshift(NbnxmGpu* nb)
274 cl_atomdata_t* adat = nb->atdat;
275 cl_command_queue ls = nb->deviceStreams[InteractionLocality::Local]->stream();
277 size_t local_work_size[3] = { 1, 1, 1 };
278 size_t global_work_size[3] = { 1, 1, 1 };
280 cl_int shifts = SHIFTS * 3;
284 cl_kernel zero_e_fshift = nb->kernel_zero_e_fshift;
286 local_work_size[0] = 64;
287 // Round the total number of threads up from the array size
288 global_work_size[0] = ((shifts + local_work_size[0] - 1) / local_work_size[0]) * local_work_size[0];
291 cl_error = clSetKernelArg(zero_e_fshift, arg_no++, sizeof(cl_mem), &(adat->fshift));
292 cl_error |= clSetKernelArg(zero_e_fshift, arg_no++, sizeof(cl_mem), &(adat->e_lj));
293 cl_error |= clSetKernelArg(zero_e_fshift, arg_no++, sizeof(cl_mem), &(adat->e_el));
294 cl_error |= clSetKernelArg(zero_e_fshift, arg_no++, sizeof(cl_uint), &shifts);
295 GMX_ASSERT(cl_error == CL_SUCCESS, ocl_get_error_string(cl_error).c_str());
297 cl_error = clEnqueueNDRangeKernel(ls, zero_e_fshift, 3, nullptr, global_work_size,
298 local_work_size, 0, nullptr, nullptr);
299 GMX_ASSERT(cl_error == CL_SUCCESS, ocl_get_error_string(cl_error).c_str());
302 /*! \brief Initializes the OpenCL kernel pointers of the nbnxn_ocl_ptr_t input data structure. */
303 static void nbnxn_gpu_init_kernels(NbnxmGpu* nb)
305 /* Init to 0 main kernel arrays */
306 /* They will be later on initialized in select_nbnxn_kernel */
307 // TODO: consider always creating all variants of the kernels here so that there is no
308 // need for late call to clCreateKernel -- if that gives any advantage?
309 memset(nb->kernel_ener_noprune_ptr, 0, sizeof(nb->kernel_ener_noprune_ptr));
310 memset(nb->kernel_ener_prune_ptr, 0, sizeof(nb->kernel_ener_prune_ptr));
311 memset(nb->kernel_noener_noprune_ptr, 0, sizeof(nb->kernel_noener_noprune_ptr));
312 memset(nb->kernel_noener_prune_ptr, 0, sizeof(nb->kernel_noener_prune_ptr));
314 /* Init pruning kernels
316 * TODO: we could avoid creating kernels if dynamic pruning is turned off,
317 * but ATM that depends on force flags not passed into the initialization.
319 nb->kernel_pruneonly[epruneFirst] = nbnxn_gpu_create_kernel(nb, "nbnxn_kernel_prune_opencl");
320 nb->kernel_pruneonly[epruneRolling] =
321 nbnxn_gpu_create_kernel(nb, "nbnxn_kernel_prune_rolling_opencl");
323 /* Init auxiliary kernels */
324 nb->kernel_zero_e_fshift = nbnxn_gpu_create_kernel(nb, "zero_e_fshift");
327 /*! \brief Initializes simulation constant data.
329 * Initializes members of the atomdata and nbparam structs and
330 * clears e/fshift output buffers.
332 static void nbnxn_ocl_init_const(cl_atomdata_t* atomData,
333 NBParamGpu* nbParams,
334 const interaction_const_t* ic,
335 const PairlistParams& listParams,
336 const nbnxn_atomdata_t::Params& nbatParams,
337 const DeviceContext& deviceContext)
339 init_atomdata_first(atomData, nbatParams.numTypes, deviceContext);
340 init_nbparam(nbParams, ic, listParams, nbatParams, deviceContext);
344 //! This function is documented in the header file
345 NbnxmGpu* gpu_init(const gmx::DeviceStreamManager& deviceStreamManager,
346 const interaction_const_t* ic,
347 const PairlistParams& listParams,
348 const nbnxn_atomdata_t* nbat,
349 const bool bLocalAndNonlocal)
351 GMX_ASSERT(ic, "Need a valid interaction constants object");
353 auto nb = new NbnxmGpu();
354 nb->deviceContext_ = &deviceStreamManager.context();
356 snew(nb->nbparam, 1);
357 snew(nb->plist[InteractionLocality::Local], 1);
358 if (bLocalAndNonlocal)
360 snew(nb->plist[InteractionLocality::NonLocal], 1);
363 nb->bUseTwoStreams = bLocalAndNonlocal;
365 nb->timers = new cl_timers_t();
366 snew(nb->timings, 1);
368 /* set device info, just point it to the right GPU among the detected ones */
369 nb->dev_rundata = new gmx_device_runtime_data_t();
372 pmalloc(reinterpret_cast<void**>(&nb->nbst.e_lj), sizeof(*nb->nbst.e_lj));
373 pmalloc(reinterpret_cast<void**>(&nb->nbst.e_el), sizeof(*nb->nbst.e_el));
374 pmalloc(reinterpret_cast<void**>(&nb->nbst.fshift), SHIFTS * sizeof(*nb->nbst.fshift));
376 init_plist(nb->plist[InteractionLocality::Local]);
378 /* OpenCL timing disabled if GMX_DISABLE_GPU_TIMING is defined. */
379 nb->bDoTime = (getenv("GMX_DISABLE_GPU_TIMING") == nullptr);
381 /* local/non-local GPU streams */
382 GMX_RELEASE_ASSERT(deviceStreamManager.streamIsValid(gmx::DeviceStreamType::NonBondedLocal),
383 "Local non-bonded stream should be initialized to use GPU for non-bonded.");
384 nb->deviceStreams[InteractionLocality::Local] =
385 &deviceStreamManager.stream(gmx::DeviceStreamType::NonBondedLocal);
387 if (nb->bUseTwoStreams)
389 init_plist(nb->plist[InteractionLocality::NonLocal]);
391 GMX_RELEASE_ASSERT(deviceStreamManager.streamIsValid(gmx::DeviceStreamType::NonBondedNonLocal),
392 "Non-local non-bonded stream should be initialized to use GPU for "
393 "non-bonded with domain decomposition.");
394 nb->deviceStreams[InteractionLocality::NonLocal] =
395 &deviceStreamManager.stream(gmx::DeviceStreamType::NonBondedNonLocal);
400 init_timings(nb->timings);
403 nbnxn_ocl_init_const(nb->atdat, nb->nbparam, ic, listParams, nbat->params(), *nb->deviceContext_);
405 /* Enable LJ param manual prefetch for AMD or Intel or if we request through env. var.
406 * TODO: decide about NVIDIA
408 nb->bPrefetchLjParam = (getenv("GMX_OCL_DISABLE_I_PREFETCH") == nullptr)
409 && ((nb->deviceContext_->deviceInfo().deviceVendor == DeviceVendor::Amd)
410 || (nb->deviceContext_->deviceInfo().deviceVendor == DeviceVendor::Intel)
411 || (getenv("GMX_OCL_ENABLE_I_PREFETCH") != nullptr));
413 /* NOTE: in CUDA we pick L1 cache configuration for the nbnxn kernels here,
414 * but sadly this is not supported in OpenCL (yet?). Consider adding it if
415 * it becomes supported.
417 nbnxn_gpu_compile_kernels(nb);
418 nbnxn_gpu_init_kernels(nb);
420 /* clear energy and shift force outputs */
421 nbnxn_ocl_clear_e_fshift(nb);
425 fprintf(debug, "Initialized OpenCL data structures.\n");
431 /*! \brief Clears the first natoms_clear elements of the GPU nonbonded force output array.
433 static void nbnxn_ocl_clear_f(NbnxmGpu* nb, int natoms_clear)
435 if (natoms_clear == 0)
440 cl_atomdata_t* atomData = nb->atdat;
441 const DeviceStream& localStream = *nb->deviceStreams[InteractionLocality::Local];
443 clearDeviceBufferAsync(&atomData->f, 0, natoms_clear * DIM, localStream);
446 //! This function is documented in the header file
447 void gpu_clear_outputs(NbnxmGpu* nb, bool computeVirial)
449 nbnxn_ocl_clear_f(nb, nb->atdat->natoms);
450 /* clear shift force array and energies if the outputs were
451 used in the current step */
454 nbnxn_ocl_clear_e_fshift(nb);
457 /* kick off buffer clearing kernel to ensure concurrency with constraints/update */
458 cl_int gmx_unused cl_error;
459 cl_error = clFlush(nb->deviceStreams[InteractionLocality::Local]->stream());
460 GMX_ASSERT(cl_error == CL_SUCCESS, ("clFlush failed: " + ocl_get_error_string(cl_error)).c_str());
463 //! This function is documented in the header file
464 void gpu_upload_shiftvec(NbnxmGpu* nb, const nbnxn_atomdata_t* nbatom)
466 cl_atomdata_t* adat = nb->atdat;
467 const DeviceStream& deviceStream = *nb->deviceStreams[InteractionLocality::Local];
469 /* only if we have a dynamic box */
470 if (nbatom->bDynamicBox || !adat->bShiftVecUploaded)
472 GMX_ASSERT(sizeof(float) * DIM == sizeof(*nbatom->shift_vec.data()),
473 "Sizes of host- and device-side shift vectors should be the same.");
474 copyToDeviceBuffer(&adat->shift_vec, reinterpret_cast<const float*>(nbatom->shift_vec.data()),
475 0, SHIFTS * DIM, deviceStream, GpuApiCallBehavior::Async, nullptr);
476 adat->bShiftVecUploaded = CL_TRUE;
480 //! This function is documented in the header file
481 void gpu_init_atomdata(NbnxmGpu* nb, const nbnxn_atomdata_t* nbat)
486 bool bDoTime = nb->bDoTime;
487 cl_timers_t* timers = nb->timers;
488 cl_atomdata_t* d_atdat = nb->atdat;
489 const DeviceContext& deviceContext = *nb->deviceContext_;
490 const DeviceStream& deviceStream = *nb->deviceStreams[InteractionLocality::Local];
492 natoms = nbat->numAtoms();
497 /* time async copy */
498 timers->atdat.openTimingRegion(deviceStream);
501 /* need to reallocate if we have to copy more atoms than the amount of space
502 available and only allocate if we haven't initialized yet, i.e d_atdat->natoms == -1 */
503 if (natoms > d_atdat->nalloc)
505 nalloc = over_alloc_small(natoms);
507 /* free up first if the arrays have already been initialized */
508 if (d_atdat->nalloc != -1)
510 freeDeviceBuffer(&d_atdat->f);
511 freeDeviceBuffer(&d_atdat->xq);
512 freeDeviceBuffer(&d_atdat->lj_comb);
513 freeDeviceBuffer(&d_atdat->atom_types);
517 allocateDeviceBuffer(&d_atdat->f, nalloc * DIM, deviceContext);
518 allocateDeviceBuffer(&d_atdat->xq, nalloc * (DIM + 1), deviceContext);
520 if (useLjCombRule(nb->nbparam->vdwtype))
522 // Two Lennard-Jones parameters per atom
523 allocateDeviceBuffer(&d_atdat->lj_comb, nalloc * 2, deviceContext);
527 allocateDeviceBuffer(&d_atdat->atom_types, nalloc, deviceContext);
530 d_atdat->nalloc = nalloc;
534 d_atdat->natoms = natoms;
535 d_atdat->natoms_local = nbat->natoms_local;
537 /* need to clear GPU f output if realloc happened */
540 nbnxn_ocl_clear_f(nb, nalloc);
543 if (useLjCombRule(nb->nbparam->vdwtype))
545 GMX_ASSERT(sizeof(float) == sizeof(*nbat->params().lj_comb.data()),
546 "Size of the LJ parameters element should be equal to the size of float2.");
547 copyToDeviceBuffer(&d_atdat->lj_comb, nbat->params().lj_comb.data(), 0, 2 * natoms,
548 deviceStream, GpuApiCallBehavior::Async,
549 bDoTime ? timers->atdat.fetchNextEvent() : nullptr);
553 GMX_ASSERT(sizeof(int) == sizeof(*nbat->params().type.data()),
554 "Sizes of host- and device-side atom types should be the same.");
555 copyToDeviceBuffer(&d_atdat->atom_types, nbat->params().type.data(), 0, natoms, deviceStream,
556 GpuApiCallBehavior::Async, bDoTime ? timers->atdat.fetchNextEvent() : nullptr);
561 timers->atdat.closeTimingRegion(deviceStream);
564 /* kick off the tasks enqueued above to ensure concurrency with the search */
565 cl_error = clFlush(deviceStream.stream());
566 GMX_RELEASE_ASSERT(cl_error == CL_SUCCESS,
567 ("clFlush failed: " + ocl_get_error_string(cl_error)).c_str());
570 /*! \brief Releases an OpenCL kernel pointer */
571 static void free_kernel(cl_kernel* kernel_ptr)
573 cl_int gmx_unused cl_error;
575 GMX_ASSERT(kernel_ptr, "Need a valid kernel pointer");
579 cl_error = clReleaseKernel(*kernel_ptr);
580 GMX_RELEASE_ASSERT(cl_error == CL_SUCCESS,
581 ("clReleaseKernel failed: " + ocl_get_error_string(cl_error)).c_str());
583 *kernel_ptr = nullptr;
587 /*! \brief Releases a list of OpenCL kernel pointers */
588 static void free_kernels(cl_kernel* kernels, int count)
592 for (i = 0; i < count; i++)
594 free_kernel(kernels + i);
598 /*! \brief Free the OpenCL program.
600 * The function releases the OpenCL program assuciated with the
601 * device that the calling PP rank is running on.
603 * \param program [in] OpenCL program to release.
605 static void freeGpuProgram(cl_program program)
609 cl_int cl_error = clReleaseProgram(program);
610 GMX_RELEASE_ASSERT(cl_error == CL_SUCCESS,
611 ("clReleaseProgram failed: " + ocl_get_error_string(cl_error)).c_str());
616 //! This function is documented in the header file
617 void gpu_free(NbnxmGpu* nb)
625 // NOLINTNEXTLINE(bugprone-sizeof-expression)
626 int kernel_count = sizeof(nb->kernel_ener_noprune_ptr) / sizeof(nb->kernel_ener_noprune_ptr[0][0]);
627 free_kernels(nb->kernel_ener_noprune_ptr[0], kernel_count);
629 // NOLINTNEXTLINE(bugprone-sizeof-expression)
630 kernel_count = sizeof(nb->kernel_ener_prune_ptr) / sizeof(nb->kernel_ener_prune_ptr[0][0]);
631 free_kernels(nb->kernel_ener_prune_ptr[0], kernel_count);
633 // NOLINTNEXTLINE(bugprone-sizeof-expression)
634 kernel_count = sizeof(nb->kernel_noener_noprune_ptr) / sizeof(nb->kernel_noener_noprune_ptr[0][0]);
635 free_kernels(nb->kernel_noener_noprune_ptr[0], kernel_count);
637 // NOLINTNEXTLINE(bugprone-sizeof-expression)
638 kernel_count = sizeof(nb->kernel_noener_prune_ptr) / sizeof(nb->kernel_noener_prune_ptr[0][0]);
639 free_kernels(nb->kernel_noener_prune_ptr[0], kernel_count);
641 free_kernel(&(nb->kernel_zero_e_fshift));
644 freeDeviceBuffer(&(nb->atdat->xq));
645 freeDeviceBuffer(&(nb->atdat->f));
646 freeDeviceBuffer(&(nb->atdat->e_lj));
647 freeDeviceBuffer(&(nb->atdat->e_el));
648 freeDeviceBuffer(&(nb->atdat->fshift));
649 freeDeviceBuffer(&(nb->atdat->lj_comb));
650 freeDeviceBuffer(&(nb->atdat->atom_types));
651 freeDeviceBuffer(&(nb->atdat->shift_vec));
655 freeDeviceBuffer(&(nb->nbparam->nbfp));
656 freeDeviceBuffer(&(nb->nbparam->nbfp_comb));
657 freeDeviceBuffer(&(nb->nbparam->coulomb_tab));
661 auto* plist = nb->plist[InteractionLocality::Local];
662 freeDeviceBuffer(&plist->sci);
663 freeDeviceBuffer(&plist->cj4);
664 freeDeviceBuffer(&plist->imask);
665 freeDeviceBuffer(&plist->excl);
667 if (nb->bUseTwoStreams)
669 auto* plist_nl = nb->plist[InteractionLocality::NonLocal];
670 freeDeviceBuffer(&plist_nl->sci);
671 freeDeviceBuffer(&plist_nl->cj4);
672 freeDeviceBuffer(&plist_nl->imask);
673 freeDeviceBuffer(&plist_nl->excl);
678 pfree(nb->nbst.e_lj);
679 nb->nbst.e_lj = nullptr;
681 pfree(nb->nbst.e_el);
682 nb->nbst.e_el = nullptr;
684 pfree(nb->nbst.fshift);
685 nb->nbst.fshift = nullptr;
687 /* Free other events */
688 if (nb->nonlocal_done)
690 clReleaseEvent(nb->nonlocal_done);
691 nb->nonlocal_done = nullptr;
693 if (nb->misc_ops_and_local_H2D_done)
695 clReleaseEvent(nb->misc_ops_and_local_H2D_done);
696 nb->misc_ops_and_local_H2D_done = nullptr;
699 freeGpuProgram(nb->dev_rundata->program);
700 delete nb->dev_rundata;
702 /* Free timers and timings */
709 fprintf(debug, "Cleaned up OpenCL data structures.\n");
713 //! This function is documented in the header file
714 int gpu_min_ci_balanced(NbnxmGpu* nb)
716 return nb != nullptr ? gpu_min_ci_balanced_factor * nb->deviceContext_->deviceInfo().compute_units : 0;