CudaStreamFactory.cpp 4.11 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
#include "CudaPlatform.h"
28
29
#include "CudaStreamFactory.h"
#include "CudaStreamImpl.h"
30
#include "openmm/OpenMMException.h"
31
#include "openmm/internal/ContextImpl.h"
32
#include "kernels/gputypes.h"
33
34
35

using namespace OpenMM;

36
StreamImpl* CudaStreamFactory::createStreamImpl(std::string name, int size, Stream::DataType type, const Platform& platform, ContextImpl& context) const {
37
    CudaPlatform::PlatformData& data = *static_cast<CudaPlatform::PlatformData*>(context.getPlatformData());
Peter Eastman's avatar
Peter Eastman committed
38
    if (name == "particlePositions") {
39
        float padding[] = {100000.0f, 100000.0f, 100000.0f, 0.2f};
40
        return new CudaStreamImpl<float4>(name, size, type, platform, data.gpu->psPosq4, 4, padding, data.gpu);
41
    }
Peter Eastman's avatar
Peter Eastman committed
42
    if (name == "particleVelocities") {
43
        float padding[] = {0.0f, 0.0f, 0.0f, 0.0f};
44
        return new CudaStreamImpl<float4>(name, size, type, platform, data.gpu->psVelm4, 4, padding, data.gpu);
45
    }
Peter Eastman's avatar
Peter Eastman committed
46
    if (name == "particleForces") {
47
        float padding[] = {0.0f, 0.0f, 0.0f, 0.0f};
48
        return new CudaStreamImpl<float4>(name, size, type, platform, data.gpu->psForce4, 4, padding, data.gpu);
49
50
51
52
    }
    switch (type) {
    case Stream::Float:
    case Stream::Double:
53
        return new CudaStreamImpl<float1>(name, size, type, platform, 1, data.gpu);
54
55
    case Stream::Float2:
    case Stream::Double2:
56
        return new CudaStreamImpl<float2>(name, size, type, platform, 1, data.gpu);
57
58
    case Stream::Float3:
    case Stream::Double3:
59
        return new CudaStreamImpl<float3>(name, size, type, platform, 1, data.gpu);
60
61
    case Stream::Float4:
    case Stream::Double4:
62
        return new CudaStreamImpl<float4>(name, size, type, platform, 1, data.gpu);
63
    case Stream::Integer:
64
        return new CudaStreamImpl<int1>(name, size, type, platform, 1, data.gpu);
65
    case Stream::Integer2:
66
        return new CudaStreamImpl<int2>(name, size, type, platform, 1, data.gpu);
67
    case Stream::Integer3:
68
        return new CudaStreamImpl<int3>(name, size, type, platform, 1, data.gpu);
69
    case Stream::Integer4:
70
        return new CudaStreamImpl<int4>(name, size, type, platform, 1, data.gpu);
71
72
73
    }
    throw OpenMMException("Tried to create a Stream with an illegal DataType.");
}