CudaPlatform.cpp 4.07 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
/* -------------------------------------------------------------------------- *
 *                                   OpenMM                                   *
 * -------------------------------------------------------------------------- *
 * This is part of the OpenMM molecular simulation toolkit originating from   *
 * Simbios, the NIH National Center for Physics-Based Simulation of           *
 * Biological Structures at Stanford, funded under the NIH Roadmap for        *
 * Medical Research, grant U54 GM072970. See https://simtk.org.               *
 *                                                                            *
 * Portions copyright (c) 2008 Stanford University and the Authors.           *
 * Authors: Peter Eastman                                                     *
 * Contributors:                                                              *
 *                                                                            *
13
14
15
16
 * This program is free software: you can redistribute it and/or modify       *
 * it under the terms of the GNU Lesser General Public License as published   *
 * by the Free Software Foundation, either version 3 of the License, or       *
 * (at your option) any later version.                                        *
17
 *                                                                            *
18
19
20
21
 * This program is distributed in the hope that it will be useful,            *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
 * GNU Lesser General Public License for more details.                        *
22
 *                                                                            *
23
24
 * You should have received a copy of the GNU Lesser General Public License   *
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.      *
25
26
27
28
29
 * -------------------------------------------------------------------------- */

#include "CudaPlatform.h"
#include "CudaKernelFactory.h"
#include "CudaKernels.h"
30
31
#include "openmm/PluginInitializer.h"
#include "openmm/internal/OpenMMContextImpl.h"
32
#include "kernels/gputypes.h"
33
#include "openmm/System.h"
34

35
36
using namespace OpenMM;

37
extern "C" void initOpenMMPlugin() {
Peter Eastman's avatar
Peter Eastman committed
38
39
    if (gpuIsAvailable())
        Platform::registerPlatform(new CudaPlatform());
40
41
}

42
43
CudaPlatform::CudaPlatform() {
    CudaKernelFactory* factory = new CudaKernelFactory();
44
    registerKernelFactory(InitializeForcesKernel::Name(), factory);
45
    registerKernelFactory(UpdateTimeKernel::Name(), factory);
46
47
48
49
50
    registerKernelFactory(CalcHarmonicBondForceKernel::Name(), factory);
    registerKernelFactory(CalcHarmonicAngleForceKernel::Name(), factory);
    registerKernelFactory(CalcPeriodicTorsionForceKernel::Name(), factory);
    registerKernelFactory(CalcRBTorsionForceKernel::Name(), factory);
    registerKernelFactory(CalcNonbondedForceKernel::Name(), factory);
51
    registerKernelFactory(CalcGBSAOBCForceKernel::Name(), factory);
52
    registerKernelFactory(IntegrateVerletStepKernel::Name(), factory);
53
    registerKernelFactory(IntegrateLangevinStepKernel::Name(), factory);
54
    registerKernelFactory(IntegrateBrownianStepKernel::Name(), factory);
55
    registerKernelFactory(IntegrateVariableVerletStepKernel::Name(), factory);
56
    registerKernelFactory(ApplyAndersenThermostatKernel::Name(), factory);
57
    registerKernelFactory(CalcKineticEnergyKernel::Name(), factory);
58
    registerKernelFactory(RemoveCMMotionKernel::Name(), factory);
59
60
61
62
63
64
65
66
67
68
69
}

bool CudaPlatform::supportsDoublePrecision() const {
    return false;
}

const StreamFactory& CudaPlatform::getDefaultStreamFactory() const {
    return defaultStreamFactory;
}

void CudaPlatform::contextCreated(OpenMMContextImpl& context) const {
Peter Eastman's avatar
Peter Eastman committed
70
71
    int numParticles = context.getSystem().getNumParticles();
    _gpuContext* gpu = (_gpuContext*) gpuInit(numParticles);
72
    context.setPlatformData(new PlatformData(gpu));
73
74
75
}

void CudaPlatform::contextDestroyed(OpenMMContextImpl& context) const {
76
77
78
    PlatformData* data = reinterpret_cast<PlatformData*>(context.getPlatformData());
    gpuShutDown(data->gpu);
    delete data;
79
}