PaStiX Handbook  6.3.2
pastix_starpu_interface.c
Go to the documentation of this file.
1 /**
2  *
3  * @file pastix_starpu_interface.c
4  *
5  * Interface used by StarPU to handle factorization.
6  *
7  * @copyright 2021-2023 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria,
8  * Univ. Bordeaux. All rights reserved.
9  *
10  * @version 6.3.2
11  * @author Nolan Bredel
12  * @author Mathieu Faverge
13  * @author Alycia Lisito
14  * @author Florent Pruvost
15  * @author Tom Moenne-Loccoz
16  * @date 2023-12-01
17  *
18  **/
19 #include "common/common.h"
21 #include "blend/solver.h"
26 #include "pastix_starpu.h"
27 
28 #ifndef DOXYGEN_SHOULD_SKIP_THIS
29 
30 #if defined(PASTIX_STARPU_INTERFACE_DEBUG)
31 #define pastix_starpu_logger fprintf( stderr, "pastix_starpu: %s\n", __func__ )
32 #else
33 #define pastix_starpu_logger do {} while(0)
34 #endif
35 
36 static inline void
37 psi_register_data_handle( starpu_data_handle_t handle, int home_node, void *data_interface )
38 {
39  pastix_starpu_interface_t *interf = (pastix_starpu_interface_t *)data_interface;
40  int node;
41 
42  pastix_starpu_logger;
43 
44  for ( node = 0; node < STARPU_MAXNODES; node++ ) {
45  pastix_starpu_interface_t *local_interface =
46  (pastix_starpu_interface_t *)starpu_data_get_interface_on_node( handle, node );
47 
48  memcpy( local_interface, interf, sizeof( pastix_starpu_interface_t ) );
49 
50  if ( node != home_node ) {
51  local_interface->dataptr = NULL;
52  }
53  }
54 }
55 
56 static inline starpu_ssize_t
57 psi_allocate_data_on_node( void *data_interface, unsigned node )
58 {
59  pastix_starpu_interface_t *interf = (pastix_starpu_interface_t *)data_interface;
60  starpu_ssize_t allocated_memory;
61  uintptr_t addr = 0;
62  uintptr_t handle;
63 
64  pastix_starpu_logger;
65 
66  allocated_memory = interf->allocsize;
67  if ( allocated_memory <= 0 ) {
68  return 0;
69  }
70 
71  handle = starpu_malloc_on_node( node, allocated_memory );
72  if ( !handle ) {
73  return -ENOMEM;
74  }
75 
76  if ( starpu_node_get_kind( node ) != STARPU_OPENCL_RAM ) {
77  addr = handle;
78  }
79 
80  /* update the data properly */
81  interf->dataptr = (void *)addr;
82 
83  /* /\* Allocate the workspace for the low-rank blocks *\/ */
84  /* if ( interf->cblk->cblktype & CBLK_COMPRESSED ) */
85  /* { */
86  /* SolverBlok *blok = interf->cblk->fblokptr; */
87  /* pastix_lrblock_t *LRblock = interf->dataptr; */
88  /* int offset = pastix_imax( 0, interf->offset ); */
89  /* int i, ncols, M; */
90 
91  /* assert( node == STARPU_MAIN_RAM ); */
92 
93  /* ncols = cblk_colnbr( interf->cblk ); */
94  /* blok += offset; */
95  /* for ( i = 0; i < interf->nbblok; i++, blok++, LRblock++ ) { */
96  /* M = blok_rownbr( blok ); */
97 
98  /* /\* Allocate the LR block to its max space *\/ */
99  /* switch ( interf->flttype ) { */
100  /* case PastixComplex64: */
101  /* core_zlralloc( M, ncols, -1, LRblock ); */
102  /* break; */
103  /* case PastixComplex32: */
104  /* core_clralloc( M, ncols, -1, LRblock ); */
105  /* break; */
106  /* case PastixDouble: */
107  /* core_dlralloc( M, ncols, -1, LRblock ); */
108  /* break; */
109  /* case PastixFloat: */
110  /* core_slralloc( M, ncols, -1, LRblock ); */
111  /* break; */
112  /* default: */
113  /* assert( 0 ); */
114  /* } */
115  /* } */
116  /* } */
117 
118  return allocated_memory;
119 }
120 
121 static inline void
122 psi_free_data_on_node( void *data_interface, unsigned node )
123 {
124  pastix_starpu_interface_t *interf = (pastix_starpu_interface_t *)data_interface;
125 
126  /* SolverCblk *cblk = interf->cblk; */
127 
128  pastix_starpu_logger;
129 
130  starpu_free_on_node( node, (uintptr_t)interf->dataptr, interf->allocsize );
131 
132  interf->dataptr = NULL;
133 }
134 
135 static inline void
136 psi_init( void *data_interface )
137 {
138  pastix_starpu_interface_t *interf = data_interface;
139  interf->id = PASTIX_STARPU_INTERFACE_ID;
140  interf->allocsize = -1;
141 
142  pastix_starpu_logger;
143 }
144 
145 static inline void *
146 psi_to_pointer( void *data_interface, unsigned node )
147 {
148  (void)node;
149  pastix_starpu_interface_t *interf = (pastix_starpu_interface_t *)data_interface;
150 
151  pastix_starpu_logger;
152 
153  return interf->dataptr;
154 }
155 
156 static inline size_t
157 psi_get_size( starpu_data_handle_t handle )
158 {
159  pastix_starpu_interface_t *interf =
160  starpu_data_get_interface_on_node( handle, STARPU_MAIN_RAM );
161  const SolverCblk *cblk = interf->cblk;
162  pastix_int_t ncols = cblk_colnbr( cblk );
163  size_t nrows;
164  size_t size;
165 
166  if ( interf->offset == -1 ) {
167  nrows = cblk->stride;
168  }
169  else {
170  SolverBlok *fblok = interf->cblk->fblokptr + interf->offset;
171  SolverBlok *lblok = fblok + interf->nbblok;
172 
173  nrows = 0;
174  for( ; fblok < lblok; fblok++ ) {
175  nrows += blok_rownbr( fblok );
176  }
177  }
178 
179  size = ncols * nrows;
180 
181 #ifdef STARPU_DEBUG
182  STARPU_ASSERT_MSG( interf->id == PASTIX_STARPU_INTERFACE_ID,
183  "psi_get_size: The given data is not a pastix interface for starpu." );
184 #endif
185 
186  return size;
187 }
188 
189 static inline size_t
190 psi_get_alloc_size( starpu_data_handle_t handle )
191 {
192  pastix_starpu_interface_t *interf =
193  starpu_data_get_interface_on_node( handle, STARPU_MAIN_RAM );
194 
195  pastix_starpu_logger;
196 
197 #ifdef STARPU_DEBUG
198  STARPU_ASSERT_MSG( interf->id == PASTIX_STARPU_INTERFACE_ID,
199  "psi_get_alloc_size: The given data is not a pastix interface for starpu." );
200 #endif
201 
202  STARPU_ASSERT_MSG( interf->allocsize != (size_t)-1,
203  "psi_get_alloc_size: The allocation size needs to be defined" );
204 
205  return interf->allocsize;
206 }
207 
208 static inline uint32_t
209 psi_footprint( starpu_data_handle_t handle )
210 {
211  pastix_starpu_interface_t *interf =
212  starpu_data_get_interface_on_node( handle, STARPU_MAIN_RAM );
213  const SolverCblk *cblk = interf->cblk;
214 
215  pastix_starpu_logger;
216 
217  return starpu_hash_crc32c_be( cblk->gcblknum, interf->offset + 1 );
218 }
219 
220 static inline uint32_t
221 psi_alloc_footprint( starpu_data_handle_t handle )
222 {
223  pastix_starpu_interface_t *interf =
224  starpu_data_get_interface_on_node( handle, STARPU_MAIN_RAM );
225 
226  pastix_starpu_logger;
227 
228  return starpu_hash_crc32c_be( interf->allocsize, 0 );
229 }
230 
231 static inline int
232 psi_compare( void *data_interface_a, void *data_interface_b )
233 {
234  pastix_starpu_interface_t *pastix_interface_a = (pastix_starpu_interface_t *)data_interface_a;
235  pastix_starpu_interface_t *pastix_interface_b = (pastix_starpu_interface_t *)data_interface_b;
236 
237  const SolverCblk *solva = pastix_interface_a->cblk;
238  const SolverCblk *solvb = pastix_interface_b->cblk;
239 
240  pastix_starpu_logger;
241 
242  /* Two interfaces are considered compatible if they point to the same solver */
243  return ( solva == solvb );
244 }
245 
246 static inline int
247 psi_alloc_compare( void *data_interface_a, void *data_interface_b )
248 {
249  pastix_starpu_interface_t *pastix_interface_a = (pastix_starpu_interface_t *)data_interface_a;
250  pastix_starpu_interface_t *pastix_interface_b = (pastix_starpu_interface_t *)data_interface_b;
251 
252  pastix_starpu_logger;
253 
254  /* Two matrices are considered compatible if they have the same allocated size */
255  return ( pastix_interface_a->allocsize == pastix_interface_b->allocsize );
256 }
257 
258 static inline void
259 psi_display( starpu_data_handle_t handle, FILE *f )
260 {
261  pastix_starpu_interface_t *interf =
262  (pastix_starpu_interface_t *)starpu_data_get_interface_on_node( handle, STARPU_MAIN_RAM );
263 
264  const SolverCblk *cblk = interf->cblk;
265 
266  pastix_starpu_logger;
267 
268  if ( interf->offset == -1 ) {
269  fprintf( f, "Cblk%ld", (long)( cblk->gcblknum ) );
270  }
271  else {
272  fprintf( f, "Cblk%ldBlok%ld", (long)( cblk->gcblknum ), (long)( interf->offset ) );
273  }
274 }
275 
276 static inline size_t
277 psi_compute_size_lr( pastix_starpu_interface_t *interf )
278 {
279  assert( interf->cblk->cblktype & CBLK_COMPRESSED );
280 
281  size_t elemsize = pastix_size_of( interf->flttype );
282  pastix_lrblock_t *LRblock = interf->dataptr;
283  pastix_int_t N = cblk_colnbr( interf->cblk );
284  pastix_int_t suv, M;
285 
286  SolverBlok *blok = interf->cblk->fblokptr + pastix_imax( 0, interf->offset );
287 
288  pastix_starpu_logger;
289 
290  suv = 0;
291  int i;
292  for ( i = 0; i < interf->nbblok; i++, blok++, LRblock++ ) {
293  M = blok_rownbr( blok );
294  suv += sizeof( int ) + core_zlrgetsize( M, N, LRblock ) * elemsize;
295  }
296  return suv;
297 }
298 
299 static inline size_t
300 psi_compute_size_fr( pastix_starpu_interface_t *interf )
301 {
302  assert( !( interf->cblk->cblktype & CBLK_COMPRESSED ) );
303 
304  pastix_starpu_logger;
305 
306  return interf->allocsize;
307 }
308 
309 static inline void
310 psi_pack_lr( pastix_starpu_interface_t *interf, void **ptr )
311 {
312  assert( interf->cblk->cblktype & CBLK_COMPRESSED );
313 
314  char *tmp = *ptr;
315  pastix_lrblock_t *LRblock = interf->dataptr;
316  int N = cblk_colnbr( interf->cblk );
317  int j = 0;
318  int M;
319 
320  SolverBlok *blok = interf->cblk->fblokptr + pastix_imax( 0, interf->offset );
321 
322  pastix_starpu_logger;
323 
324  for ( ; j < interf->nbblok; j++, blok++, LRblock++ ) {
325  M = blok_rownbr( blok );
326 
327  switch ( interf->flttype ) {
328  case PastixComplex64:
329  tmp = core_zlrpack( M, N, LRblock, tmp );
330  break;
331  case PastixComplex32:
332  tmp = core_clrpack( M, N, LRblock, tmp );
333  break;
334  case PastixDouble:
335  tmp = core_dlrpack( M, N, LRblock, tmp );
336  break;
337  case PastixFloat:
338  tmp = core_slrpack( M, N, LRblock, tmp );
339  break;
340  default:
341  assert( 0 );
342  }
343  }
344 }
345 
346 static inline void
347 psi_pack_fr( pastix_starpu_interface_t *interf, void **ptr, starpu_ssize_t *count )
348 {
349  assert( !( interf->cblk->cblktype & CBLK_COMPRESSED ) );
350 
351  pastix_starpu_logger;
352 
353  memcpy( *ptr, interf->dataptr, *count );
354 }
355 
356 static inline int
357 psi_pack_data( starpu_data_handle_t handle, unsigned node, void **ptr, starpu_ssize_t *count )
358 {
359  STARPU_ASSERT( starpu_data_test_if_allocated_on_node( handle, node ) );
360 
361  pastix_starpu_interface_t *interf =
362  (pastix_starpu_interface_t *)starpu_data_get_interface_on_node( handle, node );
363 
364  const SolverCblk *cblk = interf->cblk;
365 
366  pastix_starpu_logger;
367 
368  if ( cblk->cblktype & CBLK_COMPRESSED ) {
369  *count = psi_compute_size_lr( interf );
370  }
371  else {
372  *count = psi_compute_size_fr( interf );
373  }
374 
375  if ( ptr != NULL ) {
376  *ptr = (void *)starpu_malloc_on_node_flags( node, *count, 0 );
377 
378  if ( cblk->cblktype & CBLK_COMPRESSED ) {
379  psi_pack_lr( interf, ptr );
380  }
381  else {
382  psi_pack_fr( interf, ptr, count );
383  }
384  }
385 
386  return 0;
387 }
388 
389 static inline void
390 psi_unpack_lr( pastix_starpu_interface_t *interf, unsigned node, const void *ptr, size_t count )
391 {
392  SolverBlok *blok = interf->cblk->fblokptr + pastix_imax( 0, interf->offset );
393  pastix_lrblock_t *LRblock;
394  const char *input = ptr;
395  char *output;
396  size_t lrsize = interf->nbblok * sizeof( pastix_lrblock_t );
397  int N = cblk_colnbr( interf->cblk );
398  int i;
399 
400  pastix_starpu_logger;
401 
402  assert( interf->cblk->cblktype & CBLK_COMPRESSED );
403  assert( interf->allocsize == 0 );
404 
405  /* Remove the size of all the rk */
406  count -= interf->nbblok * sizeof( int );
407 
408  interf->allocsize = count + lrsize;
409  psi_allocate_data_on_node( interf, node );
410 
411  LRblock = interf->dataptr;
412  output = interf->dataptr;
413  output += lrsize;
414 
415  for ( i=0; i < interf->nbblok; i++, blok++, LRblock++ ) {
416  int M = blok_rownbr( blok );
417 
418  /* Allocate the LR block to its tight space */
419  switch ( interf->flttype ) {
420  case PastixComplex64:
421  input = core_zlrunpack2( M, N, LRblock, input, &output );
422  break;
423  case PastixComplex32:
424  input = core_clrunpack2( M, N, LRblock, input, &output );
425  break;
426  case PastixDouble:
427  input = core_dlrunpack2( M, N, LRblock, input, &output );
428  break;
429  case PastixFloat:
430  input = core_slrunpack2( M, N, LRblock, input, &output );
431  break;
432  default:
433  assert( 0 );
434  }
435  }
436 }
437 
438 static inline void
439 psi_unpack_fr( pastix_starpu_interface_t *interf, void *ptr, size_t count )
440 {
441  pastix_starpu_logger;
442 
443  assert( count == interf->allocsize );
444  memcpy( interf->dataptr, ptr, count );
445 }
446 
447 static inline int
448 psi_peek_data( starpu_data_handle_t handle, unsigned node, void *ptr, size_t count )
449 {
450  pastix_starpu_interface_t *interf =
451  (pastix_starpu_interface_t *)starpu_data_get_interface_on_node( handle, node );
452 
453  STARPU_ASSERT( starpu_data_test_if_allocated_on_node( handle, node ) );
454 
455  pastix_starpu_logger;
456 
457  if ( interf->cblk->cblktype & CBLK_COMPRESSED ) {
458  psi_unpack_lr( interf, node, ptr, count );
459  }
460  else {
461  psi_unpack_fr( interf, ptr, count );
462  }
463 
464  return 0;
465 }
466 
467 static inline int
468 psi_unpack_data( starpu_data_handle_t handle, unsigned node, void *ptr, size_t count )
469 {
470  pastix_starpu_logger;
471 
472  psi_peek_data( handle, node, ptr, count );
473 
474  /* Free the received information */
475  starpu_free_on_node_flags( node, (uintptr_t)ptr, count, 0 );
476 
477  return 0;
478 }
479 
480 static inline starpu_ssize_t
481 psi_describe( void *data_interface, char *buf, size_t size )
482 {
483  pastix_starpu_interface_t *interf = (pastix_starpu_interface_t *)data_interface;
484  const SolverCblk *cblk = interf->cblk;
485 
486  pastix_starpu_logger;
487 
488  return snprintf( buf, size, "Cblk%ld", (long)( cblk->gcblknum ) );
489 }
490 
491 static inline int
492 psi_copy_any_to_any( void *src_interface,
493  unsigned src_node,
494  void *dst_interface,
495  unsigned dst_node,
496  void *async_data )
497 {
498  pastix_starpu_interface_t *pastix_src = (pastix_starpu_interface_t *)src_interface;
499  pastix_starpu_interface_t *pastix_dst = (pastix_starpu_interface_t *)dst_interface;
500 
501  int ret = 0;
502 
503  pastix_starpu_logger;
504 
505  assert( !( pastix_src->cblk->cblktype & CBLK_COMPRESSED ) );
506 
507  if ( starpu_interface_copy( (uintptr_t)pastix_src->dataptr, 0, src_node,
508  (uintptr_t)pastix_dst->dataptr, 0, dst_node,
509  pastix_src->allocsize,
510  async_data ) )
511  {
512  ret = -EAGAIN;
513  }
514  starpu_interface_data_copy( src_node, dst_node, pastix_src->allocsize );
515 
516  return ret;
517 }
518 
519 static const struct starpu_data_copy_methods psi_copy_methods = {
520  .any_to_any = psi_copy_any_to_any,
521 };
522 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
523 
524 /**
525  * @ingroup pastix_starpu
526  * @{
527  *
528  * @brief TODO
529  */
530 struct starpu_data_interface_ops pastix_starpu_interface_ops = {
531  .register_data_handle = psi_register_data_handle,
532  .allocate_data_on_node = psi_allocate_data_on_node,
533  .free_data_on_node = psi_free_data_on_node,
534  .init = psi_init,
535  .copy_methods = &psi_copy_methods,
536  .to_pointer = psi_to_pointer,
537  .get_size = psi_get_size,
538  .get_alloc_size = psi_get_alloc_size,
539  .footprint = psi_footprint,
540  .alloc_footprint = psi_alloc_footprint,
541  .compare = psi_compare,
542  .alloc_compare = psi_alloc_compare,
543  .display = psi_display,
544  .describe = psi_describe,
545  .pack_data = psi_pack_data,
546 #if defined( HAVE_STARPU_DATA_PEEK )
547  .peek_data = psi_peek_data,
548 #endif
549  .unpack_data = psi_unpack_data,
550  .interfaceid = STARPU_UNKNOWN_INTERFACE_ID,
551  .interface_size = sizeof( pastix_starpu_interface_t ),
552  .dontcache = 0, /* Should we set it to 1 */
553  .name = "PASTIX_STARPU_INTERFACE"
554 };
555 
556 /**
557  *******************************************************************************
558  *
559  * @brief Initialize the interface ID
560  *
561  ********************************************************************************/
562 void
564 {
565  if ( pastix_starpu_interface_ops.interfaceid == STARPU_UNKNOWN_INTERFACE_ID ) {
566  pastix_starpu_interface_ops.interfaceid = starpu_data_interface_get_next_id();
567 
568  /*
569  * TODO : Add mpi datatype
570  */
571 
572  /* #if defined(PASTIX_STARPU_USE_MPI_DATATYPES) */
573  /* #if defined(HAVE_STARPU_MPI_INTERFACE_DATATYPE_NODE_REGISTER) */
574  /* starpu_mpi_interface_datatype_node_register( pastix_starpu_interface_ops.interfaceid, */
575  /* psi_allocate_datatype_node, */
576  /* psi_free_datatype ); */
577  /* #else */
578  /* starpu_mpi_interface_datatype_register( pastix_starpu_interface_ops.interfaceid, */
579  /* psi_allocate_datatype, */
580  /* psi_free_datatype ); */
581  /* #endif */
582  /* #endif */
583  }
584 }
585 
586 /**
587  *******************************************************************************
588  *
589  * @brief Finalize the interface and reset the ID
590  *
591  ********************************************************************************/
592 void
594 {
595  if ( pastix_starpu_interface_ops.interfaceid != STARPU_UNKNOWN_INTERFACE_ID ) {
596  /* #if defined(PASTIX_STARPU_USE_MPI_DATATYPES) */
597  /* starpu_mpi_interface_datatype_unregister( pastix_starpu_interface_ops.interfaceid ); */
598  /* #endif */
599  pastix_starpu_interface_ops.interfaceid = STARPU_UNKNOWN_INTERFACE_ID;
600  }
601 }
602 
603 /**
604  *
605  *******************************************************************************
606  *
607  * @brief Register a cblk at the StarPU level
608  *
609  *******************************************************************************
610  *
611  * @param[out] handleptr
612  * The StarPU data handle to the registered data. Space must be allocated on call.
613  *
614  * @param[in] home_node
615  * The StarPU memory node enum to specify where the initial data is located
616  * -1 if not local, STARPU_MAIN_RAM if local.
617  *
618  * @param[in] cblk
619  * The cblk to register
620  *
621  * @param[in] side
622  * Specify which part of the cblk (Upper or Lower) to register
623  *
624  * @param[in] flttype
625  * Specify the arithmetic floating type of the coefficients
626  *
627  ********************************************************************************/
628 void
629 pastix_starpu_register( starpu_data_handle_t *handleptr,
630  const SolverCblk *cblk,
631  pastix_coefside_t side,
632  pastix_coeftype_t flttype )
633 {
634  pastix_starpu_interface_t interf = {
636  .flttype = flttype,
637  .offset = -1,
638  .nbblok = 0,
639  .allocsize = -1,
640  .cblk = cblk,
641  .dataptr = NULL,
642  };
643  SolverBlok *fblok = cblk[0].fblokptr;
644  SolverBlok *lblok = cblk[1].fblokptr;
645  size_t size = 0;
646  int home_node = -1;
647 
648  assert( side != PastixLUCoef );
649 
650  pastix_starpu_logger;
651 
652  /*
653  * Get the right dataptr
654  * coeftab if the cblk is not compressed
655  * else lrblock
656  */
657  if ( !( cblk->cblktype & CBLK_COMPRESSED ) ) {
658  size = cblk->stride * cblk_colnbr( cblk ) * pastix_size_of( flttype );
659  interf.dataptr = side == PastixLCoef ? cblk->lcoeftab : cblk->ucoeftab;
660  if ( interf.dataptr != NULL ) {
661  home_node = STARPU_MAIN_RAM;
662  }
663  }
664  else {
665  interf.dataptr = cblk->fblokptr->LRblock[side];
666  if ( interf.dataptr != NULL )
667  {
668  size = ( lblok - fblok ) * sizeof( pastix_lrblock_t );
669  home_node = STARPU_MAIN_RAM;
670  }
671  }
672 
673  interf.nbblok = lblok - fblok;
674  interf.allocsize = size;
675 
676 #if defined(PASTIX_STARPU_INTERFACE_DEBUG)
677  fprintf( stderr,
678  "cblk (%9s, size=%8zu, nbblok=%2ld )\n",
679  cblk->cblktype & CBLK_COMPRESSED ? "Low-rank" : "Full-rank",
680  interf.allocsize, (long)(interf.nbblok) );
681 #endif
682 
683  starpu_data_register( handleptr, home_node, &interf, &pastix_starpu_interface_ops );
684 }
685 
686 void
687 pastix_starpu_register_ws( starpu_data_handle_t *handleptr,
688  const SolverCblk *cblk,
689  pastix_coeftype_t flttype )
690 {
691  pastix_starpu_interface_t interf = {
693  .flttype = flttype,
694  .offset = -1,
695  .nbblok = 0,
696  .allocsize = -1,
697  .cblk = cblk,
698  .dataptr = NULL,
699  };
700  SolverBlok *fblok = cblk[0].fblokptr;
701  SolverBlok *lblok = cblk[1].fblokptr;
702  size_t size = 0;
703  pastix_int_t M = cblk->stride;
704  pastix_int_t N = cblk_colnbr( cblk );
705 
706  pastix_starpu_logger;
707 
708  /*
709  * Get the correct size to allocate
710  */
711  interf.nbblok = lblok - fblok;
712  if ( (M - N) > 0 ) /* Check for useless cases where we have only a diagonal block */
713  {
714  if ( (cblk->cblktype & CBLK_COMPRESSED) &&
715  (cblk_getdataL( cblk ) != NULL) )
716  {
717  size = M * N * pastix_size_of( flttype );
718  size += interf.nbblok * sizeof( pastix_lrblock_t );
719  }
720 
721  if ( !(cblk->cblktype & CBLK_COMPRESSED) )
722  {
723  size = M * N * pastix_size_of( flttype );
724  }
725  }
726  interf.allocsize = size;
727 
728 #if defined(PASTIX_STARPU_INTERFACE_DEBUG)
729  fprintf( stderr,
730  "cblk (%9s, size=%8zu, nbblok=%2ld )\n",
731  cblk->cblktype & CBLK_COMPRESSED ? "Low-rank" : "Full-rank",
732  interf.allocsize, (long)(interf.nbblok) );
733 #endif
734 
735  starpu_data_register( handleptr, -1, &interf, &pastix_starpu_interface_ops );
736 }
737 
738 void
739 pastix_starpu_register_blok( starpu_data_handle_t *handleptr,
740  const SolverCblk *cblk,
741  const SolverBlok *blok,
742  pastix_coeftype_t flttype )
743 {
744  pastix_starpu_interface_t interf = {
746  .flttype = flttype,
747  .offset = -1,
748  .nbblok = 1,
749  .allocsize = -1,
750  .cblk = cblk,
751  .dataptr = NULL,
752  };
753  SolverBlok *fblok = cblk[0].fblokptr;
754  SolverBlok *lblok = cblk[1].fblokptr;
755  size_t size = 0;
756  pastix_int_t M = blok_rownbr( blok );
757  pastix_int_t N = cblk_colnbr( cblk );
758 
759  pastix_starpu_logger;
760 
761  /* Count the number of blocks and number of rows */
762  {
763  const SolverBlok *cblok = blok;
764 
765  while( (cblok[0].lcblknm == cblok[1].lcblknm) &&
766  (cblok[0].fcblknm == cblok[1].fcblknm) )
767  {
768  cblok++;
769  interf.nbblok++;
770  M += blok_rownbr( cblok );
771  }
772  }
773 
774  /*
775  * Get the right dataptr
776  * coeftab if the cblk is not compressed
777  * else lrblock
778  */
779  if ( !( cblk->cblktype & CBLK_COMPRESSED ) )
780  {
781  size = M * N * pastix_size_of( flttype );
782  }
783 
784  interf.nbblok = lblok - fblok;
785  interf.allocsize = size;
786 
787 #if defined(PASTIX_STARPU_INTERFACE_DEBUG)
788  fprintf( stderr,
789  "cblk (%9s, size=%8zu, nbblok=%2ld )\n",
790  cblk->cblktype & CBLK_COMPRESSED ? "Low-rank" : "Full-rank",
791  interf.allocsize, (long)(interf.nbblok) );
792 #endif
793 
794  starpu_data_register( handleptr, -1, &interf, &pastix_starpu_interface_ops );
795 }
796 /**
797  * @}
798  */
BEGIN_C_DECLS typedef int pastix_int_t
Definition: datatypes.h:51
struct pastix_lrblock_s pastix_lrblock_t
The block low-rank structure to hold a matrix in low-rank form.
The block low-rank structure to hold a matrix in low-rank form.
const char * core_slrunpack2(pastix_int_t M, pastix_int_t N, pastix_lrblock_t *A, const char *input, char **outptr)
Unpack low rank data and fill the cblk concerned by the computation.
char * core_clrpack(pastix_int_t M, pastix_int_t N, const pastix_lrblock_t *A, char *buffer)
Pack low-rank data by side.
char * core_slrpack(pastix_int_t M, pastix_int_t N, const pastix_lrblock_t *A, char *buffer)
Pack low-rank data by side.
char * core_dlrpack(pastix_int_t M, pastix_int_t N, const pastix_lrblock_t *A, char *buffer)
Pack low-rank data by side.
const char * core_dlrunpack2(pastix_int_t M, pastix_int_t N, pastix_lrblock_t *A, const char *input, char **outptr)
Unpack low rank data and fill the cblk concerned by the computation.
const char * core_clrunpack2(pastix_int_t M, pastix_int_t N, pastix_lrblock_t *A, const char *input, char **outptr)
Unpack low rank data and fill the cblk concerned by the computation.
char * core_zlrpack(pastix_int_t M, pastix_int_t N, const pastix_lrblock_t *A, char *buffer)
Pack low-rank data by side.
const char * core_zlrunpack2(pastix_int_t M, pastix_int_t N, pastix_lrblock_t *A, const char *input, char **outptr)
Unpack low rank data and fill the cblk concerned by the computation.
size_t core_zlrgetsize(pastix_int_t M, pastix_int_t N, pastix_lrblock_t *A)
Compute the size of a block to send in LR.
spm_coeftype_t pastix_coeftype_t
Arithmetic types.
Definition: api.h:294
enum pastix_coefside_e pastix_coefside_t
Data blocks used in the kernel.
@ PastixLCoef
Definition: api.h:478
@ PastixLUCoef
Definition: api.h:480
enum starpu_data_interface_id id
const SolverCblk * cblk
pastix_coeftype_t flttype
struct starpu_data_interface_ops pastix_starpu_interface_ops
TODO.
void pastix_starpu_interface_init()
Initialize the interface ID.
void pastix_starpu_interface_fini()
Finalize the interface and reset the ID.
#define PASTIX_STARPU_INTERFACE_ID
Alias to get the Interface id.
struct pastix_starpu_interface_s pastix_starpu_interface_t
Interface data structure to register the pieces of data in StarPU.
void pastix_starpu_register(starpu_data_handle_t *handleptr, const SolverCblk *cblk, pastix_coefside_t side, pastix_coeftype_t flttype)
Register a cblk at the StarPU level.
Interface data structure to register the pieces of data in StarPU.
static pastix_int_t blok_rownbr(const SolverBlok *blok)
Compute the number of rows of a block.
Definition: solver.h:390
void * ucoeftab
Definition: solver.h:172
static pastix_int_t cblk_colnbr(const SolverCblk *cblk)
Compute the number of columns in a column block.
Definition: solver.h:324
SolverBlok * fblokptr
Definition: solver.h:163
static void * cblk_getdataL(const SolverCblk *cblk)
Get the pointer to the data associated to the lower part of the cblk.
Definition: solver.h:337
pastix_lrblock_t * LRblock[2]
Definition: solver.h:150
pastix_int_t gcblknum
Definition: solver.h:169
pastix_int_t stride
Definition: solver.h:164
int8_t cblktype
Definition: solver.h:159
void * lcoeftab
Definition: solver.h:171
Solver block structure.
Definition: solver.h:137
Solver column block structure.
Definition: solver.h:156