MAGMA  1.2.0
MatrixAlgebraonGPUandMulticoreArchitectures
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
context.c
Go to the documentation of this file.
1 
15 #include <stdlib.h>
16 #include "common.h"
17 #include "context.h"
18 
19 /***************************************************************************/
22 /* master threads context lookup table */
23 static magma_context_t *magma_ctxt = NULL;
24 
25 /***************************************************************************/
29 {
31 
32  if ( magma_ctxt != NULL ) {
33  magma_error("magma_context_create", "a context is already existing\n");
34  return NULL;
35  }
36 
37  magma = (magma_context_t*)malloc(sizeof(magma_context_t));
38  if (magma == NULL) {
39  magma_error("magma_context_create", "malloc() failed");
40  return NULL;
41  }
42 
44  magma->nworkers = 1;
45  magma->ncudas = 0;
46  magma->nthreads_per_worker= 1;
47 
48  magma->errors_enabled = MAGMA_FALSE;
53 
56 
57  /* These initializations are just in case the user
58  disables autotuning and does not set nb and ib */
59  magma->nb = 128;
60  magma->ib = 32;
61  magma->rhblock = 4;
62 
63  /* Initialize scheduler */
64  morse_context_create(magma);
65 
66  magma_ctxt = magma;
67  return magma;
68 }
69 
70 
71 /***************************************************************************/
75 {
76  return magma_ctxt;
77 }
78 
79 /***************************************************************************/
84 
85  morse_context_destroy(magma_ctxt);
86  free(magma_ctxt);
87  magma_ctxt = NULL;
88 
89  return MAGMA_SUCCESS;
90 }
91 
92 /***************************************************************************/
114 {
116 
117  magma = magma_context_self();
118  if (magma == NULL) {
119  magma_error("MAGMA_Enable", "MAGMA not initialized");
121  }
122 
123  switch (option)
124  {
125  case MAGMA_WARNINGS:
126  magma->warnings_enabled = MAGMA_TRUE;
127  break;
128  case MAGMA_ERRORS:
129  magma->errors_enabled = MAGMA_TRUE;
130  break;
131  case MAGMA_AUTOTUNING:
133  break;
135  magma->profiling_enabled = MAGMA_TRUE;
136  break;
137  /* case MAGMA_PARALLEL: */
138  /* magma->parallel_enabled = MAGMA_TRUE; */
139  /* break; */
140  default:
141  magma_error("MAGMA_Enable", "illegal parameter value");
143  }
144 
145  /* Enable at the lower level if required */
146  morse_enable( magma, option );
147 
148  return MAGMA_SUCCESS;
149 }
150 
151 /***************************************************************************/
173 {
175 
176  magma = magma_context_self();
177  if (magma == NULL) {
178  magma_error("MAGMA_Disable", "MAGMA not initialized");
180  }
181  switch ( option )
182  {
183  case MAGMA_WARNINGS:
184  magma->warnings_enabled = MAGMA_FALSE;
185  break;
186  case MAGMA_ERRORS:
187  magma->errors_enabled = MAGMA_FALSE;
188  break;
189  case MAGMA_AUTOTUNING:
191  break;
194  break;
195  case MAGMA_PARALLEL_MODE:
196  magma->parallel_enabled = MAGMA_FALSE;
197  break;
198  default:
199  magma_error("MAGMA_Disable", "illegal parameter value");
201  }
202 
203  /* Disable at the lower level if required */
204  morse_disable( magma, option );
205 
206  return MAGMA_SUCCESS;
207 }
208 
209 /***************************************************************************/
231 int MAGMA_Set(MAGMA_enum param, int value)
232 {
234 
235  magma = magma_context_self();
236  if (magma == NULL) {
237  magma_error("MAGMA_Set", "MAGMA not initialized");
239  }
240  switch (param) {
241  case MAGMA_TILE_SIZE:
242  if (value <= 0) {
243  magma_error("MAGMA_Set", "negative tile size");
245  }
246  magma->nb = value;
247  if ( magma->autotuning_enabled ) {
249  magma_warning("MAGMA_Set", "autotuning has been automatically disable\n");
250  }
251  /* Limit ib to nb */
252  magma->ib = min( magma->nb, magma->ib );
253  break;
255  if (value <= 0) {
256  magma_error("MAGMA_Set", "negative inner block size");
258  }
259  if (value > magma->nb) {
260  magma_error("MAGMA_Set", "inner block larger than tile");
262  }
263  /* if (magma->nb % value != 0) { */
264  /* magma_error("MAGMA_Set", "inner block does not divide tile"); */
265  /* return MAGMA_ERR_ILLEGAL_VALUE; */
266  /* } */
267  magma->ib = value;
268 
269  if ( magma->autotuning_enabled ) {
271  magma_warning("MAGMA_Set", "autotuning has been automatically disable\n");
272  }
273  break;
275  if (value != MAGMA_FLAT_HOUSEHOLDER && value != MAGMA_TREE_HOUSEHOLDER) {
276  magma_error("MAGMA_Set", "illegal value of MAGMA_HOUSEHOLDER_MODE");
278  }
279  magma->householder = value;
280  break;
282  if (value <= 0) {
283  magma_error("MAGMA_Set", "negative householder size");
285  }
286  magma->rhblock = value;
287  break;
289  if (value != MAGMA_INPLACE && value != MAGMA_OUTOFPLACE) {
290  magma_error("MAGMA_Set", "illegal value of MAGMA_TRANSLATION_MODE");
292  }
293  magma->translation = value;
294  break;
295  default:
296  magma_error("MAGMA_Set", "unknown parameter");
298  }
299 
300  return MAGMA_SUCCESS;
301 }
302 
303 /***************************************************************************/
325 int MAGMA_Get(MAGMA_enum param, int *value)
326 {
328 
329  magma = magma_context_self();
330  if (magma == NULL) {
331  magma_error("MAGMA_Get", "MAGMA not initialized");
333  }
334  switch (param) {
335  case MAGMA_TILE_SIZE:
336  *value = magma->nb;
337  return MAGMA_SUCCESS;
339  *value = magma->ib;
340  return MAGMA_SUCCESS;
342  *value = magma->householder;
343  return MAGMA_SUCCESS;
345  *value = magma->rhblock;
346  return MAGMA_SUCCESS;
348  *value = magma->translation;
349  return MAGMA_SUCCESS;
350  default:
351  magma_error("MAGMA_Get", "unknown parameter");
353  }
354 
355  return MAGMA_SUCCESS;
356 }