CudaKernelFactory.cpp 9.7 KB
Newer Older
1
2
3
4
5
6
7
8
/* -------------------------------------------------------------------------- *
 *                                   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.               *
 *                                                                            *
9
 * Portions copyright (c) 2008-2024 Stanford University and the Authors.      *
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 * Authors: Peter Eastman                                                     *
 * Contributors:                                                              *
 *                                                                            *
 * 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.                                        *
 *                                                                            *
 * 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.                        *
 *                                                                            *
 * 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/>.      *
 * -------------------------------------------------------------------------- */

#include "CudaKernelFactory.h"
28
#include "CudaKernels.h"
29
#include "CudaParallelKernels.h"
30
#include "CudaPlatform.h"
31
#include "openmm/common/CommonKernels.h"
32
33
34
35
36
37
38
#include "openmm/internal/ContextImpl.h"
#include "openmm/OpenMMException.h"

using namespace OpenMM;

KernelImpl* CudaKernelFactory::createKernelImpl(std::string name, const Platform& platform, ContextImpl& context) const {
    CudaPlatform::PlatformData& data = *static_cast<CudaPlatform::PlatformData*>(context.getPlatformData());
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
    if (data.contexts.size() > 1) {
        // We are running in parallel on multiple devices, so we may want to create a parallel kernel.
        
        if (name == CalcForcesAndEnergyKernel::Name())
            return new CudaParallelCalcForcesAndEnergyKernel(name, platform, data);
        if (name == CalcHarmonicBondForceKernel::Name())
            return new CudaParallelCalcHarmonicBondForceKernel(name, platform, data, context.getSystem());
        if (name == CalcCustomBondForceKernel::Name())
            return new CudaParallelCalcCustomBondForceKernel(name, platform, data, context.getSystem());
        if (name == CalcHarmonicAngleForceKernel::Name())
            return new CudaParallelCalcHarmonicAngleForceKernel(name, platform, data, context.getSystem());
        if (name == CalcCustomAngleForceKernel::Name())
            return new CudaParallelCalcCustomAngleForceKernel(name, platform, data, context.getSystem());
        if (name == CalcPeriodicTorsionForceKernel::Name())
            return new CudaParallelCalcPeriodicTorsionForceKernel(name, platform, data, context.getSystem());
        if (name == CalcRBTorsionForceKernel::Name())
            return new CudaParallelCalcRBTorsionForceKernel(name, platform, data, context.getSystem());
        if (name == CalcCMAPTorsionForceKernel::Name())
            return new CudaParallelCalcCMAPTorsionForceKernel(name, platform, data, context.getSystem());
        if (name == CalcCustomTorsionForceKernel::Name())
            return new CudaParallelCalcCustomTorsionForceKernel(name, platform, data, context.getSystem());
        if (name == CalcNonbondedForceKernel::Name())
            return new CudaParallelCalcNonbondedForceKernel(name, platform, data, context.getSystem());
        if (name == CalcCustomNonbondedForceKernel::Name())
            return new CudaParallelCalcCustomNonbondedForceKernel(name, platform, data, context.getSystem());
        if (name == CalcCustomExternalForceKernel::Name())
            return new CudaParallelCalcCustomExternalForceKernel(name, platform, data, context.getSystem());
        if (name == CalcCustomHbondForceKernel::Name())
            return new CudaParallelCalcCustomHbondForceKernel(name, platform, data, context.getSystem());
        if (name == CalcCustomCompoundBondForceKernel::Name())
            return new CudaParallelCalcCustomCompoundBondForceKernel(name, platform, data, context.getSystem());
    }
71
72
73
74
    CudaContext& cu = *data.contexts[0];
    if (name == CalcForcesAndEnergyKernel::Name())
        return new CudaCalcForcesAndEnergyKernel(name, platform, cu);
    if (name == UpdateStateDataKernel::Name())
75
        return new CommonUpdateStateDataKernel(name, platform, cu);
76
    if (name == ApplyConstraintsKernel::Name())
77
        return new CommonApplyConstraintsKernel(name, platform, cu);
78
    if (name == VirtualSitesKernel::Name())
79
        return new CommonVirtualSitesKernel(name, platform, cu);
80
    if (name == CalcHarmonicBondForceKernel::Name())
81
        return new CommonCalcHarmonicBondForceKernel(name, platform, cu, context.getSystem());
82
    if (name == CalcCustomBondForceKernel::Name())
83
        return new CommonCalcCustomBondForceKernel(name, platform, cu, context.getSystem());
84
    if (name == CalcHarmonicAngleForceKernel::Name())
85
        return new CommonCalcHarmonicAngleForceKernel(name, platform, cu, context.getSystem());
86
    if (name == CalcCustomAngleForceKernel::Name())
87
        return new CommonCalcCustomAngleForceKernel(name, platform, cu, context.getSystem());
88
    if (name == CalcPeriodicTorsionForceKernel::Name())
89
        return new CommonCalcPeriodicTorsionForceKernel(name, platform, cu, context.getSystem());
90
    if (name == CalcRBTorsionForceKernel::Name())
91
        return new CommonCalcRBTorsionForceKernel(name, platform, cu, context.getSystem());
92
    if (name == CalcCMAPTorsionForceKernel::Name())
93
        return new CommonCalcCMAPTorsionForceKernel(name, platform, cu, context.getSystem());
94
    if (name == CalcCustomTorsionForceKernel::Name())
95
        return new CommonCalcCustomTorsionForceKernel(name, platform, cu, context.getSystem());
96
97
    if (name == CalcNonbondedForceKernel::Name())
        return new CudaCalcNonbondedForceKernel(name, platform, cu, context.getSystem());
98
    if (name == CalcCustomNonbondedForceKernel::Name())
99
        return new CommonCalcCustomNonbondedForceKernel(name, platform, cu, context.getSystem());
100
    if (name == CalcGBSAOBCForceKernel::Name())
101
        return new CommonCalcGBSAOBCForceKernel(name, platform, cu);
102
    if (name == CalcCustomGBForceKernel::Name())
103
        return new CommonCalcCustomGBForceKernel(name, platform, cu, context.getSystem());
104
    if (name == CalcCustomExternalForceKernel::Name())
105
        return new CommonCalcCustomExternalForceKernel(name, platform, cu, context.getSystem());
106
    if (name == CalcCustomHbondForceKernel::Name())
107
        return new CommonCalcCustomHbondForceKernel(name, platform, cu, context.getSystem());
108
    if (name == CalcCustomCentroidBondForceKernel::Name())
109
        return new CommonCalcCustomCentroidBondForceKernel(name, platform, cu, context.getSystem());
110
    if (name == CalcCustomCompoundBondForceKernel::Name())
111
        return new CommonCalcCustomCompoundBondForceKernel(name, platform, cu, context.getSystem());
112
113
    if (name == CalcCustomCVForceKernel::Name())
        return new CudaCalcCustomCVForceKernel(name, platform, cu);
114
115
    if (name == CalcATMForceKernel::Name())
        return new CudaCalcATMForceKernel(name, platform, cu);
116
117
    if (name == CalcCustomCPPForceKernel::Name())
        return new CommonCalcCustomCPPForceKernel(name, platform, context, cu);
118
    if (name == CalcRMSDForceKernel::Name())
119
        return new CommonCalcRMSDForceKernel(name, platform, cu);
120
    if (name == CalcCustomManyParticleForceKernel::Name())
121
        return new CommonCalcCustomManyParticleForceKernel(name, platform, cu, context.getSystem());
peastman's avatar
peastman committed
122
    if (name == CalcGayBerneForceKernel::Name())
123
        return new CommonCalcGayBerneForceKernel(name, platform, cu);
124
    if (name == IntegrateVerletStepKernel::Name())
125
        return new CommonIntegrateVerletStepKernel(name, platform, cu);
126
127
    if (name == IntegrateLangevinMiddleStepKernel::Name())
        return new CommonIntegrateLangevinMiddleStepKernel(name, platform, cu);
128
    if (name == IntegrateBrownianStepKernel::Name())
129
        return new CommonIntegrateBrownianStepKernel(name, platform, cu);
130
    if (name == IntegrateVariableVerletStepKernel::Name())
131
        return new CommonIntegrateVariableVerletStepKernel(name, platform, cu);
132
    if (name == IntegrateVariableLangevinStepKernel::Name())
133
        return new CommonIntegrateVariableLangevinStepKernel(name, platform, cu);
134
    if (name == IntegrateCustomStepKernel::Name())
135
        return new CommonIntegrateCustomStepKernel(name, platform, cu);
136
    if (name == ApplyAndersenThermostatKernel::Name())
137
        return new CommonApplyAndersenThermostatKernel(name, platform, cu);
138
139
    if (name == IntegrateNoseHooverStepKernel::Name())
        return new CommonIntegrateNoseHooverStepKernel(name, platform, cu);
140
    if (name == ApplyMonteCarloBarostatKernel::Name())
141
        return new CommonApplyMonteCarloBarostatKernel(name, platform, cu);
142
    if (name == RemoveCMMotionKernel::Name())
143
        return new CommonRemoveCMMotionKernel(name, platform, cu);
144
145
    throw OpenMMException((std::string("Tried to create kernel with illegal kernel name '")+name+"'").c_str());
}