MAGMA
1.2.0
MatrixAlgebraonGPUandMulticoreArchitectures
Main Page
Modules
Namespaces
Classes
Files
File List
File Members
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
/***************************************************************************/
28
magma_context_t
*
magma_context_create
()
29
{
30
magma_context_t
*
magma
;
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
43
magma->
scheduler
=
MAGMA_SCHED_QUARK
;
44
magma->
nworkers
= 1;
45
magma->
ncudas
= 0;
46
magma->
nthreads_per_worker
= 1;
47
48
magma->
errors_enabled
=
MAGMA_FALSE
;
49
magma->
warnings_enabled
=
MAGMA_FALSE
;
50
magma->
autotuning_enabled
=
MAGMA_TRUE
;
51
magma->
parallel_enabled
=
MAGMA_FALSE
;
52
magma->
profiling_enabled
=
MAGMA_FALSE
;
53
54
magma->
householder
=
MAGMA_FLAT_HOUSEHOLDER
;
55
magma->
translation
=
MAGMA_OUTOFPLACE
;
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
/***************************************************************************/
74
magma_context_t
*
magma_context_self
()
75
{
76
return
magma_ctxt
;
77
}
78
79
/***************************************************************************/
83
int
magma_context_destroy
(){
84
85
morse_context_destroy
(magma_ctxt);
86
free(magma_ctxt);
87
magma_ctxt = NULL;
88
89
return
MAGMA_SUCCESS
;
90
}
91
92
/***************************************************************************/
113
int
MAGMA_Enable
(
MAGMA_enum
option)
114
{
115
magma_context_t
*
magma
;
116
117
magma =
magma_context_self
();
118
if
(magma == NULL) {
119
magma_error
(
"MAGMA_Enable"
,
"MAGMA not initialized"
);
120
return
MAGMA_ERR_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
:
132
magma->
autotuning_enabled
=
MAGMA_TRUE
;
133
break
;
134
case
MAGMA_PROFILING_MODE
:
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"
);
142
return
MAGMA_ERR_ILLEGAL_VALUE
;
143
}
144
145
/* Enable at the lower level if required */
146
morse_enable
( magma, option );
147
148
return
MAGMA_SUCCESS
;
149
}
150
151
/***************************************************************************/
172
int
MAGMA_Disable
(
MAGMA_enum
option)
173
{
174
magma_context_t
*
magma
;
175
176
magma =
magma_context_self
();
177
if
(magma == NULL) {
178
magma_error
(
"MAGMA_Disable"
,
"MAGMA not initialized"
);
179
return
MAGMA_ERR_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
:
190
magma->
autotuning_enabled
=
MAGMA_FALSE
;
191
break
;
192
case
MAGMA_PROFILING_MODE
:
193
magma->
profiling_enabled
=
MAGMA_FALSE
;
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"
);
200
return
MAGMA_ERR_ILLEGAL_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
{
233
magma_context_t
*
magma
;
234
235
magma =
magma_context_self
();
236
if
(magma == NULL) {
237
magma_error
(
"MAGMA_Set"
,
"MAGMA not initialized"
);
238
return
MAGMA_ERR_NOT_INITIALIZED
;
239
}
240
switch
(param) {
241
case
MAGMA_TILE_SIZE
:
242
if
(value <= 0) {
243
magma_error
(
"MAGMA_Set"
,
"negative tile size"
);
244
return
MAGMA_ERR_ILLEGAL_VALUE
;
245
}
246
magma->
nb
= value;
247
if
( magma->
autotuning_enabled
) {
248
magma->
autotuning_enabled
=
MAGMA_FALSE
;
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
;
254
case
MAGMA_INNER_BLOCK_SIZE
:
255
if
(value <= 0) {
256
magma_error
(
"MAGMA_Set"
,
"negative inner block size"
);
257
return
MAGMA_ERR_ILLEGAL_VALUE
;
258
}
259
if
(value > magma->
nb
) {
260
magma_error
(
"MAGMA_Set"
,
"inner block larger than tile"
);
261
return
MAGMA_ERR_ILLEGAL_VALUE
;
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
) {
270
magma->
autotuning_enabled
=
MAGMA_FALSE
;
271
magma_warning
(
"MAGMA_Set"
,
"autotuning has been automatically disable\n"
);
272
}
273
break
;
274
case
MAGMA_HOUSEHOLDER_MODE
:
275
if
(value !=
MAGMA_FLAT_HOUSEHOLDER
&& value !=
MAGMA_TREE_HOUSEHOLDER
) {
276
magma_error
(
"MAGMA_Set"
,
"illegal value of MAGMA_HOUSEHOLDER_MODE"
);
277
return
MAGMA_ERR_ILLEGAL_VALUE
;
278
}
279
magma->
householder
= value;
280
break
;
281
case
MAGMA_HOUSEHOLDER_SIZE
:
282
if
(value <= 0) {
283
magma_error
(
"MAGMA_Set"
,
"negative householder size"
);
284
return
MAGMA_ERR_ILLEGAL_VALUE
;
285
}
286
magma->
rhblock
= value;
287
break
;
288
case
MAGMA_TRANSLATION_MODE
:
289
if
(value !=
MAGMA_INPLACE
&& value !=
MAGMA_OUTOFPLACE
) {
290
magma_error
(
"MAGMA_Set"
,
"illegal value of MAGMA_TRANSLATION_MODE"
);
291
return
MAGMA_ERR_ILLEGAL_VALUE
;
292
}
293
magma->
translation
= value;
294
break
;
295
default
:
296
magma_error
(
"MAGMA_Set"
,
"unknown parameter"
);
297
return
MAGMA_ERR_ILLEGAL_VALUE
;
298
}
299
300
return
MAGMA_SUCCESS
;
301
}
302
303
/***************************************************************************/
325
int
MAGMA_Get
(
MAGMA_enum
param,
int
*value)
326
{
327
magma_context_t
*
magma
;
328
329
magma =
magma_context_self
();
330
if
(magma == NULL) {
331
magma_error
(
"MAGMA_Get"
,
"MAGMA not initialized"
);
332
return
MAGMA_ERR_NOT_INITIALIZED
;
333
}
334
switch
(param) {
335
case
MAGMA_TILE_SIZE
:
336
*value = magma->
nb
;
337
return
MAGMA_SUCCESS
;
338
case
MAGMA_INNER_BLOCK_SIZE
:
339
*value = magma->
ib
;
340
return
MAGMA_SUCCESS
;
341
case
MAGMA_HOUSEHOLDER_MODE
:
342
*value = magma->
householder
;
343
return
MAGMA_SUCCESS
;
344
case
MAGMA_HOUSEHOLDER_SIZE
:
345
*value = magma->
rhblock
;
346
return
MAGMA_SUCCESS
;
347
case
MAGMA_TRANSLATION_MODE
:
348
*value = magma->
translation
;
349
return
MAGMA_SUCCESS
;
350
default
:
351
magma_error
(
"MAGMA_Get"
,
"unknown parameter"
);
352
return
MAGMA_ERR_ILLEGAL_VALUE
;
353
}
354
355
return
MAGMA_SUCCESS
;
356
}
magma-1.2.0
multi-gpu-dynamic
common
context.c
Generated on Mon May 21 2012 16:42:21 for MAGMA by
1.8.1