PaStiX Handbook  6.4.0
codelet_solve_sgemm.c
Go to the documentation of this file.
1 /**
2  *
3  * @file codelet_solve_sgemm.c
4  *
5  * StarPU codelet for gemm function
6  *
7  * @copyright 2016-2024 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria,
8  * Univ. Bordeaux. All rights reserved.
9  *
10  * @version 6.4.0
11  * @author Vincent Bridonneau
12  * @author Mathieu Faverge
13  * @author Pierre Ramet
14  * @author Alycia Lisito
15  * @author Nolan Bredel
16  * @author Tom Moenne-Loccoz
17  * @date 2024-07-05
18  *
19  * @generated from /builds/solverstack/pastix/sopalin/starpu/codelet_solve_zgemm.c, normal z -> s, Fri Jul 12 15:10:00 2024
20  *
21  * @addtogroup pastix_starpu
22  * @{
23  *
24  **/
25 #ifndef DOXYGEN_SHOULD_SKIP_THIS
26 #define _GNU_SOURCE
27 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
28 #include "common.h"
29 #include "blend/solver.h"
30 #include "sopalin/sopalin_data.h"
31 #include "pastix_scores.h"
32 #include "pastix_starpu.h"
33 #include "pastix_sstarpu.h"
34 #include "codelets.h"
35 
36 #if defined( PASTIX_STARPU_PROFILING )
37 /**
38  * @brief Block version
39  */
40 starpu_profile_t solve_blok_sgemm_profile = {
41  .next = NULL,
42  .name = "solve_blok_sgemm"
43 };
44 
45 /**
46  * @brief Profiling registration function
47  */
48 void solve_blok_sgemm_profile_register( void ) __attribute__( ( constructor ) );
49 void
50 solve_blok_sgemm_profile_register( void )
51 {
52  profiling_register_cl( &solve_blok_sgemm_profile );
53 }
54 #endif
55 
56 #ifndef DOXYGEN_SHOULD_SKIP_THIS
57 struct cl_solve_blok_sgemm_args_s {
58  profile_data_t profile_data;
59  pastix_side_t side;
60  pastix_trans_t trans;
61  const SolverCblk *cblk;
62  const SolverBlok *blok;
63  SolverCblk *fcbk;
64 };
65 
66 static struct starpu_perfmodel starpu_solve_blok_sgemm_model = {
67  .type = STARPU_HISTORY_BASED,
68  .symbol = "solve_blok_sgemm",
69 };
70 
71 #if !defined(PASTIX_STARPU_SIMULATION)
72 static void
73 fct_solve_blok_sgemm_cpu( void *descr[], void *cl_arg )
74 {
75  const void *dataA = NULL;
76  const pastix_lrblock_t *lrA;
77  const float *A;
78  float *B, *C;
79  pastix_int_t nrhs, ldb, ldc;
80  struct cl_solve_blok_sgemm_args_s *args = (struct cl_solve_blok_sgemm_args_s *)cl_arg;
81 
82  dataA = pastix_starpu_cblk_get_ptr( descr[0] );
83  B = (float *)STARPU_MATRIX_GET_PTR( descr[1] );
84  ldb = (pastix_int_t) STARPU_MATRIX_GET_LD( descr[1] );
85  nrhs = (pastix_int_t) STARPU_MATRIX_GET_NY( descr[1] );
86  C = (float *)STARPU_MATRIX_GET_PTR( descr[2] );
87  ldc = (pastix_int_t) STARPU_MATRIX_GET_LD( descr[2] );
88 
89  /*
90  * Make sure we get the correct pointer to the lrA, or to the right position in [lu]coeftab
91  */
92  if ( (args->side == PastixLeft) && (args->cblk->cblktype & CBLK_COMPRESSED) ) {
93  lrA = dataA;
94  lrA += (args->blok - args->cblk->fblokptr);
95  dataA = lrA;
96  }
97  else if ( (args->side == PastixRight) && (args->fcbk->cblktype & CBLK_COMPRESSED) ) {
98  lrA = dataA;
99  lrA += (args->blok - args->fcbk->fblokptr);
100  dataA = lrA;
101  }
102  else {
103  A = dataA;
104  A += args->blok->coefind;
105  dataA = A;
106  }
107 
108  solve_blok_sgemm( args->side, args->trans, nrhs,
109  args->cblk, args->blok, args->fcbk, dataA, B, ldb, C, ldc );
110 }
111 #endif /* !defined(PASTIX_STARPU_SIMULATION) */
112 
113 CODELETS_CPU( solve_blok_sgemm, 3 );
114 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
115 
116 /**
117  *******************************************************************************
118  *
119  * @brief Submit a task to perform a gemm.
120  *
121  *******************************************************************************
122  *
123  * @param[in] coef
124  * Specify whether the computation are made with the L part, or the U
125  * part of A. It has to be either PastixLCoef, or PastixUCoef.
126  *
127  * @param[inout] rhsb
128  * The pointer to the rhs data structure that holds the vectors of the
129  * right hand side.
130  *
131  * @param[in] side
132  * Specify the side parameter of the TRSM.
133  *
134  * @param[in] trans
135  * Specify the transposition used for the matrix A in the
136  * computation. It has to be either PastixTrans or PastixTrans.
137  *
138  * @param[in] cblk
139  * The cblk structure that corresponds to the A and B matrix.
140  *
141  * @param[in] blok
142  * The blok structure that corresponds to the A matrix, and that
143  * belongs either to cblk or fcbk depending on the side parameter.
144  *
145  * @param[inout] fcbk
146  * The cblk structure that corresponds to the C matrix.
147  *
148  * @param[in] sopalin_data
149  * The data that provide the SolverMatrix structure from PaStiX, and
150  * descriptor of b (providing nrhs, b and ldb).
151 
152  * @param[in] prio
153  * The priority of the task in th DAG.
154  *
155  *******************************************************************************/
156 void
157 starpu_stask_blok_sgemm( sopalin_data_t *sopalin_data,
158  pastix_rhs_t rhsb,
159  pastix_coefside_t coef,
160  pastix_side_t side,
161  pastix_trans_t trans,
162  const SolverCblk *cblk,
163  const SolverBlok *blok,
164  SolverCblk *fcbk,
165  pastix_int_t prio )
166 {
167  struct cl_solve_blok_sgemm_args_s *cl_arg;
168  SolverMatrix *solvmtx = sopalin_data->solvmtx;
169  pastix_int_t cblknum = cblk - solvmtx->cblktab;
170  pastix_int_t fcbknum = fcbk - solvmtx->cblktab;
171  starpu_data_handle_t handle;
172 #if defined(PASTIX_DEBUG_STARPU)
173  char *task_name;
174 #endif
175 
176  /*
177  * Check if it needs to be submitted
178  */
179 #if defined(PASTIX_WITH_MPI)
180  {
181  int need_submit = 0;
182  if ( (cblk->cblktype & CBLK_FANIN) ||
183  (cblk->ownerid == sopalin_data->solvmtx->clustnum) )
184  {
185  need_submit = 1;
186  }
187  if ( (fcbk->cblktype & CBLK_FANIN) ||
188  (fcbk->ownerid == sopalin_data->solvmtx->clustnum) )
189  {
190  need_submit = 1;
191  }
192  if ( starpu_mpi_cached_receive( rhsb->starpu_desc->handletab[fcbknum] ) ) {
193  need_submit = 1;
194  }
195  if ( !need_submit ) {
196  return;
197  }
198  }
199 #endif
200 
201 #if defined(PASTIX_DEBUG_STARPU)
202  fprintf( stderr, "[%2d][%s] cblk = %d, fcblk = %d, ownerid = %d, handler = %p, size = %ld\n",
203  solvmtx->clustnum, __func__, cblk->gcblknum, fcbk->gcblknum, cblk->ownerid, solvmtx->starpu_desc_rhs->handletab[cblknum],
204  cblk_colnbr( cblk ) * sizeof(float) );
205 #endif
206 
207  /*
208  * Create the arguments array
209  */
210  cl_arg = malloc( sizeof(struct cl_solve_blok_sgemm_args_s) );
211 #if defined(PASTIX_STARPU_PROFILING)
212  cl_arg->profile_data.measures = solve_blok_sgemm_profile.measures;
213  cl_arg->profile_data.flops = NAN;
214 #endif
215  cl_arg->side = side;
216  cl_arg->trans = trans;
217  cl_arg->cblk = cblk;
218  cl_arg->blok = blok;
219  cl_arg->fcbk = fcbk;
220 
221 #if defined(PASTIX_DEBUG_STARPU)
222  asprintf( &task_name, "%s( %ld, %ld, %ld )",
223  cl_solve_blok_sgemm_cpu.name,
224  (long)( ( side == PastixRight ) ? fcbknum : cblknum ),
225  (long)cblknum,
226  (long)fcbknum );
227 #endif
228 
229  if ( side == PastixRight ) {
230  handle = fcbk->handler[coef];
231  }
232  else {
233  handle = cblk->handler[coef];
234  }
235 
236  pastix_starpu_insert_task(
237  &cl_solve_blok_sgemm_cpu,
238  STARPU_CL_ARGS, cl_arg, sizeof( struct cl_solve_blok_sgemm_args_s ),
239 #if defined(PASTIX_STARPU_PROFILING)
240  STARPU_CALLBACK_WITH_ARG_NFREE, cl_profiling_callback, cl_arg,
241 #endif
242  STARPU_R, handle,
243  STARPU_R, rhsb->starpu_desc->handletab[cblknum],
244  STARPU_RW, rhsb->starpu_desc->handletab[fcbknum],
245 #if defined(PASTIX_DEBUG_STARPU)
246  STARPU_NAME, task_name,
247 #endif
248 #if defined(PASTIX_STARPU_HETEROPRIO)
249  STARPU_PRIORITY, BucketSolveGEMM,
250 #endif
251  0);
252  (void)prio;
253 }
254 
255 /**
256  * @}
257  */
BEGIN_C_DECLS typedef int pastix_int_t
Definition: datatypes.h:51
The block low-rank structure to hold a matrix in low-rank form.
void solve_blok_sgemm(pastix_side_t side, pastix_trans_t trans, pastix_int_t nrhs, const SolverCblk *cblk, const SolverBlok *blok, SolverCblk *fcbk, const void *dataA, const float *B, pastix_int_t ldb, float *C, pastix_int_t ldc)
Apply a solve gemm update related to a single block of the matrix A.
enum pastix_side_e pastix_side_t
Side of the operation.
enum pastix_trans_e pastix_trans_t
Transpostion.
enum pastix_coefside_e pastix_coefside_t
Data blocks used in the kernel.
@ PastixRight
Definition: api.h:496
@ PastixLeft
Definition: api.h:495
void starpu_stask_blok_sgemm(sopalin_data_t *sopalin_data, pastix_rhs_t rhsb, pastix_coefside_t coef, pastix_side_t side, pastix_trans_t trans, const SolverCblk *cblk, const SolverBlok *blok, SolverCblk *fcbk, pastix_int_t prio)
Submit a task to perform a gemm.
Base structure to all codelet arguments that include the profiling data.
Main PaStiX RHS structure.
Definition: pastixdata.h:155
static pastix_int_t cblk_colnbr(const SolverCblk *cblk)
Compute the number of columns in a column block.
Definition: solver.h:329
pastix_int_t gcblknum
Definition: solver.h:174
SolverCblk *restrict cblktab
Definition: solver.h:228
void * handler[2]
Definition: solver.h:179
int8_t cblktype
Definition: solver.h:164
int ownerid
Definition: solver.h:181
Solver block structure.
Definition: solver.h:141
Solver column block structure.
Definition: solver.h:161
Solver column block structure.
Definition: solver.h:203