9.2
general documentation
cs_sles_it_cuda.h
Go to the documentation of this file.
1#ifndef CS_SLES_IT_CUDA_H
2#define CS_SLES_IT_CUDA_H
3
4/*============================================================================
5 * Sparse Linear Equation Solvers using CUDA
6 *============================================================================*/
7
8/*
9 This file is part of code_saturne, a general-purpose CFD tool.
10
11 Copyright (C) 1998-2026 EDF S.A.
12
13 This program is free software; you can redistribute it and/or modify it under
14 the terms of the GNU General Public License as published by the Free Software
15 Foundation; either version 2 of the License, or (at your option) any later
16 version.
17
18 This program is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
21 details.
22
23 You should have received a copy of the GNU General Public License along with
24 this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
25 Street, Fifth Floor, Boston, MA 02110-1301, USA.
26*/
27
28/*----------------------------------------------------------------------------*/
29
30/*----------------------------------------------------------------------------
31 * Local headers
32 *----------------------------------------------------------------------------*/
33
34#include "base/cs_base.h"
35#include "alge/cs_matrix.h"
36#include "alge/cs_sles.h"
37#include "alge/cs_sles_pc.h"
38
39/*----------------------------------------------------------------------------*/
40
41/*============================================================================
42 * Macro definitions
43 *============================================================================*/
44
45/*============================================================================
46 * Type definitions
47 *============================================================================*/
48
49/*============================================================================
50 * Global variables
51 *============================================================================*/
52
53/*=============================================================================
54 * User function prototypes
55 *============================================================================*/
56
57/*============================================================================
58 * Semi-private function prototypes
59 *============================================================================*/
60
61#if defined(__CUDACC__)
62
63/*----------------------------------------------------------------------------
64 * Compute dot product, summing result over all ranks.
65 *
66 * parameters:
67 * c <-- pointer to solver context info
68 * stream <-- CUDA stream
69 * x <-- first vector
70 * y <-- vector
71 *
72 * return:
73 * result of s = x.x
74 *----------------------------------------------------------------------------*/
75
76double
78(
79 const cs_sles_it_t *c,
80 cudaStream_t stream,
81 const cs_real_t *x,
82 const cs_real_t *y
83);
84
85/*----------------------------------------------------------------------------
86 * Compute dot product, summing result over all ranks.
87 *
88 * parameters:
89 * c <-- pointer to solver context info
90 * stream <-- CUDA stream
91 * x <-- first vector
92 * y <-- second vector
93 *
94 * return:
95 * result of s = x.y
96 *----------------------------------------------------------------------------*/
97
98double
100(
101 const cs_sles_it_t *c,
102 cudaStream_t stream,
103 const cs_real_t *x,
104 const cs_real_t *y
105);
106
107/*----------------------------------------------------------------------------
108 * Compute dot product, summing result over all ranks.
109 *
110 * parameters:
111 * c <-- pointer to solver context info
112 * stream <-- CUDA stream
113 * x <-- vector
114 *
115 * return:
116 * result of s = x.x
117 *----------------------------------------------------------------------------*/
118
119double
121(
122 const cs_sles_it_t *c,
123 cudaStream_t stream,
124 const cs_real_t *x
125);
126
127/*----------------------------------------------------------------------------
128 * Compute 2 dot products, summing result over all ranks.
129 *
130 * parameters:
131 * c <-- pointer to solver context info
132 * stream <-- CUDA stream
133 * x <-- first vector
134 * y <-- second vector
135 * z <-- third vector
136 * xx --> result of s1 = x.x
137 * xy --> result of s2 = x.y
138 *----------------------------------------------------------------------------*/
139
140void
142(
143 const cs_sles_it_t *c,
144 cudaStream_t stream,
145 const cs_real_t *x,
146 const cs_real_t *y,
147 double *xx,
148 double *xy
149);
150
151/*----------------------------------------------------------------------------
152 * Compute 2 dot products, summing result over all ranks.
153 *
154 * parameters:
155 * c <-- pointer to solver context info
156 * stream <-- CUDA stream
157 * x <-- first vector
158 * y <-- second vector
159 * z <-- second vector
160 * xy --> result of s1 = x.y
161 * yz --> result of s2 = y.z
162 *----------------------------------------------------------------------------*/
163
164void
166(
167 const cs_sles_it_t *c,
168 cudaStream_t stream,
169 const cs_real_t *x,
170 const cs_real_t *y,
171 const cs_real_t *z,
172 double *xy,
173 double *yz
174);
175
176/*----------------------------------------------------------------------------
177 * Compute 3 dot products, summing result over all ranks.
178 *
179 * parameters:
180 * c <-- pointer to solver context info
181 * stream <-- CUDA stream
182 * x <-- first vector
183 * y <-- second vector
184 * z <-- third vector
185 * xx --> result of s1 = x.x
186 * xy --> result of s2 = x.y
187 * yz --> result of s3 = y.z
188 *----------------------------------------------------------------------------*/
189
190void
192(
193 const cs_sles_it_t *c,
194 cudaStream_t stream,
195 const cs_real_t *x,
196 const cs_real_t *y,
197 const cs_real_t *z,
198 double *xx,
199 double *xy,
200 double *yz
201);
202
203/*----------------------------------------------------------------------------
204 * Compute 5 dot products, summing result over all ranks.
205 *
206 * parameters:
207 * c <-- pointer to solver context info
208 * stream <-- CUDA stream
209 * x <-- first vector
210 * y <-- second vector
211 * z <-- third vector
212 * xx --> result of x.x
213 * yy --> result of y.y
214 * xy --> result of x.y
215 * xz --> result of x.z
216 * yz --> result of y.z
217 *----------------------------------------------------------------------------*/
218
219void
221(
222 const cs_sles_it_t *c,
223 cudaStream_t stream,
224 const cs_real_t *x,
225 const cs_real_t *y,
226 const cs_real_t *z,
227 double *xx,
228 double *yy,
229 double *xy,
230 double *xz,
231 double *yz
232);
233
234#endif // defined(__CUDACC__)
235
236/*=============================================================================
237 * Public function prototypes
238 *============================================================================*/
239
240/*----------------------------------------------------------------------------
241 * Solution of A.vx = Rhs using Jacobi.
242 *
243 * parameters:
244 * c <-- pointer to solver context info
245 * a <-- linear equation matrix
246 * diag_block_size <-- diagonal block size
247 * rotation_mode <-- halo update option for rotational periodicity
248 * convergence <-- convergence information structure
249 * rhs <-- right hand side
250 * vx_ini <-- initial system solution
251 * (vx if nonzero, nullptr if zero)
252 * vx <-> system solution
253 * aux_size <-- number of elements in aux_vectors (in bytes)
254 * aux_vectors --- optional working area (allocation otherwise)
255 *
256 * returns:
257 * convergence state
258 *----------------------------------------------------------------------------*/
259
262 const cs_matrix_t *a,
263 cs_lnum_t diag_block_size,
264 cs_sles_it_convergence_t *convergence,
265 const cs_real_t *rhs,
266 cs_real_t *vx_ini,
267 cs_real_t *vx,
268 size_t aux_size,
269 void *aux_vectors);
270
271/*----------------------------------------------------------------------------
272 * Solution of A.vx = Rhs using block Jacobi.
273 *
274 * parameters:
275 * c <-- pointer to solver context info
276 * a <-- linear equation matrix
277 * diag_block_size <-- diagonal block size
278 * rotation_mode <-- halo update option for rotational periodicity
279 * convergence <-- convergence information structure
280 * rhs <-- right hand side
281 * vx_ini <-- initial system solution
282 * (vx if nonzero, nullptr if zero)
283 * vx <-> system solution
284 * aux_size <-- number of elements in aux_vectors (in bytes)
285 * aux_vectors --- optional working area (allocation otherwise)
286 *
287 * returns:
288 * convergence state
289 *----------------------------------------------------------------------------*/
290
293 const cs_matrix_t *a,
294 cs_lnum_t diag_block_size,
295 cs_sles_it_convergence_t *convergence,
296 const cs_real_t *rhs,
297 cs_real_t *vx_ini,
298 cs_real_t *vx,
299 size_t aux_size,
300 void *aux_vectors);
301
302/*----------------------------------------------------------------------------
303 * Solution of A.vx = Rhs using flexible preconditioned conjugate gradient.
304 *
305 * Compared to standard PCG, FCG supports variable preconditioners.
306 *
307 * This variant, described in \cite Notay:2015, allows computing the
308 * required inner products with a single global communication.
309 *
310 * parameters:
311 * c <-- pointer to solver context info
312 * a <-- matrix
313 * diag_block_size <-- diagonal block size
314 * convergence <-- convergence information structure
315 * rhs <-- right hand side
316 * vx_ini <-- initial system solution
317 * (vx if nonzero, nullptr if zero)
318 * vx <-> system solution
319 * aux_size <-- number of elements in aux_vectors (in bytes)
320 * aux_vectors --- optional working area (allocation otherwise)
321 *
322 * returns:
323 * convergence state
324 *----------------------------------------------------------------------------*/
325
328 const cs_matrix_t *a,
329 cs_lnum_t diag_block_size,
330 cs_sles_it_convergence_t *convergence,
331 const cs_real_t *rhs,
332 cs_real_t *vx_ini,
333 cs_real_t *vx,
334 size_t aux_size,
335 void *aux_vectors);
336
337/*----------------------------------------------------------------------------
338 * Solution of A.vx = Rhs using optimised preconditioned GCR (CUDA version).
339 *
340 * parameters:
341 * c <-- pointer to solver context info
342 * a <-- matrix
343 * diag_block_size <-- diagonal block size (unused here)
344 * convergence <-- convergence information structure
345 * rhs <-- right hand side
346 * vx_ini <-- initial system solution
347 * (vx if nonzero, nullptr if zero)
348 * vx <-> system solution
349 * aux_size <-- number of elements in aux_vectors (in bytes)
350 * aux_vectors --- optional working area (allocation otherwise)
351 *
352 * returns:
353 * convergence state
354 *----------------------------------------------------------------------------*/
355
358 const cs_matrix_t *a,
359 cs_lnum_t diag_block_size,
360 cs_sles_it_convergence_t *convergence,
361 const cs_real_t *rhs,
362 cs_real_t *vx_ini,
363 cs_real_t *vx,
364 size_t aux_size,
365 void *aux_vectors);
366
367/*----------------------------------------------------------------------------*/
368
369#endif /* CS_SLES_IT_CUDA_H */
double cs_real_t
Floating-point value.
Definition: cs_defs.h:332
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:325
struct _cs_matrix_t cs_matrix_t
Definition: cs_matrix.h:108
cs_sles_convergence_state_t
Definition: cs_sles.h:57
struct _cs_sles_it_t cs_sles_it_t
Definition: cs_sles_it.h:95
struct _cs_sles_it_convergence_t cs_sles_it_convergence_t
Definition: cs_sles_it.h:99
cs_sles_convergence_state_t cs_sles_it_cuda_jacobi(cs_sles_it_t *c, const cs_matrix_t *a, cs_lnum_t diag_block_size, cs_sles_it_convergence_t *convergence, const cs_real_t *rhs, cs_real_t *vx_ini, cs_real_t *vx, size_t aux_size, void *aux_vectors)
cs_sles_convergence_state_t cs_sles_it_cuda_fcg(cs_sles_it_t *c, const cs_matrix_t *a, cs_lnum_t diag_block_size, cs_sles_it_convergence_t *convergence, const cs_real_t *rhs, cs_real_t *vx_ini, cs_real_t *vx, size_t aux_size, void *aux_vectors)
cs_sles_convergence_state_t cs_sles_it_cuda_gcr(cs_sles_it_t *c, const cs_matrix_t *a, cs_lnum_t diag_block_size, cs_sles_it_convergence_t *convergence, const cs_real_t *rhs, cs_real_t *vx_ini, cs_real_t *vx, size_t aux_size, void *aux_vectors)
cs_sles_convergence_state_t cs_sles_it_cuda_block_jacobi(cs_sles_it_t *c, const cs_matrix_t *a, cs_lnum_t diag_block_size, cs_sles_it_convergence_t *convergence, const cs_real_t *rhs, cs_real_t *vx_ini, cs_real_t *vx, size_t aux_size, void *aux_vectors)
void cs_sles_it_dot_products_xx_yy_xy_xz_yz(const cs_sles_it_t *c, hipStream_t stream, const cs_real_t *x, const cs_real_t *y, const cs_real_t *z, double *xx, double *yy, double *xy, double *xz, double *yz)
Definition: cs_sles_it_hip.cpp:1948
double cs_sles_it_dot_product_xx(const cs_sles_it_t *c, hipStream_t stream, const cs_real_t *x)
Definition: cs_sles_it_hip.cpp:1637
void cs_sles_it_dot_products_xx_xy_yz(const cs_sles_it_t *c, hipStream_t stream, const cs_real_t *x, const cs_real_t *y, const cs_real_t *z, double *xx, double *xy, double *yz)
Definition: cs_sles_it_hip.cpp:1864
void cs_sles_it_dot_products_xy_yz(const cs_sles_it_t *c, hipStream_t stream, const cs_real_t *x, const cs_real_t *y, const cs_real_t *z, double *xy, double *yz)
Definition: cs_sles_it_hip.cpp:1785
double cs_sles_it_dot_product(const cs_sles_it_t *c, hipStream_t stream, const cs_real_t *x, const cs_real_t *y)
Definition: cs_sles_it_hip.cpp:1565
void cs_sles_it_dot_products_xx_xy(const cs_sles_it_t *c, hipStream_t stream, const cs_real_t *x, const cs_real_t *y, double *xx, double *xy)
Definition: cs_sles_it_hip.cpp:1708