MAGMA  1.2.0
MatrixAlgebraonGPUandMulticoreArchitectures
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
descriptor.c
Go to the documentation of this file.
1 
14 #include <stdlib.h>
15 #include "common.h"
16 
17 /***************************************************************************/
20 magma_desc_t magma_desc_init(MAGMA_enum dtyp, int mb, int nb, int bsiz,
21  int lm, int ln, int i, int j, int m, int n)
22 {
23  magma_desc_t desc;
24  PLASMA_desc *pdesc = &(desc.desc);
25 
26  // Matrix address
27  pdesc->mat = NULL;
28  pdesc->A21 = (lm - lm%mb)*(ln - ln%nb);
29  pdesc->A12 = ( lm%mb)*(ln - ln%nb) + pdesc->A21;
30  pdesc->A22 = (lm - lm%mb)*( ln%nb) + pdesc->A12;
31  // Matrix properties
32  pdesc->dtyp = dtyp;
33  pdesc->mb = mb;
34  pdesc->nb = nb;
35  pdesc->bsiz = bsiz;
36  // Large matrix parameters
37  pdesc->lm = lm;
38  pdesc->ln = ln;
39  // Large matrix derived parameters
40  pdesc->lm1 = (lm/mb);
41  pdesc->ln1 = (ln/nb);
42  pdesc->lmt = (lm%mb==0) ? (lm/mb) : (lm/mb+1);
43  pdesc->lnt = (ln%nb==0) ? (ln/nb) : (ln/nb+1);
44  // Submatrix parameters
45  pdesc->i = i;
46  pdesc->j = j;
47  pdesc->m = m;
48  pdesc->n = n;
49  // Submatrix derived parameters
50  pdesc->mt = (i+m-1)/mb - i/mb + 1;
51  pdesc->nt = (j+n-1)/nb - j/nb + 1;
52 
53  desc.occurences = 0;
54  morse_desc_init( &desc );
55 
56  return desc;
57 }
58 
59 /***************************************************************************/
62 magma_desc_t magma_desc_submatrix(magma_desc_t descA, int i, int j, int m, int n)
63 {
64  magma_desc_t descB;
65  PLASMA_desc *pdescB = &(descB.desc);
66  int mb, nb;
67 
68  descB = descA;
69  mb = descA.desc.mb;
70  nb = descA.desc.nb;
71  // Submatrix parameters
72  pdescB->i = i;
73  pdescB->j = j;
74  pdescB->m = m;
75  pdescB->n = n;
76  // Submatrix derived parameters
77  pdescB->mt = (i+m-1)/mb - i/mb + 1;
78  pdescB->nt = (j+n-1)/nb - j/nb + 1;
79 
80  morse_desc_submatrix( &descB );
81 
82  return descB;
83 }
84 
85 /***************************************************************************/
89 {
90  if (desc->desc.mat == NULL) {
91  magma_error("magma_desc_check", "NULL matrix pointer");
92  return MAGMA_ERR_UNALLOCATED;
93  }
94  if (desc->desc.dtyp != PlasmaRealFloat &&
95  desc->desc.dtyp != PlasmaRealDouble &&
96  desc->desc.dtyp != PlasmaComplexFloat &&
97  desc->desc.dtyp != PlasmaComplexDouble ) {
98  magma_error("magma_desc_check", "invalid matrix type");
100  }
101  if (desc->desc.mb <= 0 || desc->desc.nb <= 0) {
102  magma_error("magma_desc_check", "negative tile dimension");
104  }
105  if (desc->desc.bsiz < desc->desc.mb*desc->desc.nb) {
106  magma_error("magma_desc_check", "tile memory size smaller than the product of dimensions");
108  }
109  if (desc->desc.lm <= 0 || desc->desc.ln <= 0) {
110  magma_error("magma_desc_check", "negative matrix dimension");
112  }
113  if (desc->desc.i >= desc->desc.lm || desc->desc.j >= desc->desc.ln) {
114  magma_error("magma_desc_check", "beginning of the matrix out of scope");
116  }
117  if (desc->desc.i+desc->desc.m > desc->desc.lm || desc->desc.j+desc->desc.n > desc->desc.ln) {
118  magma_error("magma_desc_check", "submatrix out of scope");
120  }
121  return MAGMA_SUCCESS;
122 }
123 
124 /***************************************************************************/
128 {
129  size_t size;
130 
131  size = (size_t)desc->desc.lm * (size_t)desc->desc.ln * (size_t)plasma_element_size(desc->desc.dtyp);
132  if ((desc->desc.mat = malloc(size)) == NULL) {
133  magma_error("magma_desc_mat_alloc", "malloc() failed");
135  }
136 
137  morse_desc_create( desc );
138 
139  return MAGMA_SUCCESS;
140 }
141 
142 /***************************************************************************/
146 {
147 
148  morse_desc_destroy( desc );
149 
150  if (desc->desc.mat != NULL) {
151  free(desc->desc.mat);
152  desc->desc.mat = NULL;
153  }
154  return MAGMA_SUCCESS;
155 }
156 
157 /***************************************************************************/
211 int MAGMA_Desc_Create(magma_desc_t **desc, void *mat, MAGMA_enum dtyp, int mb, int nb, int bsiz,
212  int lm, int ln, int i, int j, int m, int n)
213 {
215  int status;
216 
217  magma = magma_context_self();
218  if (magma == NULL) {
219  magma_error("MAGMA_Desc_Create", "MAGMA not initialized");
221  }
222  /* Allocate memory and initialize the descriptor */
223  *desc = (magma_desc_t*)malloc(sizeof(magma_desc_t));
224  if (*desc == NULL) {
225  magma_error("MAGMA_Desc_Create", "malloc() failed");
227  }
228  **desc = magma_desc_init(dtyp, mb, nb, bsiz, lm, ln, i, j, m, n);
229  (**desc).desc.mat = mat;
230 
231  /* Create scheduler structure like registering data */
232  morse_desc_create( *desc );
233 
234  status = magma_desc_check(*desc);
235  if (status != MAGMA_SUCCESS) {
236  magma_error("MAGMA_Desc_Create", "invalid descriptor");
237  return status;
238  }
239 
240  return MAGMA_SUCCESS;
241 }
242 
243 /***************************************************************************/
261 {
263 
264  magma = magma_context_self();
265  if (magma == NULL) {
266  magma_error("MAGMA_Desc_Destroy", "MAGMA not initialized");
268  }
269  if (*desc == NULL) {
270  magma_error("MAGMA_Desc_Destroy", "attempting to destroy a NULL descriptor");
271  return MAGMA_ERR_UNALLOCATED;
272  }
273 
274  /* Clean at scheduler level like unregistering data */
275  morse_desc_destroy( *desc );
276 
277  free(*desc);
278  *desc = NULL;
279  return MAGMA_SUCCESS;
280 }
281 
282 
283