OpenCLKernelFactory.cpp 4.85 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/* -------------------------------------------------------------------------- *
 *                                   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:                                                              *
 *                                                                            *
 * 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"
#include "OpenCLKernels.h"
#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());
36
    OpenCLContext& cl = *data.context;
37
    if (name == CalcForcesAndEnergyKernel::Name())
38
        return new OpenCLCalcForcesAndEnergyKernel(name, platform, cl);
39
    if (name == UpdateStateDataKernel::Name())
40
        return new OpenCLUpdateStateDataKernel(name, platform, cl);
41
    if (name == CalcHarmonicBondForceKernel::Name())
42
        return new OpenCLCalcHarmonicBondForceKernel(name, platform, cl, context.getSystem());
43
44
    if (name == CalcCustomBondForceKernel::Name())
        return new OpenCLCalcCustomBondForceKernel(name, platform, cl, context.getSystem());
45
    if (name == CalcHarmonicAngleForceKernel::Name())
46
        return new OpenCLCalcHarmonicAngleForceKernel(name, platform, cl, context.getSystem());
47
    if (name == CalcPeriodicTorsionForceKernel::Name())
48
        return new OpenCLCalcPeriodicTorsionForceKernel(name, platform, cl, context.getSystem());
49
    if (name == CalcRBTorsionForceKernel::Name())
50
        return new OpenCLCalcRBTorsionForceKernel(name, platform, cl, context.getSystem());
51
52
    if (name == CalcNonbondedForceKernel::Name())
        return new OpenCLCalcNonbondedForceKernel(name, platform, cl, context.getSystem());
53
54
    if (name == CalcCustomNonbondedForceKernel::Name())
        return new OpenCLCalcCustomNonbondedForceKernel(name, platform, cl, context.getSystem());
55
56
    if (name == CalcGBSAOBCForceKernel::Name())
        return new OpenCLCalcGBSAOBCForceKernel(name, platform, cl);
57
    if (name == IntegrateVerletStepKernel::Name())
58
        return new OpenCLIntegrateVerletStepKernel(name, platform, cl);
59
60
    if (name == IntegrateLangevinStepKernel::Name())
        return new OpenCLIntegrateLangevinStepKernel(name, platform, cl);
61
62
    if (name == IntegrateBrownianStepKernel::Name())
        return new OpenCLIntegrateBrownianStepKernel(name, platform, cl);
63
64
65
66
    if (name == IntegrateVariableVerletStepKernel::Name())
        return new OpenCLIntegrateVariableVerletStepKernel(name, platform, cl);
    if (name == IntegrateVariableLangevinStepKernel::Name())
        return new OpenCLIntegrateVariableLangevinStepKernel(name, platform, cl);
67
68
    if (name == ApplyAndersenThermostatKernel::Name())
        return new OpenCLApplyAndersenThermostatKernel(name, platform, cl);
69
    if (name == CalcKineticEnergyKernel::Name())
70
        return new OpenCLCalcKineticEnergyKernel(name, platform, cl);
71
72
    if (name == RemoveCMMotionKernel::Name())
        return new OpenCLRemoveCMMotionKernel(name, platform, cl);
73
74
    throw OpenMMException((std::string("Tried to create kernel with illegal kernel name '")+name+"'").c_str());
}