-
Notifications
You must be signed in to change notification settings - Fork 2
/
potential_GPU.cu
227 lines (175 loc) · 7.71 KB
/
potential_GPU.cu
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
/********************************************************************************
*
* Copyright (C) 2015 Culham Centre for Fusion Energy,
* United Kingdom Atomic Energy Authority, Oxfordshire OX14 3DB, UK
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
********************************************************************************
*
* Program: SPILADY - A Spin-Lattice Dynamics Simulation Program
* Version: 1.0
* Date: Aug 2015
* Author: Pui-Wai (Leo) MA
* Contact: [email protected]
* Address: Culham Centre for Fusion Energy, OX14 3DB, United Kingdom
*
********************************************************************************
*
* Edit notes:
* Date: Oct 2015
* Author: Pui-Wai (Leo) Ma
* Address: Culham Centre for Fusion Energy, OX14 3DB, United Kingdom
1) Added function __device__ double interpolation_d(double x, double input_over_max, double* x_ptr);
* 2) All functions are rewritten using interpolation_d for simplicity.
*
********************************************************************************/
#ifdef GPU
#include "spilady.h"
#include "prototype_GPU.h"
void potential_table_GPU(){
size_t size_input = ninput*sizeof(double);
#if defined MD || defined SLDH || defined SLDHL || defined SLDNC
//Big F
cudaMalloc((void**)&bf_ptr_d, size_input);
cudaMalloc((void**)&dbf_ptr_d, size_input);
cudaMemcpy(bf_ptr_d, bf_ptr, size_input, cudaMemcpyHostToDevice);
cudaMemcpy(dbf_ptr_d, dbf_ptr, size_input, cudaMemcpyHostToDevice);
//small f
cudaMalloc((void**)&sf_ptr_d, size_input);
cudaMalloc((void**)&dsf_ptr_d, size_input);
cudaMemcpy(sf_ptr_d, sf_ptr, size_input, cudaMemcpyHostToDevice);
cudaMemcpy(dsf_ptr_d, dsf_ptr, size_input, cudaMemcpyHostToDevice);
//pair term
cudaMalloc((void**)&pr_ptr_d, size_input);
cudaMalloc((void**)&dpr_ptr_d, size_input);
cudaMemcpy(pr_ptr_d, pr_ptr, size_input, cudaMemcpyHostToDevice);
cudaMemcpy(dpr_ptr_d, dpr_ptr, size_input, cudaMemcpyHostToDevice);
#endif
#if defined SDH || defined SDHL || defined SLDH || defined SLDHL
//Jij
cudaMalloc((void**)&Jij_ptr_d, size_input);
cudaMalloc((void**)&dJij_ptr_d, size_input);
cudaMemcpy(Jij_ptr_d, Jij_ptr, size_input, cudaMemcpyHostToDevice);
cudaMemcpy(dJij_ptr_d, dJij_ptr, size_input, cudaMemcpyHostToDevice);
#endif
#if defined SDHL || defined SLDHL
cudaMalloc((void**)&LandauA_ptr_d, size_input);
cudaMalloc((void**)&LandauB_ptr_d, size_input);
cudaMalloc((void**)&LandauC_ptr_d, size_input);
cudaMalloc((void**)&LandauD_ptr_d, size_input);
cudaMemcpy(LandauA_ptr_d, LandauA_ptr, size_input, cudaMemcpyHostToDevice);
cudaMemcpy(LandauB_ptr_d, LandauB_ptr, size_input, cudaMemcpyHostToDevice);
cudaMemcpy(LandauC_ptr_d, LandauC_ptr, size_input, cudaMemcpyHostToDevice);
cudaMemcpy(LandauD_ptr_d, LandauD_ptr, size_input, cudaMemcpyHostToDevice);
#endif
#ifdef SLDHL
cudaMalloc((void**)&dLandauA_ptr_d, size_input);
cudaMalloc((void**)&dLandauB_ptr_d, size_input);
cudaMalloc((void**)&dLandauC_ptr_d, size_input);
cudaMalloc((void**)&dLandauD_ptr_d, size_input);
cudaMemcpy(dLandauA_ptr_d, dLandauA_ptr, size_input, cudaMemcpyHostToDevice);
cudaMemcpy(dLandauB_ptr_d, dLandauB_ptr, size_input, cudaMemcpyHostToDevice);
cudaMemcpy(dLandauC_ptr_d, dLandauC_ptr, size_input, cudaMemcpyHostToDevice);
cudaMemcpy(dLandauD_ptr_d, dLandauD_ptr, size_input, cudaMemcpyHostToDevice);
#endif
}
__device__ double interpolation_d(double x, double input_over_max, double* x_ptr){
double fn = x*input_over_max;
int n = int(fn);
double ratio = double(n+1)- fn;
return *(x_ptr+n-1)*ratio + *(x_ptr+n)*(1e0-ratio);
}
#if defined MD || defined SLDH || defined SLDHL || defined SLDNC
__device__ double bigf_d(double rho, double *bf_ptr_d, struct varGPU *var_ptr_d){
return interpolation_d(rho, var_ptr_d->finput_over_rhomax, bf_ptr_d);
}
__device__ double dbigf_d(double rho, double *dbf_ptr_d, struct varGPU *var_ptr_d){
return interpolation_d(rho, var_ptr_d->finput_over_rhomax, dbf_ptr_d);
}
__device__ double smallf_d(double rij, double *sf_ptr_d, struct varGPU *var_ptr_d){
return interpolation_d(rij, var_ptr_d->finput_over_rmax, sf_ptr_d);
}
__device__ double dsmallf_d(double rij, double *dsf_ptr_d, struct varGPU *var_ptr_d){
return interpolation_d(rij, var_ptr_d->finput_over_rmax, dsf_ptr_d);
}
__device__ double pair_d(double rij, double *pr_ptr_d, struct varGPU *var_ptr_d){
return interpolation_d(rij, var_ptr_d->finput_over_rmax, pr_ptr_d);
}
__device__ double dpair_d(double rij, double *dpr_ptr_d, struct varGPU *var_ptr_d){
return interpolation_d(rij, var_ptr_d->finput_over_rmax, dpr_ptr_d);
}
#endif
#if defined SDH || defined SDHL || defined SLDH || defined SLDHL
__device__ double Jij_d(double rij, double *Jij_ptr_d, struct varGPU *var_ptr_d){
return interpolation_d(rij, var_ptr_d->finput_over_rmax, Jij_ptr_d);
}
__device__ double dJij_d(double rij, double *dJij_ptr_d, struct varGPU *var_ptr_d){
return interpolation_d(rij, var_ptr_d->finput_over_rmax, dJij_ptr_d);
}
#endif
#if defined SDHL || defined SLDHL
__device__ double LandauA_d(double rho, double *LandauA_ptr_d, struct varGPU *var_ptr_d){
return interpolation_d(rho, var_ptr_d->finput_over_rhomax, LandauA_ptr_d);
}
__device__ double LandauB_d(double rho, double *LandauB_ptr_d, struct varGPU *var_ptr_d){
return interpolation_d(rho, var_ptr_d->finput_over_rhomax, LandauB_ptr_d);
}
__device__ double LandauC_d(double rho, double *LandauC_ptr_d, struct varGPU *var_ptr_d){
return interpolation_d(rho, var_ptr_d->finput_over_rhomax, LandauC_ptr_d);
}
__device__ double LandauD_d(double rho, double *LandauD_ptr_d, struct varGPU *var_ptr_d){
return interpolation_d(rho, var_ptr_d->finput_over_rhomax, LandauD_ptr_d);
}
#endif
#ifdef SLDHL
__device__ double dLandauA_d(double rho, double *dLandauA_ptr_d, struct varGPU *var_ptr_d){
return interpolation_d(rho, var_ptr_d->finput_over_rhomax, dLandauA_ptr_d);
}
__device__ double dLandauB_d(double rho, double *dLandauB_ptr_d, struct varGPU *var_ptr_d){
return interpolation_d(rho, var_ptr_d->finput_over_rhomax, dLandauB_ptr_d);
}
__device__ double dLandauC_d(double rho, double *dLandauC_ptr_d, struct varGPU *var_ptr_d){
return interpolation_d(rho, var_ptr_d->finput_over_rhomax, dLandauC_ptr_d);
}
__device__ double dLandauD_d(double rho, double *dLandauD_ptr_d, struct varGPU *var_ptr_d){
return interpolation_d(rho, var_ptr_d->finput_over_rhomax, dLandauD_ptr_d);
}
#endif
void free_potential_ptr_GPU(){
#if defined MD || defined SLDH || defined SLDHL || defined SLDNC
cudaFree(bf_ptr_d);
cudaFree(dbf_ptr_d);
cudaFree(sf_ptr_d);
cudaFree(dsf_ptr_d);
cudaFree(pr_ptr_d);
cudaFree(dpr_ptr_d);
#endif
#if defined SDH || defined SDHL || defined SLDH || defined SLDHL
cudaFree(Jij_ptr_d);
cudaFree(dJij_ptr_d);
#endif
#if defined SDHL || defined SLDHL
cudaFree(LandauA_ptr_d);
cudaFree(LandauB_ptr_d);
cudaFree(LandauC_ptr_d);
cudaFree(LandauD_ptr_d);
#endif
#if defined SLDHL
cudaFree(dLandauA_ptr_d);
cudaFree(dLandauB_ptr_d);
cudaFree(dLandauC_ptr_d);
cudaFree(dLandauD_ptr_d);
#endif
}
#endif