-
Notifications
You must be signed in to change notification settings - Fork 189
/
Copy pathcuda_interface.hpp
188 lines (149 loc) · 5.01 KB
/
cuda_interface.hpp
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/*
Copyright (C) 2013-2018 The ESPResSo project
This file is part of ESPResSo.
ESPResSo is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
ESPResSo 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef CORE_CUDA_INTERFACE_HPP
#define CORE_CUDA_INTERFACE_HPP
#include "config.hpp"
#ifdef CUDA
#include "ParticleRange.hpp"
#include "SystemInterface.hpp"
#ifdef ENGINE
// velocities which need to be copied from the GPU to the CPU to calculate a
// torque
typedef struct {
// center and source velocity of the md part
float v_cs[6];
} CUDA_v_cs;
#endif
typedef struct {
/** fluid composition at the particle given to md part */
float weight[LB_COMPONENTS];
} CUDA_fluid_composition;
// Parameters for swimmers
#ifdef ENGINE
typedef struct {
// v_cs has to stay in the front for memmove reasons
float v_cs[6];
float v_swim;
float f_swim;
float director[3];
int push_pull;
float dipole_length;
bool swimming;
} CUDA_ParticleParametersSwimming;
#endif
/** data structure which must be copied to the GPU at each step run on the GPU
*/
struct CUDA_particle_data {
// // This has to stay in front of the struct for memmove reasons
#ifdef ENGINE
CUDA_ParticleParametersSwimming swim;
#endif
int identity;
/** particle position given from md part*/
float p[3];
#if defined(LB_GPU)
/** particle momentum struct velocity p.m->v*/
float v[3];
#endif
#ifdef ROTATION
float director[3];
#endif
#ifdef SHANCHEN
float solvation[2 * LB_COMPONENTS];
#endif
#if defined(LB_ELECTROHYDRODYNAMICS) && defined(LB_GPU)
float mu_E[3];
#endif
#ifdef ELECTROSTATICS
float q;
#endif
#ifdef MASS
float mass;
#endif
#ifdef VIRTUAL_SITES
bool is_virtual;
#endif
#ifdef DIPOLES
float dip[3];
#endif
};
/** data structure for the different kinds of energies */
typedef struct {
float bonded, non_bonded, coulomb, dipolar;
} CUDA_energy;
/** Note the particle's seed gets its own struct since it doesn't get copied
* back and forth from the GPU */
typedef struct {
unsigned int seed;
} CUDA_particle_seed;
extern CUDA_particle_data *particle_data_host;
/** This structure contains global variables associated with all of the
* particles and not with one individual particle */
typedef struct {
/** This is for seeding the particles' individual seeds and is initialized
* using irandom, beware if using for other purposes */
unsigned int seed;
unsigned int number_of_particles;
/** a boolean variable to indicate if particle info should be communicated
* between the cpu and gpu */
unsigned int communication_enabled;
} CUDA_global_part_vars;
void copy_forces_from_GPU(ParticleRange particles);
void copy_energy_from_GPU();
void copy_CUDA_energy_to_energy(CUDA_energy energy_host);
void clear_energy_on_GPU();
void copy_composition_from_GPU();
CUDA_global_part_vars *gpu_get_global_particle_vars_pointer_host();
CUDA_global_part_vars *gpu_get_global_particle_vars_pointer();
CUDA_particle_data *gpu_get_particle_pointer();
float *gpu_get_particle_force_pointer();
#ifdef ROTATION
float *gpu_get_particle_torque_pointer();
#endif
CUDA_energy *gpu_get_energy_pointer();
float *gpu_get_particle_torque_pointer();
CUDA_fluid_composition *gpu_get_fluid_composition_pointer();
CUDA_particle_seed *gpu_get_particle_seed_pointer();
void gpu_change_number_of_part_to_comm();
void gpu_init_particle_comm();
void cuda_mpi_get_particles(ParticleRange particles,
CUDA_particle_data *host_result);
void copy_part_data_to_gpu(ParticleRange particles);
/**
* @brief Distribute forces to the slaves, and and them to the particles.
*
* @param particles The particles the forces (and torques should be added to)
* @param host_forces The forces as flat array of size 3 * particles.size(),
only relevant on the master.
* @param host_torques The torques as flat array of size 3 * particles.size(),
* this is only touched if ROTATION is active. Only relevant
on the master.
*
* This is a collective call.
*/
void cuda_mpi_send_forces(ParticleRange particles, float *host_forces,
float *host_torques);
void cuda_bcast_global_part_params();
void cuda_copy_to_device(void *host_data, void *device_data, size_t n);
void cuda_copy_to_host(void *host_device, void *device_host, size_t n);
#ifdef SHANCHEN
void cuda_mpi_send_composition(ParticleRange, CUDA_fluid_composition *);
#endif
#ifdef ENGINE
void copy_v_cs_from_GPU(ParticleRange particles);
void cuda_mpi_send_v_cs(ParticleRange particles, CUDA_v_cs *host_v_cs);
#endif
#endif /* ifdef CUDA */
#endif /* ifdef CUDA_INTERFACE_HPP */