PaStiX Handbook  6.3.2
codelet_blok_dpotrfsp.c
Go to the documentation of this file.
1 /**
2  *
3  * @file codelet_blok_dpotrfsp.c
4  *
5  * StarPU codelets for Cholesky functions
6  *
7  * @copyright 2016-2023 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria,
8  * Univ. Bordeaux. All rights reserved.
9  *
10  * @version 6.3.2
11  * @author Mathieu Faverge
12  * @author Pierre Ramet
13  * @author Ian Masliah
14  * @author Tom Moenne-Loccoz
15  * @date 2023-07-21
16  *
17  * @generated from /builds/solverstack/pastix/sopalin/starpu/codelet_blok_zpotrfsp.c, normal z -> d, Wed Dec 13 12:09:26 2023
18  *
19  * @addtogroup pastix_starpu
20  * @{
21  *
22  **/
23 #ifndef DOXYGEN_SHOULD_SKIP_THIS
24 #define _GNU_SOURCE
25 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
26 #include "common.h"
27 #include "blend/solver.h"
28 #include "sopalin/sopalin_data.h"
29 #include "pastix_dcores.h"
30 #include "pastix_starpu.h"
31 #include "pastix_dstarpu.h"
32 #include "codelets.h"
33 
34 /**
35  * @brief Main structure for all tasks of blok_dpotrfsp type
36  */
37 struct cl_blok_dpotrfsp_args_s {
38  profile_data_t profile_data;
39  sopalin_data_t *sopalin_data;
40  SolverCblk *cblk;
41 };
42 
43 #if defined(PASTIX_STARPU_PROFILING)
44 /**
45  * @brief Functions to profile the codelet
46  *
47  * Two levels of profiling are available:
48  * 1) A generic one that returns the flops per worker
49  * 2) A more detailed one that generate logs of the performance for each kernel
50  */
51 starpu_profile_t blok_dpotrfsp_profile = {
52  .next = NULL,
53  .name = "blok_dpotrfsp"
54 };
55 
56 /**
57  * @brief Profiling registration function
58  */
59 void blok_dpotrfsp_profile_register( void ) __attribute__( ( constructor ) );
60 void
61 blok_dpotrfsp_profile_register( void )
62 {
63  profiling_register_cl( &blok_dpotrfsp_profile );
64 }
65 
66 #ifndef DOXYGEN_SHOULD_SKIP_THIS
67 #if defined(PASTIX_STARPU_PROFILING_LOG)
68 static void
69 cl_profiling_cb_blok_dpotrfsp( void *callback_arg )
70 {
71  cl_profiling_callback( callback_arg );
72 
73  struct starpu_task *task = starpu_task_get_current();
74  struct starpu_profiling_task_info *info = task->profiling_info;
75 
76  /* Quick return */
77  if ( info == NULL ) {
78  return;
79  }
80 
81  struct cl_blok_dpotrfsp_args_s *args = (struct cl_blok_dpotrfsp_args_s *) callback_arg;
82  pastix_fixdbl_t flops = args->profile_data.flops;
83  pastix_fixdbl_t duration = starpu_timing_timespec_delay_us( &info->start_time, &info->end_time );
84  pastix_fixdbl_t speed = flops / ( 1000.0 * duration );
85 
86  pastix_int_t N = cblk_colnbr( args->cblk );
87 
88  cl_profiling_log_register( task->name, "blok_dpotrfsp", N, 0, 0, flops, speed );
89 }
90 #endif
91 
92 #if defined(PASTIX_STARPU_PROFILING_LOG)
93 static void (*blok_dpotrfsp_callback)(void*) = cl_profiling_cb_blok_dpotrfsp;
94 #else
95 static void (*blok_dpotrfsp_callback)(void*) = cl_profiling_callback;
96 #endif
97 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
98 
99 #endif /* defined(PASTIX_STARPU_PROFILING) */
100 
101 /**
102  *******************************************************************************
103  *
104  * @brief Cost model function
105  *
106  * The user can switch from the pastix static model to an history based model
107  * computed automatically.
108  *
109  *******************************************************************************
110  *
111  * @param[in] task
112  * TODO
113  *
114  * @param[in] arch
115  * TODO
116  *
117  * @param[in] nimpl
118  * TODO
119  *
120  *******************************************************************************
121  *
122  * @retval TODO
123  *
124  *******************************************************************************/
125 static inline pastix_fixdbl_t
126 fct_blok_dpotrfsp_cost( struct starpu_task *task,
127  struct starpu_perfmodel_arch *arch,
128  unsigned nimpl )
129 {
130  struct cl_blok_dpotrfsp_args_s *args = (struct cl_blok_dpotrfsp_args_s *)(task->cl_arg);
131 
132  pastix_fixdbl_t cost = 0.;
133  pastix_fixdbl_t *coefs;
134  pastix_int_t N = cblk_colnbr( args->cblk );
135 
136  switch( arch->devices->type ) {
137  case STARPU_CPU_WORKER:
138  coefs = &(args->sopalin_data->cpu_models->coefficients[PastixDouble-2][PastixKernelPOTRF][0]);
139  break;
140  case STARPU_CUDA_WORKER:
141  coefs = &(args->sopalin_data->gpu_models->coefficients[PastixDouble-2][PastixKernelPOTRF][0]);
142  break;
143  default:
144  assert(0);
145  return 0.;
146  }
147 
148  /* Get cost in us */
149  cost = modelsGetCost1Param( coefs, N );
150 
151  (void)nimpl;
152  return cost;
153 }
154 
155 #ifndef DOXYGEN_SHOULD_SKIP_THIS
156 static struct starpu_perfmodel starpu_blok_dpotrfsp_model = {
157 #if defined(PASTIX_STARPU_COST_PER_ARCH)
158  .type = STARPU_PER_ARCH,
159  .arch_cost_function = fct_blok_dpotrfsp_cost,
160 #else
161  .type = STARPU_HISTORY_BASED,
162 #endif
163  .symbol = "blok_dpotrfsp",
164 };
165 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
166 
167 #if !defined(PASTIX_STARPU_SIMULATION)
168 /**
169  *******************************************************************************
170  *
171  * @brief StarPU CPU implementation
172  *
173  *******************************************************************************
174  *
175  * @param[in] descr
176  * TODO
177  *
178  * @param[in] cl_arg
179  * TODO
180  *
181  *******************************************************************************/
182 static void
183 fct_blok_dpotrfsp_cpu( void *descr[], void *cl_arg )
184 {
185  struct cl_blok_dpotrfsp_args_s *args = (struct cl_blok_dpotrfsp_args_s *)cl_arg;
186  void *L;
187 
188  L = pastix_starpu_blok_get_ptr( descr[0] );
189 
190  assert( args->cblk->cblktype & CBLK_TASKS_2D );
191 
192  cpucblk_dpotrfsp1d_potrf( args->sopalin_data->solvmtx, args->cblk, L );
193 }
194 #endif /* !defined(PASTIX_STARPU_SIMULATION) */
195 
196 #ifndef DOXYGEN_SHOULD_SKIP_THIS
197 CODELETS_CPU( blok_dpotrfsp, 1 );
198 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
199 
200 /**
201  *******************************************************************************
202  *
203  * @brief TODO
204  *
205  *******************************************************************************
206  *
207  * @param[in] sopalin_data
208  * TODO
209  *
210  * @param[in] cblk
211  * TODO
212  *
213  * @param[in] prio
214  * TODO
215  *
216  *******************************************************************************/
217 void
218 starpu_task_blok_dpotrf( sopalin_data_t *sopalin_data,
219  SolverCblk *cblk,
220  int prio )
221 {
222  struct cl_blok_dpotrfsp_args_s *cl_arg = NULL;
223  int need_exec = 1;
224 #if defined(PASTIX_DEBUG_STARPU)
225  char *task_name;
226 #endif
227 
228  /*
229  * Check if it needs to be submitted
230  */
231 #if defined(PASTIX_WITH_MPI)
232  {
233  int need_submit = 0;
234  if ( cblk->ownerid == sopalin_data->solvmtx->clustnum ) {
235  need_submit = 1;
236  }
237  else {
238  need_exec = 0;
239  }
240  if ( starpu_mpi_cached_receive( cblk->fblokptr->handler[0] ) ) {
241  need_submit = 1;
242  }
243  if ( !need_submit ) {
244  return;
245  }
246  }
247 #endif
248 
249  /*
250  * Create the arguments array
251  */
252  if ( need_exec ) {
253  cl_arg = malloc( sizeof( struct cl_blok_dpotrfsp_args_s) );
254  cl_arg->sopalin_data = sopalin_data;
255 #if defined(PASTIX_STARPU_PROFILING)
256  cl_arg->profile_data.measures = blok_dpotrfsp_profile.measures;
257  cl_arg->profile_data.flops = NAN;
258 #endif
259  cl_arg->cblk = cblk;
260  }
261 
262 #if defined(PASTIX_DEBUG_STARPU)
263  /* This actually generates a memory leak */
264  asprintf( &task_name, "%s( %ld )",
265  cl_blok_dpotrfsp_cpu.name,
266  (long)(cblk - sopalin_data->solvmtx->cblktab) );
267 #endif
268 
269  pastix_starpu_insert_task(
270  &cl_blok_dpotrfsp_cpu,
271  STARPU_CL_ARGS, cl_arg, sizeof( struct cl_blok_dpotrfsp_args_s ),
272 #if defined(PASTIX_STARPU_PROFILING)
273  STARPU_CALLBACK_WITH_ARG_NFREE, blok_dpotrfsp_callback, cl_arg,
274 #endif
275  STARPU_RW, cblk->fblokptr->handler[0],
276 #if defined(PASTIX_DEBUG_STARPU)
277  STARPU_NAME, task_name,
278 #endif
279 #if defined(PASTIX_STARPU_HETEROPRIO)
280  STARPU_PRIORITY, BucketFacto2D,
281 #else
282  STARPU_PRIORITY, prio,
283 #endif
284  0);
285  (void)prio;
286 }
287 
288 /**
289  * @}
290  */
BEGIN_C_DECLS typedef int pastix_int_t
Definition: datatypes.h:51
double pastix_fixdbl_t
Definition: datatypes.h:65
@ PastixKernelPOTRF
Definition: kernels_enums.h:50
int cpucblk_dpotrfsp1d_potrf(SolverMatrix *solvmtx, SolverCblk *cblk, void *dataL)
Compute the Cholesky factorization of the diagonal block in a panel.
static pastix_fixdbl_t fct_blok_dpotrfsp_cost(struct starpu_task *task, struct starpu_perfmodel_arch *arch, unsigned nimpl)
Cost model function.
void starpu_task_blok_dpotrf(sopalin_data_t *sopalin_data, SolverCblk *cblk, int prio)
TODO.
static void fct_blok_dpotrfsp_cpu(void *descr[], void *cl_arg)
StarPU CPU implementation.
Base structure to all codelet arguments that include the profiling data.
static double cost(symbol_cblk_t *cblk)
Computes the cost of a cblk.
void * handler[2]
Definition: solver.h:138
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
int ownerid
Definition: solver.h:175
Solver column block structure.
Definition: solver.h:156