"platforms/cuda2/src/kernels/virtualSites.cu" did not exist on "6e842d8ce9dff25183f89bd7377a6ed93a9a5bff"
nonbonded_nvidia.cl 9.31 KB
Newer Older
1
#define TILE_SIZE 32
2

3
typedef struct {
4
5
6
    float x, y, z;
    float q;
    float fx, fy, fz;
7
8
9
    ATOM_PARAMETER_DATA
} AtomData;

10
11
12
13
/**
 * Compute nonbonded interactions.
 */

14
15
__kernel __attribute__((reqd_work_group_size(WORK_GROUP_SIZE, 1, 1)))
void computeNonbonded(__global float4* forceBuffers, __global float* energyBuffer, __global float4* posq, __global unsigned int* exclusions,
16
        __global unsigned int* exclusionIndices, __local AtomData* localData, __local float4* tempBuffer, __global unsigned int* tiles,
17
#ifdef USE_CUTOFF
18
        __global unsigned int* interactionFlags, __global unsigned int* interactionCount
19
20
#else
        unsigned int numTiles
21
#endif
22
        PARAMETER_ARGUMENTS) {
23
24
25
#ifdef USE_CUTOFF
    unsigned int numTiles = interactionCount[0];
#endif
26
27
    unsigned int totalWarps = get_global_size(0)/TILE_SIZE;
    unsigned int warp = get_global_id(0)/TILE_SIZE;
28
29
30
31
32
33
    unsigned int pos = warp*numTiles/totalWarps;
    unsigned int end = (warp+1)*numTiles/totalWarps;
    float energy = 0.0f;
    unsigned int lasty = 0xFFFFFFFF;

    while (pos < end) {
34
        // Extract the coordinates of this tile
35
        unsigned int x = tiles[pos];
36
        unsigned int y = ((x >> 2) & 0x7fff)*TILE_SIZE;
37
        bool hasExclusions = (x & 0x1);
38
39
        x = (x>>17)*TILE_SIZE;
        unsigned int tgx = get_local_id(0) & (TILE_SIZE-1);
40
        unsigned int tbx = get_local_id(0) - tgx;
41
        unsigned int atom1 = x + tgx;
42
        float4 force = 0.0f;
43
        float4 posq1 = posq[atom1];
44
        __local AtomData* atom1Data = &localData[get_local_id(0)];
45
        LOAD_ATOM1_PARAMETERS
46
        if (x == y) {
47
            // This tile is on the diagonal.
48

49
50
51
52
            atom1Data->x = posq1.x;
            atom1Data->y = posq1.y;
            atom1Data->z = posq1.z;
            atom1Data->q = posq1.w;
53
            LOAD_LOCAL_PARAMETERS_FROM_1
54
55
            unsigned int xi = x/TILE_SIZE;
            unsigned int tile = xi+xi*PADDED_NUM_ATOMS/TILE_SIZE-xi*(xi+1)/2;
56
#ifdef USE_EXCLUSIONS
57
            unsigned int excl = exclusions[exclusionIndices[tile]+tgx];
58
#endif
59
            for (unsigned int j = 0; j < TILE_SIZE; j++) {
60
#ifdef USE_EXCLUSIONS
61
                bool isExcluded = !(excl & 0x1);
62
#endif
63
64
                __local AtomData* atom2Data = &localData[tbx+j];
                float4 posq2 = (float4) (atom2Data->x, atom2Data->y, atom2Data->z, atom2Data->q);
65
                float4 delta = (float4) (posq2.xyz - posq1.xyz, 0.0f);
66
#ifdef USE_PERIODIC
67
68
69
                delta.x -= floor(delta.x*INV_PERIODIC_BOX_SIZE_X+0.5f)*PERIODIC_BOX_SIZE_X;
                delta.y -= floor(delta.y*INV_PERIODIC_BOX_SIZE_Y+0.5f)*PERIODIC_BOX_SIZE_Y;
                delta.z -= floor(delta.z*INV_PERIODIC_BOX_SIZE_Z+0.5f)*PERIODIC_BOX_SIZE_Z;
70
#endif
71
72
                float r2 = delta.x*delta.x + delta.y*delta.y + delta.z*delta.z;
                float r = sqrt(r2);
73
                float invR = 1.0f/r;
74
                LOAD_ATOM2_PARAMETERS
75
                int atom2 = y+j;
76
77
78
                float dEdR = 0.0f;
                float tempEnergy = 0.0f;
                COMPUTE_INTERACTION
79
80
                energy += 0.5f*tempEnergy;
                delta.xyz *= dEdR;
81
                force.xyz -= delta.xyz;
82
                excl >>= 1;
83
84
85
            }

            // Write results
86
#ifdef USE_OUTPUT_BUFFER_PER_BLOCK
87
            unsigned int offset = x + tgx + (x/TILE_SIZE)*PADDED_NUM_ATOMS;
88
#else
89
            unsigned int offset = x + tgx + warp*PADDED_NUM_ATOMS;
90
#endif
91
            forceBuffers[offset].xyz += force.xyz;
92
93
        }
        else {
94
95
            // This is an off-diagonal tile.

96
97
            if (lasty != y) {
                unsigned int j = y + tgx;
98
                float4 tempPosq = posq[j];
99
100
101
102
                atom1Data->x = tempPosq.x;
                atom1Data->y = tempPosq.y;
                atom1Data->z = tempPosq.z;
                atom1Data->q = tempPosq.w;
103
                LOAD_LOCAL_PARAMETERS_FROM_GLOBAL
104
            }
105
106
107
            atom1Data->fx = 0.0f;
            atom1Data->fy = 0.0f;
            atom1Data->fz = 0.0f;
108
#ifdef USE_CUTOFF
109
            unsigned int flags = interactionFlags[pos];
110
            if (!hasExclusions && flags != 0xFFFFFFFF) {
111
112
113
114
115
116
                if (flags == 0) {
                    // No interactions in this tile.
                }
                else {
                    // Compute only a subset of the interactions in this tile.

117
                    for (unsigned int j = 0; j < TILE_SIZE; j++) {
118
119
                        if ((flags&(1<<j)) != 0) {
                            bool isExcluded = false;
120
121
                            __local AtomData* atom2Data = &localData[tbx+j];
                            float4 posq2 = (float4) (atom2Data->x, atom2Data->y, atom2Data->z, atom2Data->q);
122
                            float4 delta = (float4) (posq2.xyz - posq1.xyz, 0.0f);
123
#ifdef USE_PERIODIC
124
125
126
                            delta.x -= floor(delta.x*INV_PERIODIC_BOX_SIZE_X+0.5f)*PERIODIC_BOX_SIZE_X;
                            delta.y -= floor(delta.y*INV_PERIODIC_BOX_SIZE_Y+0.5f)*PERIODIC_BOX_SIZE_Y;
                            delta.z -= floor(delta.z*INV_PERIODIC_BOX_SIZE_Z+0.5f)*PERIODIC_BOX_SIZE_Z;
127
#endif
128
                            float r2 = delta.x*delta.x + delta.y*delta.y + delta.z*delta.z;
129
130
                            float invR = RSQRT(r2);
                            float r = RECIP(invR);
131
                            LOAD_ATOM2_PARAMETERS
132
                            int atom2 = y+j;
133
134
135
                            float dEdR = 0.0f;
                            float tempEnergy = 0.0f;
                            COMPUTE_INTERACTION
136
137
			    energy += tempEnergy;
                            delta.xyz *= dEdR;
138
                            force.xyz -= delta.xyz;
139
140
                            tempBuffer[get_local_id(0)] = delta;

141
                            // Sum the forces on atom2.
142
143
144
145
146
147
148
149
150

                            if (tgx % 2 == 0)
                                tempBuffer[get_local_id(0)].xyz += tempBuffer[get_local_id(0)+1].xyz;
                            if (tgx % 4 == 0)
                                tempBuffer[get_local_id(0)].xyz += tempBuffer[get_local_id(0)+2].xyz;
                            if (tgx % 8 == 0)
                                tempBuffer[get_local_id(0)].xyz += tempBuffer[get_local_id(0)+4].xyz;
                            if (tgx % 16 == 0)
                                tempBuffer[get_local_id(0)].xyz += tempBuffer[get_local_id(0)+8].xyz;
151
                            if (tgx == 0) {
152
153
154
                                atom2Data->fx += tempBuffer[get_local_id(0)].x + tempBuffer[get_local_id(0)+16].x;
                                atom2Data->fy += tempBuffer[get_local_id(0)].y + tempBuffer[get_local_id(0)+16].y;
                                atom2Data->fz += tempBuffer[get_local_id(0)].z + tempBuffer[get_local_id(0)+16].z;
155
                            }
156
157
158
159
                        }
                    }
                }
            }
160
            else
161
162
#endif
            {
163
164
                // Compute the full set of interactions in this tile.

165
166
167
                unsigned int xi = x/TILE_SIZE;
                unsigned int yi = y/TILE_SIZE;
                unsigned int tile = xi+yi*PADDED_NUM_ATOMS/TILE_SIZE-yi*(yi+1)/2;
168
#ifdef USE_EXCLUSIONS
169
                unsigned int excl = (hasExclusions ? exclusions[exclusionIndices[tile]+tgx] : 0xFFFFFFFF);
170
                excl = (excl >> tgx) | (excl << (TILE_SIZE - tgx));
171
#endif
172
                unsigned int tj = tgx;
173
                for (unsigned int j = 0; j < TILE_SIZE; j++) {
174
#ifdef USE_EXCLUSIONS
175
                    bool isExcluded = !(excl & 0x1);
176
#endif
177
178
                    __local AtomData* atom2Data = &localData[tbx+tj];
                    float4 posq2 = (float4) (atom2Data->x, atom2Data->y, atom2Data->z, atom2Data->q);
179
                    float4 delta = (float4) (posq2.xyz - posq1.xyz, 0.0f);
180
#ifdef USE_PERIODIC
181
182
183
                    delta.x -= floor(delta.x*INV_PERIODIC_BOX_SIZE_X+0.5f)*PERIODIC_BOX_SIZE_X;
                    delta.y -= floor(delta.y*INV_PERIODIC_BOX_SIZE_Y+0.5f)*PERIODIC_BOX_SIZE_Y;
                    delta.z -= floor(delta.z*INV_PERIODIC_BOX_SIZE_Z+0.5f)*PERIODIC_BOX_SIZE_Z;
184
#endif
185
                    float r2 = delta.x*delta.x + delta.y*delta.y + delta.z*delta.z;
186
187
                    float invR = RSQRT(r2);
                    float r = RECIP(invR);
188
                    LOAD_ATOM2_PARAMETERS
189
                    int atom2 = y+tj;
190
191
192
                    float dEdR = 0.0f;
                    float tempEnergy = 0.0f;
                    COMPUTE_INTERACTION
193
194
		    energy += tempEnergy;
                    delta.xyz *= dEdR;
195
                    force.xyz -= delta.xyz;
196
197
198
                    atom2Data->fx += delta.x;
                    atom2Data->fy += delta.y;
                    atom2Data->fz += delta.z;
199
                    excl >>= 1;
200
                    tj = (tj + 1) & (TILE_SIZE - 1);
201
202
203
204
                }
            }

            // Write results
205
#ifdef USE_OUTPUT_BUFFER_PER_BLOCK
206
207
            unsigned int offset1 = x + tgx + (y/TILE_SIZE)*PADDED_NUM_ATOMS;
            unsigned int offset2 = y + tgx + (x/TILE_SIZE)*PADDED_NUM_ATOMS;
208
#else
209
210
            unsigned int offset1 = x + tgx + warp*PADDED_NUM_ATOMS;
            unsigned int offset2 = y + tgx + warp*PADDED_NUM_ATOMS;
211
#endif
212
            forceBuffers[offset1].xyz += force.xyz;
213
            forceBuffers[offset2] += (float4) (atom1Data->fx, atom1Data->fy, atom1Data->fz, 0.0f);
214
215
216
217
218
219
            lasty = y;
        }
        pos++;
    }
    energyBuffer[get_global_id(0)] += energy;
}