PaStiX Handbook 6.4.0
Loading...
Searching...
No Matches
cpucblk_spack.c
Go to the documentation of this file.
1/**
2 *
3 * @file cpucblk_spack.c
4 *
5 * Precision dependent routines to pack and unpack cblks.
6 *
7 * @copyright 2021-2024 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria,
8 * Univ. Bordeaux. All rights reserved.
9 *
10 * @version 6.4.0
11 * @author Nolan Bredel
12 * @date 2024-07-05
13 *
14 * @generated from /builds/2mk6rsew/0/solverstack/pastix/kernels/cpucblk_zpack.c, normal z -> s, Tue Feb 25 14:35:00 2025
15 *
16 **/
17#include "common/common.h"
18#include "blend/solver.h"
19#include "cpucblk_spack.h"
20#include "pastix_scores.h"
21#include "pastix_slrcores.h"
22
23/**
24 *******************************************************************************
25 *
26 * @brief Compute the size of a block to send in LR.
27 *
28 *******************************************************************************
29 *
30 * @param[in] side
31 * Define which side of the cblk must be tested.
32 * @arg PastixLCoef if lower part only
33 * @arg PastixUCoef if upper part only
34 * @arg PastixLUCoef if both sides.
35 *
36 * @param[in] N
37 * The number of columns of the block.
38 *
39 * @param[in] blok
40 * The block for which the size is computed.
41 *
42 *******************************************************************************
43 *
44 * @return size of the LR block to send in bytes
45 *
46 *******************************************************************************/
47size_t
50 const SolverBlok *blok )
51{
52 pastix_int_t M = blok_rownbr( blok );
53 pastix_int_t suv = 0;
54 pastix_int_t coef = 0;
55
56 /* Add lower part size */
57 if ( side != PastixUCoef ) {
58 suv += core_slrgetsize( M, N, blok->LRblock[0] );
59 coef++;
60 }
61
62 /* Add upper part size */
63 if ( side != PastixLCoef ) {
64 suv += core_slrgetsize( M, N, blok->LRblock[1] );
65 coef++;
66 }
67
68 /* size of rk(int) + size of u + size of v */
69 return coef * sizeof( int ) + suv * sizeof( float );
70}
71
72/**
73 *******************************************************************************
74 *
75 * @brief Compute the size of a column block to send in LR.
76 *
77 *******************************************************************************
78 *
79 * @param[in] side
80 * Define which side of the cblk must be tested.
81 * @arg PastixLCoef if lower part only
82 * @arg PastixUCoef if upper part only
83 * @arg PastixLUCoef if both sides.
84 *
85 * @param[in] cblk
86 * The low-rank column block for which the size is computed.
87 *
88 *******************************************************************************
89 *
90 * @return size of the LR column block to send in bytes.
91 *
92 *******************************************************************************/
93pastix_uint_t
95 const SolverCblk *cblk )
96{
97 assert( cblk->cblktype & CBLK_COMPRESSED );
98
99 pastix_uint_t N = cblk_colnbr( cblk );
100 pastix_uint_t size = 0;
101 const SolverBlok *blok = cblk->fblokptr;
102 const SolverBlok *lblok = cblk[1].fblokptr;
103
104 for ( ; blok < lblok; blok++ ) {
105 size += cpublok_scompute_size_lr( side, N, blok );
106 }
107
108 /* size of all blocks */
109 return size;
110}
111
112/**
113 *******************************************************************************
114 *
115 * @brief Compute the size of the buffer to send.
116 *
117 *******************************************************************************
118 *
119 * @param[in] side
120 * Define which side of the cblk must be tested.
121 * @arg PastixLCoef if lower part only
122 * @arg PastixUCoef if upper part only
123 * @arg PastixLUCoef if both sides.
124 *
125 * @param[in] cblk
126 * The column block for which the size is computed.
127 *
128 *******************************************************************************
129 *
130 * @return Size of the buffer to send.
131 *
132 *******************************************************************************/
133size_t
135 const SolverCblk *cblk )
136{
137 if ( cblk->cblktype & CBLK_COMPRESSED ) {
138 return cpucblk_scompute_size_lr( side, cblk );
139 }
140 else {
141 size_t cblksize = cblk->stride * cblk_colnbr( cblk );
142 if ( side == PastixLUCoef ) {
143 cblksize *= 2;
144 }
145 return cblksize * sizeof( float );
146 }
147}
148
149/**
150 *******************************************************************************
151 *
152 * @brief Pack low-rank data for a block.
153 *
154 *******************************************************************************
155 *
156 * @param[in] side
157 * Define which side of the cblk must be tested.
158 * @arg PastixLCoef if lower part only
159 * @arg PastixUCoef if upper part only
160 * @arg PastixLUCoef if both sides.
161 *
162 * @param[in] N
163 * Number of columns of the block.
164 *
165 * @param[in] blok
166 * The solver block to pack.
167 *
168 * @param[inout] buffer
169 * Pointer to the buffer where to pack the data.
170 *
171 *******************************************************************************
172 *
173 * @return Pointer to the end of the packed data.
174 *
175 *******************************************************************************/
176char *
178 pastix_uint_t N,
179 const SolverBlok *blok,
180 char *buffer )
181{
182 pastix_int_t M = blok_rownbr( blok );
183
184 if ( side != PastixUCoef ) {
185 buffer = core_slrpack( M, N, blok->LRblock[0], buffer );
186 }
187
188 if ( side != PastixLCoef ) {
189 buffer = core_slrpack( M, N, blok->LRblock[1], buffer );
190 }
191
192 return buffer;
193}
194
195/**
196 *******************************************************************************
197 *
198 * @brief Pack low-rank data for column block.
199 *
200 *******************************************************************************
201 *
202 * @param[in] side
203 * Define which side of the cblk must be tested.
204 * @arg PastixLCoef if lower part only
205 * @arg PastixUCoef if upper part only
206 * @arg PastixLUCoef if both sides.
207 *
208 * @param[in] cblk
209 * The column block to pack.
210 *
211 * @param[in] size
212 * Size to allocate the buffer.
213 *
214 *******************************************************************************
215 *
216 * @return Pointer to the packed data.
217 *
218 *******************************************************************************/
219void *
221 SolverCblk *cblk,
222 size_t size )
223{
224 assert( cblk->cblktype & CBLK_COMPRESSED );
225
226 char *buffer = malloc(size);
227 char *tmp = buffer;
228
229 const SolverBlok *blok = cblk->fblokptr;
230 const SolverBlok *lblok = cblk[1].fblokptr;
231
232 pastix_int_t N = cblk_colnbr( cblk );
233
234 for ( ; blok < lblok; blok++ ) {
235 tmp = cpublok_spack_lr( side, N, blok, tmp );
236 }
237
238 assert( (side == PastixUCoef) || (cblk->lcoeftab == (void*)-1) );
239 assert( (side == PastixLCoef) || (cblk->ucoeftab == (void*)-1) );
240
241 return buffer;
242}
243
244/**
245 *******************************************************************************
246 *
247 * @brief Unpack low rank data and fill the block concerned by the computation.
248 *
249 *******************************************************************************
250 *
251 * @param[in] side
252 * Define which side of the cblk must be tested.
253 * @arg PastixLCoef if lower part only
254 * @arg PastixUCoef if upper part only
255 * @arg PastixLUCoef if both sides.
256 *
257 * @param[in] N
258 * Number of columns of the block.
259 *
260 * @param[inout] blok
261 * The block concerned by the computation.
262 *
263 * @param[inout] buffer
264 * Pointer on the packed data.
265 *
266 *******************************************************************************
267 *
268 * @return Pointer to the next block to unpack.
269 *
270 *******************************************************************************/
271char *
273 pastix_int_t N,
274 SolverBlok *blok,
275 char *buffer )
276{
277 pastix_int_t M = blok_rownbr( blok );
278
279 if ( side != PastixUCoef ) {
280 buffer = core_slrunpack( M, N, blok->LRblock[0], buffer );
281 }
282
283 if ( side != PastixLCoef ) {
284 buffer = core_slrunpack( M, N, blok->LRblock[1], buffer );
285 }
286
287 return buffer;
288}
289
290/**
291 *******************************************************************************
292 *
293 * @brief Unpack low rank data and fill the column block concerned by the computation.
294 *
295 *******************************************************************************
296 *
297 * @param[in] side
298 * Define which side of the cblk must be tested.
299 * @arg PastixLCoef if lower part only
300 * @arg PastixUCoef if upper part only
301 * @arg PastixLUCoef if both sides.
302 *
303 * @param[inout] cblk
304 * The column block to fill.
305 *
306 * @param[inout] buffer
307 * Pointer on packed data.
308 *
309 *******************************************************************************/
310void
312 SolverCblk *cblk,
313 void *buffer )
314{
315 assert( cblk->cblktype & CBLK_COMPRESSED );
316
317 SolverBlok *blok = cblk->fblokptr;
318 SolverBlok *lblok = cblk[1].fblokptr;
319 pastix_int_t N = cblk_colnbr( cblk );
320
321 cpucblk_salloc_lr( side, cblk, 0 );
322
323 for ( ; blok < lblok; blok++ ) {
324 buffer = cpublok_sunpack_lr( side, N, blok, buffer );
325 }
326}
327
328/**
329 *******************************************************************************
330 *
331 * @brief Pack data in full rank.
332 *
333 *******************************************************************************
334 *
335 * @param[in] side
336 * Define which side of the cblk must be tested.
337 * @arg PastixLCoef if lower part only
338 * @arg PastixUCoef if upper part only
339 * @arg PastixLUCoef if both sides.
340 *
341 * @param[in] cblk
342 * The column block that will be sent.
343 *
344 *******************************************************************************
345 *
346 * @return Pointer to the data buffer. Note that in full-rank, the data pointer is directly returned
347 * without data copy.
348 *
349 *******************************************************************************/
350void *
352 const SolverCblk *cblk )
353{
354 assert( !( cblk->cblktype & CBLK_COMPRESSED ) );
355
356 return side == PastixUCoef ? cblk->ucoeftab : cblk->lcoeftab;
357}
358
359/**
360 *******************************************************************************
361 *
362 * @brief Unpack data in full rank and fill the column block concerned by the computation.
363 *
364 *******************************************************************************
365 *
366 * @param[in] side
367 * Define which side of the cblk must be tested.
368 * @arg PastixLCoef if lower part only
369 * @arg PastixUCoef if upper part only
370 * @arg PastixLUCoef if both sides.
371 *
372 * @param[in] cblk
373 * The column block to unpack.
374 *
375 * @param[in] buffer
376 * Pointer on packed data.
377 *
378 *******************************************************************************/
379void
381 SolverCblk *cblk,
382 float *buffer )
383{
384 assert( !( cblk->cblktype & CBLK_COMPRESSED ) );
385
386 cblk->lcoeftab = buffer;
387 if ( side != PastixLCoef ) {
388 cblk->ucoeftab = buffer + ( cblk_colnbr( cblk ) * cblk->stride );
389 }
390}
391
392/**
393 *******************************************************************************
394 *
395 * @brief Pack a column block (Full rank or low rank).
396 *
397 *******************************************************************************
398 *
399 * @param[in] side
400 * Define which side of the cblk must be tested.
401 * @arg PastixLCoef if lower part only
402 * @arg PastixUCoef if upper part only
403 * @arg PastixLUCoef if both sides.
404 *
405 * @param[in] cblk
406 * The column block that will be sent.
407 *
408 * @param[in] size
409 * TODO
410 *
411 *******************************************************************************
412 *
413 * @return Pointer to the data buffer.
414 *
415 *******************************************************************************/
416void *
418 SolverCblk *cblk,
419 size_t size )
420{
421 if ( cblk->cblktype & CBLK_COMPRESSED ) {
422 return cpucblk_spack_lr( side, cblk, size );
423 }
424 else {
425 return cpucblk_spack_fr( side, cblk );
426 }
427}
428
429/**
430 *******************************************************************************
431 *
432 * @brief Unpack data and fill the column block concerned by the computation.
433 *
434 *******************************************************************************
435 *
436 * @param[in] side
437 * Define which side of the cblk must be tested.
438 * @arg PastixLCoef if lower part only
439 * @arg PastixUCoef if upper part only
440 * @arg PastixLUCoef if both sides.
441 *
442 * @param[inout] cblk
443 * The cblk to unpack.
444 *
445 * @param[in] buffer
446 * Pointer on packed data.
447 *
448 *******************************************************************************/
449void
451 SolverCblk *cblk,
452 void *buffer )
453{
454 if ( cblk->cblktype & CBLK_COMPRESSED ) {
455 cpucblk_sunpack_lr( side, cblk, buffer );
456
457 /*
458 * In low-rank, we created a copy so we need to directly free the
459 * reception buffer
460 */
461 free( buffer );
462 }
463 else {
464 cpucblk_sunpack_fr( side, cblk, buffer );
465 }
466}
char * cpublok_spack_lr(pastix_coefside_t side, pastix_uint_t N, const SolverBlok *blok, char *buffer)
Pack low-rank data for a block.
void cpucblk_sunpack(pastix_coefside_t side, SolverCblk *cblk, void *buffer)
Unpack data and fill the column block concerned by the computation.
void * cpucblk_spack_fr(pastix_coefside_t side, const SolverCblk *cblk)
Pack data in full rank.
pastix_uint_t cpucblk_scompute_size_lr(pastix_coefside_t side, const SolverCblk *cblk)
Compute the size of a column block to send in LR.
char * cpublok_sunpack_lr(pastix_coefside_t side, pastix_int_t N, SolverBlok *blok, char *buffer)
Unpack low rank data and fill the block concerned by the computation.
void * cpucblk_spack(pastix_coefside_t side, SolverCblk *cblk, size_t size)
Pack a column block (Full rank or low rank).
size_t cpublok_scompute_size_lr(pastix_coefside_t side, pastix_int_t N, const SolverBlok *blok)
Compute the size of a block to send in LR.
void cpucblk_sunpack_fr(pastix_coefside_t side, SolverCblk *cblk, float *buffer)
Unpack data in full rank and fill the column block concerned by the computation.
void * cpucblk_spack_lr(pastix_coefside_t side, SolverCblk *cblk, size_t size)
Pack low-rank data for column block.
size_t cpucblk_scompute_size(pastix_coefside_t side, const SolverCblk *cblk)
Compute the size of the buffer to send.
void cpucblk_sunpack_lr(pastix_coefside_t side, SolverCblk *cblk, void *buffer)
Unpack low rank data and fill the column block concerned by the computation.
BEGIN_C_DECLS typedef int pastix_int_t
Definition datatypes.h:51
void cpucblk_salloc_lr(pastix_coefside_t side, SolverCblk *cblk, int rkmax)
Allocate the cblk structure to store the coefficient.
char * core_slrpack(pastix_int_t M, pastix_int_t N, const pastix_lrblock_t *A, char *buffer)
Pack low-rank data by side.
size_t core_slrgetsize(pastix_int_t M, pastix_int_t N, pastix_lrblock_t *A)
Compute the size of a block to send in LR.
char * core_slrunpack(pastix_int_t M, pastix_int_t N, pastix_lrblock_t *A, char *buffer)
Unpack low rank data and fill the cblk concerned by the computation.
enum pastix_coefside_e pastix_coefside_t
Data blocks used in the kernel.
@ PastixLCoef
Definition api.h:478
@ PastixLUCoef
Definition api.h:480
@ PastixUCoef
Definition api.h:479
static pastix_int_t blok_rownbr(const SolverBlok *blok)
Compute the number of rows of a block.
Definition solver.h:395
void * ucoeftab
Definition solver.h:178
static pastix_int_t cblk_colnbr(const SolverCblk *cblk)
Compute the number of columns in a column block.
Definition solver.h:329
SolverBlok * fblokptr
Definition solver.h:168
pastix_lrblock_t * LRblock[2]
Definition solver.h:155
pastix_int_t stride
Definition solver.h:169
int8_t cblktype
Definition solver.h:164
void * lcoeftab
Definition solver.h:177
Solver block structure.
Definition solver.h:141
Solver column block structure.
Definition solver.h:161