PLASMA
Parallel Linear Algebra Software for Multicore Architectures
plasma_descriptor.h
1 
10 #ifndef ICL_PLASMA_DESCRIPTOR_H
11 #define ICL_PLASMA_DESCRIPTOR_H
12 
13 #include "plasma_types.h"
14 #include "plasma_error.h"
15 
16 #include <stdlib.h>
17 #include <assert.h>
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
23 /***************************************************************************/
40 typedef struct {
41  // matrix properties
42  plasma_enum_t type;
43  plasma_enum_t uplo;
44  plasma_enum_t precision;
45 
46  // pointer and offsets
47  void *matrix;
48  size_t A21;
49  size_t A12;
50  size_t A22;
51 
52  // tile parameters
53  int mb;
54  int nb;
55 
56  // main matrix parameters
57  int gm;
58  int gn;
59  int gmt;
60  int gnt;
61 
62  // submatrix parameters
63  int i;
64  int j;
65  int m;
66  int n;
67  int mt;
68  int nt;
69 
70  // submatrix parameters for a band matrix
71  int kl;
72  int ku;
73  int klt;
74  int kut;
77 
78 /******************************************************************************/
79 static inline size_t plasma_element_size(int type)
80 {
81  switch (type) {
82  case PlasmaByte: return 1;
83  case PlasmaInteger: return sizeof(int);
84  case PlasmaRealFloat: return sizeof(float);
85  case PlasmaRealDouble: return sizeof(double);
86  case PlasmaComplexFloat: return 2*sizeof(float);
87  case PlasmaComplexDouble: return 2*sizeof(double);
88  default: assert(0);
89  }
90 }
91 
92 /******************************************************************************/
93 static inline void *plasma_tile_addr_general(plasma_desc_t A, int m, int n)
94 {
95  int mm = m + A.i/A.mb;
96  int nn = n + A.j/A.nb;
97  size_t eltsize = plasma_element_size(A.precision);
98  size_t offset = 0;
99 
100  int lm1 = A.gm/A.mb;
101  int ln1 = A.gn/A.nb;
102 
103  if (mm < lm1)
104  if (nn < ln1)
105  offset = A.mb*A.nb*(mm + (size_t)lm1 * nn);
106  else
107  offset = A.A12 + ((size_t)A.mb * (A.gn%A.nb) * mm);
108  else
109  if (nn < ln1)
110  offset = A.A21 + ((size_t)A.nb * (A.gm%A.mb) * nn);
111  else
112  offset = A.A22;
113 
114  return (void*)((char*)A.matrix + (offset*eltsize));
115 }
116 
117 /******************************************************************************/
118 static inline void *plasma_tile_addr_triangle(plasma_desc_t A, int m, int n)
119 {
120  int mm = m + A.i/A.mb;
121  int nn = n + A.j/A.nb;
122  size_t eltsize = plasma_element_size(A.precision);
123  size_t offset = 0;
124 
125  int lm1 = A.gm/A.mb;
126  int ln1 = A.gn/A.nb;
127 
128  if (mm < lm1) {
129  if (nn < ln1) {
130  if (A.type == PlasmaUpper) {
131  offset = A.mb*A.nb*(mm + (nn * (nn + 1))/2);
132  }
133  else {
134  offset = A.mb*A.nb*((mm - nn) + (nn * (2*lm1 - (nn-1)))/2);
135  }
136  }
137  else {
138  offset = A.A12 + ((size_t)A.mb * (A.gn%A.nb) * mm);
139  }
140  }
141  else {
142  if (nn < ln1) {
143  offset = A.A21 + ((size_t)A.nb * (A.gm%A.mb) * nn);
144  }
145  else {
146  offset = A.A22;
147  }
148  }
149 
150  return (void*)((char*)A.matrix + (offset*eltsize));
151 }
152 
153 /******************************************************************************/
154 static inline void *plasma_tile_addr_general_band(plasma_desc_t A, int m, int n)
155 {
156  return plasma_tile_addr_general(A, (A.kut-1)+m-n, n);
157 }
158 
159 /******************************************************************************/
160 static inline void *plasma_tile_addr(plasma_desc_t A, int m, int n)
161 {
162  if (A.type == PlasmaGeneral) {
163  return plasma_tile_addr_general(A, m, n);
164  }
165  else if (A.type == PlasmaGeneralBand) {
166  return plasma_tile_addr_general_band(A, m, n);
167  }
168  else if (A.type == PlasmaUpper || A.type == PlasmaLower) {
169  return plasma_tile_addr_triangle(A, m, n);
170  }
171  else {
172  plasma_fatal_error("invalid matrix type");
173  return NULL;
174  }
175 }
176 
177 /***************************************************************************/
182 static inline int plasma_tile_mmain(plasma_desc_t A, int k)
183 {
184  if (A.i/A.mb+k < A.gm/A.mb)
185  return A.mb;
186  else
187  return A.gm%A.mb;
188 }
189 
190 /***************************************************************************/
195 static inline int plasma_tile_nmain(plasma_desc_t A, int k)
196 {
197  if (A.j/A.nb+k < A.gn/A.nb)
198  return A.nb;
199  else
200  return A.gn%A.nb;
201 }
202 
203 /***************************************************************************/
209 static inline int plasma_tile_mview(plasma_desc_t A, int k)
210 {
211  if (k < A.mt-1)
212  return A.mb;
213  else
214  if ((A.i+A.m)%A.mb == 0)
215  return A.mb;
216  else
217  return (A.i+A.m)%A.mb;
218 }
219 
220 /***************************************************************************/
226 static inline int plasma_tile_nview(plasma_desc_t A, int k)
227 {
228  if (k < A.nt-1)
229  return A.nb;
230  else
231  if ((A.j+A.n)%A.nb == 0)
232  return A.nb;
233  else
234  return (A.j+A.n)%A.nb;
235 }
236 
237 /******************************************************************************/
238 static inline int plasma_tile_mmain_band(plasma_desc_t A, int m, int n)
239 {
240  return plasma_tile_mmain(A, (A.kut-1)+m-n);
241 }
242 
243 /******************************************************************************/
244 int plasma_desc_general_create(plasma_enum_t dtyp, int mb, int nb,
245  int lm, int ln, int i, int j, int m, int n,
246  plasma_desc_t *A);
247 
248 int plasma_desc_general_band_create(plasma_enum_t dtyp, plasma_enum_t uplo,
249  int mb, int nb, int lm, int ln,
250  int i, int j, int m, int n, int kl, int ku,
251  plasma_desc_t *A);
252 
253 int plasma_desc_triangular_create(plasma_enum_t dtyp, plasma_enum_t uplo, int mb, int nb,
254  int lm, int ln, int i, int j, int m, int n,
255  plasma_desc_t *A);
256 
257 int plasma_desc_destroy(plasma_desc_t *A);
258 
259 int plasma_desc_general_init(plasma_enum_t precision, void *matrix,
260  int mb, int nb, int lm, int ln, int i, int j,
261  int m, int n, plasma_desc_t *A);
262 
263 int plasma_desc_general_band_init(plasma_enum_t precision, plasma_enum_t uplo,
264  void *matrix, int mb, int nb, int lm, int ln,
265  int i, int j, int m, int n, int kl, int ku,
266  plasma_desc_t *A);
267 
268 int plasma_desc_triangular_init(plasma_enum_t precision, plasma_enum_t uplo, void *matrix,
269  int mb, int nb, int lm, int ln, int i, int j,
270  int m, int n, plasma_desc_t *A);
271 
272 int plasma_desc_check(plasma_desc_t A);
273 int plasma_desc_general_check(plasma_desc_t A);
274 int plasma_desc_general_band_check(plasma_desc_t A);
275 
276 plasma_desc_t plasma_desc_view(plasma_desc_t A, int i, int j, int m, int n);
277 
278 int plasma_descT_create(plasma_desc_t A, int ib, plasma_enum_t householder_mode,
279  plasma_desc_t *T);
280 
281 #ifdef __cplusplus
282 } // extern "C"
283 #endif
284 
285 #endif // ICL_PLASMA_DESCRIPTOR_H
int n
number of columns of the submatrix
Definition: plasma_descriptor.h:66
int mb
number of rows in a tile
Definition: plasma_descriptor.h:53
int j
column index to the beginning of the submatrix
Definition: plasma_descriptor.h:64
void * matrix
pointer to the beginning of the matrix
Definition: plasma_descriptor.h:47
int gn
number of columns of the entire matrix
Definition: plasma_descriptor.h:58
plasma_enum_t precision
precision of the matrix
Definition: plasma_descriptor.h:44
int nb
number of columns in a tile
Definition: plasma_descriptor.h:54
int i
row index to the beginning of the submatrix
Definition: plasma_descriptor.h:63
size_t A22
pointer to the beginning of A22
Definition: plasma_descriptor.h:50
size_t A12
pointer to the beginning of A12
Definition: plasma_descriptor.h:49
int gnt
number of tile columns of the entire matrix
Definition: plasma_descriptor.h:60
int m
number of rows of the submatrix
Definition: plasma_descriptor.h:65
int kl
number of rows below the diagonal
Definition: plasma_descriptor.h:71
int kut
Definition: plasma_descriptor.h:74
int gmt
number of tile rows of the entire matrix
Definition: plasma_descriptor.h:59
plasma_enum_t uplo
upper, lower, etc.
Definition: plasma_descriptor.h:43
int ku
number of rows above the diagonal
Definition: plasma_descriptor.h:72
int gm
number of rows of the entire matrix
Definition: plasma_descriptor.h:57
int mt
number of tile rows of the submatrix
Definition: plasma_descriptor.h:67
int klt
number of tile rows below the diagonal tile
Definition: plasma_descriptor.h:73
Definition: plasma_descriptor.h:40
size_t A21
pointer to the beginning of A21
Definition: plasma_descriptor.h:48
int nt
number of tile columns of the submatrix
Definition: plasma_descriptor.h:68
plasma_enum_t type
general, general band, etc.
Definition: plasma_descriptor.h:42