OpenCLKernelFactory.cpp 9.18 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-2016 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
30
31
32
33
34
35
#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
36
    if (data.contexts.size() > 1) {
37
38
39
40
41
42
        // 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());
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
        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());
59
60
        if (name == CalcCustomNonbondedForceKernel::Name())
            return new OpenCLParallelCalcCustomNonbondedForceKernel(name, platform, data, context.getSystem());
61
62
63
64
        if (name == CalcCustomExternalForceKernel::Name())
            return new OpenCLParallelCalcCustomExternalForceKernel(name, platform, data, context.getSystem());
        if (name == CalcCustomHbondForceKernel::Name())
            return new OpenCLParallelCalcCustomHbondForceKernel(name, platform, data, context.getSystem());
65
66
        if (name == CalcCustomCompoundBondForceKernel::Name())
            return new OpenCLParallelCalcCustomCompoundBondForceKernel(name, platform, data, context.getSystem());
67
68
    }
    OpenCLContext& cl = *data.contexts[0];
69
    if (name == CalcForcesAndEnergyKernel::Name())
70
        return new OpenCLCalcForcesAndEnergyKernel(name, platform, cl);
71
    if (name == UpdateStateDataKernel::Name())
72
        return new OpenCLUpdateStateDataKernel(name, platform, cl);
73
74
    if (name == ApplyConstraintsKernel::Name())
        return new OpenCLApplyConstraintsKernel(name, platform, cl);
75
76
    if (name == VirtualSitesKernel::Name())
        return new OpenCLVirtualSitesKernel(name, platform, cl);
77
    if (name == CalcHarmonicBondForceKernel::Name())
78
        return new OpenCLCalcHarmonicBondForceKernel(name, platform, cl, context.getSystem());
79
80
    if (name == CalcCustomBondForceKernel::Name())
        return new OpenCLCalcCustomBondForceKernel(name, platform, cl, context.getSystem());
81
    if (name == CalcHarmonicAngleForceKernel::Name())
82
        return new OpenCLCalcHarmonicAngleForceKernel(name, platform, cl, context.getSystem());
83
84
    if (name == CalcCustomAngleForceKernel::Name())
        return new OpenCLCalcCustomAngleForceKernel(name, platform, cl, context.getSystem());
85
    if (name == CalcPeriodicTorsionForceKernel::Name())
86
        return new OpenCLCalcPeriodicTorsionForceKernel(name, platform, cl, context.getSystem());
87
    if (name == CalcRBTorsionForceKernel::Name())
88
        return new OpenCLCalcRBTorsionForceKernel(name, platform, cl, context.getSystem());
89
90
    if (name == CalcCMAPTorsionForceKernel::Name())
        return new OpenCLCalcCMAPTorsionForceKernel(name, platform, cl, context.getSystem());
91
92
    if (name == CalcCustomTorsionForceKernel::Name())
        return new OpenCLCalcCustomTorsionForceKernel(name, platform, cl, context.getSystem());
93
94
    if (name == CalcNonbondedForceKernel::Name())
        return new OpenCLCalcNonbondedForceKernel(name, platform, cl, context.getSystem());
95
96
    if (name == CalcCustomNonbondedForceKernel::Name())
        return new OpenCLCalcCustomNonbondedForceKernel(name, platform, cl, context.getSystem());
97
98
    if (name == CalcGBSAOBCForceKernel::Name())
        return new OpenCLCalcGBSAOBCForceKernel(name, platform, cl);
99
100
    if (name == CalcCustomGBForceKernel::Name())
        return new OpenCLCalcCustomGBForceKernel(name, platform, cl, context.getSystem());
101
102
    if (name == CalcCustomExternalForceKernel::Name())
        return new OpenCLCalcCustomExternalForceKernel(name, platform, cl, context.getSystem());
103
104
    if (name == CalcCustomHbondForceKernel::Name())
        return new OpenCLCalcCustomHbondForceKernel(name, platform, cl, context.getSystem());
105
106
    if (name == CalcCustomCentroidBondForceKernel::Name())
        return new OpenCLCalcCustomCentroidBondForceKernel(name, platform, cl, context.getSystem());
107
108
    if (name == CalcCustomCompoundBondForceKernel::Name())
        return new OpenCLCalcCustomCompoundBondForceKernel(name, platform, cl, context.getSystem());
109
110
    if (name == CalcCustomCVForceKernel::Name())
        return new OpenCLCalcCustomCVForceKernel(name, platform, cl);
111
112
    if (name == CalcCustomManyParticleForceKernel::Name())
        return new OpenCLCalcCustomManyParticleForceKernel(name, platform, cl, context.getSystem());
113
114
    if (name == CalcGayBerneForceKernel::Name())
        return new OpenCLCalcGayBerneForceKernel(name, platform, cl);
115
    if (name == IntegrateVerletStepKernel::Name())
116
        return new OpenCLIntegrateVerletStepKernel(name, platform, cl);
117
118
    if (name == IntegrateLangevinStepKernel::Name())
        return new OpenCLIntegrateLangevinStepKernel(name, platform, cl);
119
120
    if (name == IntegrateBrownianStepKernel::Name())
        return new OpenCLIntegrateBrownianStepKernel(name, platform, cl);
121
122
123
124
    if (name == IntegrateVariableVerletStepKernel::Name())
        return new OpenCLIntegrateVariableVerletStepKernel(name, platform, cl);
    if (name == IntegrateVariableLangevinStepKernel::Name())
        return new OpenCLIntegrateVariableLangevinStepKernel(name, platform, cl);
125
126
    if (name == IntegrateCustomStepKernel::Name())
        return new OpenCLIntegrateCustomStepKernel(name, platform, cl);
127
128
    if (name == ApplyAndersenThermostatKernel::Name())
        return new OpenCLApplyAndersenThermostatKernel(name, platform, cl);
129
130
    if (name == ApplyMonteCarloBarostatKernel::Name())
        return new OpenCLApplyMonteCarloBarostatKernel(name, platform, cl);
131
132
    if (name == RemoveCMMotionKernel::Name())
        return new OpenCLRemoveCMMotionKernel(name, platform, cl);
133
134
    throw OpenMMException((std::string("Tried to create kernel with illegal kernel name '")+name+"'").c_str());
}