OpenCLKernelFactory.cpp 9.71 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-2019 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 "OpenCLKernelFactory.h"
28
#include "OpenCLParallelKernels.h"
29
#include "openmm/common/CommonKernels.h"
30
31
32
33
34
35
36
#include "openmm/internal/ContextImpl.h"
#include "openmm/OpenMMException.h"

using namespace OpenMM;

KernelImpl* OpenCLKernelFactory::createKernelImpl(std::string name, const Platform& platform, ContextImpl& context) const {
    OpenCLPlatform::PlatformData& data = *static_cast<OpenCLPlatform::PlatformData*>(context.getPlatformData());
Peter Eastman's avatar
Bug fix  
Peter Eastman committed
37
    if (data.contexts.size() > 1) {
38
39
40
41
42
43
        // We are running in parallel on multiple devices, so we may want to create a parallel kernel.
        
        if (name == CalcForcesAndEnergyKernel::Name())
            return new OpenCLParallelCalcForcesAndEnergyKernel(name, platform, data);
        if (name == CalcHarmonicBondForceKernel::Name())
            return new OpenCLParallelCalcHarmonicBondForceKernel(name, platform, data, context.getSystem());
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
        if (name == CalcCustomBondForceKernel::Name())
            return new OpenCLParallelCalcCustomBondForceKernel(name, platform, data, context.getSystem());
        if (name == CalcHarmonicAngleForceKernel::Name())
            return new OpenCLParallelCalcHarmonicAngleForceKernel(name, platform, data, context.getSystem());
        if (name == CalcCustomAngleForceKernel::Name())
            return new OpenCLParallelCalcCustomAngleForceKernel(name, platform, data, context.getSystem());
        if (name == CalcPeriodicTorsionForceKernel::Name())
            return new OpenCLParallelCalcPeriodicTorsionForceKernel(name, platform, data, context.getSystem());
        if (name == CalcRBTorsionForceKernel::Name())
            return new OpenCLParallelCalcRBTorsionForceKernel(name, platform, data, context.getSystem());
        if (name == CalcCMAPTorsionForceKernel::Name())
            return new OpenCLParallelCalcCMAPTorsionForceKernel(name, platform, data, context.getSystem());
        if (name == CalcCustomTorsionForceKernel::Name())
            return new OpenCLParallelCalcCustomTorsionForceKernel(name, platform, data, context.getSystem());
        if (name == CalcNonbondedForceKernel::Name())
            return new OpenCLParallelCalcNonbondedForceKernel(name, platform, data, context.getSystem());
60
61
        if (name == CalcCustomNonbondedForceKernel::Name())
            return new OpenCLParallelCalcCustomNonbondedForceKernel(name, platform, data, context.getSystem());
62
63
64
65
        if (name == CalcCustomExternalForceKernel::Name())
            return new OpenCLParallelCalcCustomExternalForceKernel(name, platform, data, context.getSystem());
        if (name == CalcCustomHbondForceKernel::Name())
            return new OpenCLParallelCalcCustomHbondForceKernel(name, platform, data, context.getSystem());
66
67
        if (name == CalcCustomCompoundBondForceKernel::Name())
            return new OpenCLParallelCalcCustomCompoundBondForceKernel(name, platform, data, context.getSystem());
68
69
    }
    OpenCLContext& cl = *data.contexts[0];
70
    if (name == CalcForcesAndEnergyKernel::Name())
71
        return new OpenCLCalcForcesAndEnergyKernel(name, platform, cl);
72
    if (name == UpdateStateDataKernel::Name())
73
        return new OpenCLUpdateStateDataKernel(name, platform, cl);
74
75
    if (name == ApplyConstraintsKernel::Name())
        return new OpenCLApplyConstraintsKernel(name, platform, cl);
76
77
    if (name == VirtualSitesKernel::Name())
        return new OpenCLVirtualSitesKernel(name, platform, cl);
78
    if (name == CalcHarmonicBondForceKernel::Name())
79
        return new CommonCalcHarmonicBondForceKernel(name, platform, cl, context.getSystem());
80
    if (name == CalcCustomBondForceKernel::Name())
81
        return new CommonCalcCustomBondForceKernel(name, platform, cl, context.getSystem());
82
    if (name == CalcHarmonicAngleForceKernel::Name())
83
        return new CommonCalcHarmonicAngleForceKernel(name, platform, cl, context.getSystem());
84
    if (name == CalcCustomAngleForceKernel::Name())
85
        return new CommonCalcCustomAngleForceKernel(name, platform, cl, context.getSystem());
86
    if (name == CalcPeriodicTorsionForceKernel::Name())
87
        return new CommonCalcPeriodicTorsionForceKernel(name, platform, cl, context.getSystem());
88
    if (name == CalcRBTorsionForceKernel::Name())
89
        return new CommonCalcRBTorsionForceKernel(name, platform, cl, context.getSystem());
90
    if (name == CalcCMAPTorsionForceKernel::Name())
91
        return new CommonCalcCMAPTorsionForceKernel(name, platform, cl, context.getSystem());
92
    if (name == CalcCustomTorsionForceKernel::Name())
93
        return new CommonCalcCustomTorsionForceKernel(name, platform, cl, context.getSystem());
94
95
    if (name == CalcNonbondedForceKernel::Name())
        return new OpenCLCalcNonbondedForceKernel(name, platform, cl, context.getSystem());
96
    if (name == CalcCustomNonbondedForceKernel::Name())
97
        return new CommonCalcCustomNonbondedForceKernel(name, platform, cl, context.getSystem());
98
    if (name == CalcGBSAOBCForceKernel::Name())
99
        return new CommonCalcGBSAOBCForceKernel(name, platform, cl);
100
    if (name == CalcCustomGBForceKernel::Name())
101
        return new CommonCalcCustomGBForceKernel(name, platform, cl, context.getSystem());
102
    if (name == CalcCustomExternalForceKernel::Name())
103
        return new CommonCalcCustomExternalForceKernel(name, platform, cl, context.getSystem());
104
    if (name == CalcCustomHbondForceKernel::Name())
105
        return new CommonCalcCustomHbondForceKernel(name, platform, cl, context.getSystem());
106
    if (name == CalcCustomCentroidBondForceKernel::Name())
107
        return new CommonCalcCustomCentroidBondForceKernel(name, platform, cl, context.getSystem());
108
    if (name == CalcCustomCompoundBondForceKernel::Name())
109
        return new CommonCalcCustomCompoundBondForceKernel(name, platform, cl, context.getSystem());
110
111
    if (name == CalcCustomCVForceKernel::Name())
        return new OpenCLCalcCustomCVForceKernel(name, platform, cl);
peastman's avatar
peastman committed
112
    if (name == CalcRMSDForceKernel::Name())
113
        return new CommonCalcRMSDForceKernel(name, platform, cl);
114
    if (name == CalcCustomManyParticleForceKernel::Name())
115
        return new CommonCalcCustomManyParticleForceKernel(name, platform, cl, context.getSystem());
116
    if (name == CalcGayBerneForceKernel::Name())
117
        return new CommonCalcGayBerneForceKernel(name, platform, cl);
118
    if (name == IntegrateVerletStepKernel::Name())
119
        return new CommonIntegrateVerletStepKernel(name, platform, cl);
120
    if (name == IntegrateLangevinStepKernel::Name())
121
        return new CommonIntegrateLangevinStepKernel(name, platform, cl);
122
123
    if (name == IntegrateLangevinMiddleStepKernel::Name())
        return new CommonIntegrateLangevinMiddleStepKernel(name, platform, cl);
124
    if (name == IntegrateBrownianStepKernel::Name())
125
        return new CommonIntegrateBrownianStepKernel(name, platform, cl);
126
    if (name == IntegrateVariableVerletStepKernel::Name())
127
        return new CommonIntegrateVariableVerletStepKernel(name, platform, cl);
128
    if (name == IntegrateVariableLangevinStepKernel::Name())
129
        return new CommonIntegrateVariableLangevinStepKernel(name, platform, cl);
130
    if (name == IntegrateCustomStepKernel::Name())
131
        return new CommonIntegrateCustomStepKernel(name, platform, cl);
132
    if (name == ApplyAndersenThermostatKernel::Name())
133
        return new CommonApplyAndersenThermostatKernel(name, platform, cl);
134
    if (name == NoseHooverChainKernel::Name())
135
        return new CommonNoseHooverChainKernel(name, platform, cl);
136
    if (name == IntegrateVelocityVerletStepKernel::Name())
137
        return new CommonIntegrateVelocityVerletStepKernel(name, platform, cl);
138
139
    if (name == ApplyMonteCarloBarostatKernel::Name())
        return new OpenCLApplyMonteCarloBarostatKernel(name, platform, cl);
140
    if (name == RemoveCMMotionKernel::Name())
141
        return new CommonRemoveCMMotionKernel(name, platform, cl);
142
143
    throw OpenMMException((std::string("Tried to create kernel with illegal kernel name '")+name+"'").c_str());
}