PLASMA
2.4.5
PLASMA - Parallel Linear Algebra for Scalable Multi-core Architectures
Main Page
Modules
Namespaces
Data Structures
Files
File List
Globals
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Groups
context.c
Go to the documentation of this file.
1
14
#include <stdlib.h>
15
#if defined( _WIN32 ) || defined( _WIN64 )
16
#include "
plasmawinthread.h
"
17
#else
18
#include <pthread.h>
19
#endif
20
21
#include "
common.h
"
22
#include "
auxiliary.h
"
23
#include "
context.h
"
24
25
/***************************************************************************/
28
/* master threads context lookup table */
29
plasma_context_map_t
context_map
[
CONTEXTS_MAX
];
30
/* context lookup table access lock */
31
pthread_mutex_t
context_map_lock
=
PTHREAD_MUTEX_INITIALIZER
;
32
33
/***************************************************************************/
36
plasma_context_t
*
plasma_context_create
()
37
{
38
plasma_context_t
*
plasma
;
39
40
plasma = (
plasma_context_t
*)malloc(
sizeof
(
plasma_context_t
));
41
if
(plasma == NULL) {
42
plasma_fatal_error
(
"plasma_context_create"
,
"malloc() failed"
);
43
return
NULL;
44
}
45
46
pthread_mutex_init
(&plasma->
action_mutex
, NULL);
47
pthread_mutex_init
(&
context_map_lock
, NULL);
48
pthread_cond_init
(&plasma->
action_condt
, NULL);
49
plasma->
action
=
PLASMA_ACT_STAND_BY
;
50
plasma->
parallel_func_ptr
= NULL;
51
52
/* These initializations are just in case the user
53
disables autotuning and does not set nb and ib */
54
plasma->
nb
= 128;
55
plasma->
ib
= 32;
56
plasma->
nbnbsize
= 16384;
57
plasma->
ibnbsize
= 4096;
58
plasma->
rhblock
= 4;
59
60
plasma->
errors_enabled
=
PLASMA_TRUE
;
61
plasma->
warnings_enabled
=
PLASMA_TRUE
;
62
plasma->
autotuning_enabled
=
PLASMA_TRUE
;
63
plasma->
dynamic_section
=
PLASMA_FALSE
;
64
65
plasma->
scheduling
=
PLASMA_STATIC_SCHEDULING
;
66
plasma->
householder
=
PLASMA_FLAT_HOUSEHOLDER
;
67
plasma->
translation
=
PLASMA_OUTOFPLACE
;
68
69
return
plasma;
70
}
71
72
/***************************************************************************/
75
int
plasma_context_insert
(
plasma_context_t
*context,
pthread_t
thread_id)
76
{
77
int
i;
78
79
// acquire the access lock
80
pthread_mutex_lock
(&
context_map_lock
);
81
// For each entry
82
for
(i = 0; i <
CONTEXTS_MAX
; i++) {
83
// If not occupied
84
if
(context_map[i].context == NULL) {
85
// Insert new context, release lock, return success
86
context_map[i].
context
= context;
87
context_map[i].
thread_id
= thread_id;
88
pthread_mutex_unlock
(&
context_map_lock
);
89
return
PLASMA_SUCCESS
;
90
}
91
}
92
// No empty entry found - release lock, return error
93
pthread_mutex_unlock
(&
context_map_lock
);
94
plasma_fatal_error
(
"plasma_context_insert"
,
"too many threads"
);
95
return
PLASMA_ERR_INTERNAL_LIMIT
;
96
}
97
98
/***************************************************************************/
101
int
plasma_context_remove
(
plasma_context_t
*context,
pthread_t
thread_id)
102
{
103
int
i;
104
105
// acquire the access lock
106
pthread_mutex_lock
(&
context_map_lock
);
107
// For each entry
108
for
(i = 0; i <
CONTEXTS_MAX
; i++) {
109
// If id matches
110
if
(
pthread_equal
(context_map[i].thread_id, thread_id)) {
111
if
(context_map[i].context == context) {
112
// Free the context, mark entry as empty, release lock, return success
113
free(context_map[i].context);
114
context_map[i].
context
= NULL;
115
pthread_mutex_unlock
(&
context_map_lock
);
116
return
PLASMA_SUCCESS
;
117
}
118
else
{
119
pthread_mutex_unlock
(&
context_map_lock
);
120
plasma_fatal_error
(
"plasma_context_remove"
,
"context does not match thread"
);
121
return
PLASMA_ERR_UNEXPECTED
;
122
}
123
}
124
}
125
// No matching id found - release lock, return error
126
pthread_mutex_unlock
(&
context_map_lock
);
127
plasma_fatal_error
(
"plasma_context_remove"
,
"thread not found"
);
128
return
PLASMA_ERR_NOT_FOUND
;
129
}
130
131
/***************************************************************************/
134
plasma_context_t
*
plasma_context_self
()
135
{
136
int
i;
137
138
// For each entry
139
for
(i = 0; i <
CONTEXTS_MAX
; i++) {
140
// If id matches
141
if
(
pthread_equal
(context_map[i].thread_id,
pthread_self
())) {
142
return
context_map[i].
context
;
143
}
144
}
145
return
NULL;
146
}
147
148
/***************************************************************************/
169
int
PLASMA_Enable
(
PLASMA_enum
lever)
170
{
171
plasma_context_t
*
plasma
;
172
173
plasma =
plasma_context_self
();
174
if
(plasma == NULL) {
175
plasma_fatal_error
(
"PLASMA_Enable"
,
"PLASMA not initialized"
);
176
return
PLASMA_ERR_NOT_INITIALIZED
;
177
}
178
179
switch
(lever)
180
{
181
case
PLASMA_WARNINGS
:
182
plasma->
warnings_enabled
=
PLASMA_TRUE
;
183
break
;
184
case
PLASMA_ERRORS
:
185
plasma->
errors_enabled
=
PLASMA_TRUE
;
186
break
;
187
case
PLASMA_AUTOTUNING
:
188
plasma->
autotuning_enabled
=
PLASMA_TRUE
;
189
break
;
190
case
PLASMA_DAG
:
191
QUARK_Barrier
(plasma->
quark
);
192
QUARK_DOT_DAG_Enable
( plasma->
quark
, 1);
193
break
;
194
default
:
195
plasma_error
(
"PLASMA_Enable"
,
"illegal parameter value"
);
196
return
PLASMA_ERR_ILLEGAL_VALUE
;
197
}
198
return
PLASMA_SUCCESS
;
199
}
200
201
/***************************************************************************/
222
int
PLASMA_Disable
(
PLASMA_enum
lever)
223
{
224
plasma_context_t
*
plasma
;
225
226
plasma =
plasma_context_self
();
227
if
(plasma == NULL) {
228
plasma_fatal_error
(
"PLASMA_Disable"
,
"PLASMA not initialized"
);
229
return
PLASMA_ERR_NOT_INITIALIZED
;
230
}
231
switch
(lever)
232
{
233
case
PLASMA_WARNINGS
:
234
plasma->
warnings_enabled
=
PLASMA_FALSE
;
235
break
;
236
case
PLASMA_ERRORS
:
237
plasma->
errors_enabled
=
PLASMA_FALSE
;
238
break
;
239
case
PLASMA_AUTOTUNING
:
240
plasma->
autotuning_enabled
=
PLASMA_FALSE
;
241
break
;
242
case
PLASMA_DAG
:
243
QUARK_Barrier
(plasma->
quark
);
244
QUARK_DOT_DAG_Enable
( plasma->
quark
, 0);
245
break
;
246
default
:
247
plasma_error
(
"PLASMA_Disable"
,
"illegal parameter value"
);
248
return
PLASMA_ERR_ILLEGAL_VALUE
;
249
}
250
return
PLASMA_SUCCESS
;
251
}
252
253
/***************************************************************************/
278
int
PLASMA_Set
(
PLASMA_enum
param,
int
value)
279
{
280
plasma_context_t
*
plasma
;
281
282
plasma =
plasma_context_self
();
283
if
(plasma == NULL) {
284
plasma_error
(
"PLASMA_Set"
,
"PLASMA not initialized"
);
285
return
PLASMA_ERR_NOT_INITIALIZED
;
286
}
287
switch
(param) {
288
case
PLASMA_TILE_SIZE
:
289
if
(value <= 0) {
290
plasma_error
(
"PLASMA_Set"
,
"negative tile size"
);
291
return
PLASMA_ERR_ILLEGAL_VALUE
;
292
}
293
plasma->
nb
= value;
294
/* Calculate A, B tile size and round up to cache line size */
295
/* round up for the smallest type (float) - will hold for all */
296
plasma->
nbnbsize
= plasma->
nb
* plasma->
nb
;
// * sizeof(float);
297
plasma->
ibnbsize
= plasma->
ib
* plasma->
nb
;
// * sizeof(float);
298
// plasma->nbnbsize = roundup(plasma->nbnbsize, CACHE_LINE_SIZE);
299
// plasma->nbnbsize /= sizeof(float);
300
if
( plasma->
autotuning_enabled
) {
301
plasma->
autotuning_enabled
=
PLASMA_FALSE
;
302
plasma_warning
(
"PLASMA_Set"
,
"autotuning has been automatically disabled\n"
);
303
}
304
/* Limit ib to nb */
305
plasma->
ib
=
min
( plasma->
nb
, plasma->
ib
);
306
break
;
307
case
PLASMA_INNER_BLOCK_SIZE
:
308
if
(value <= 0) {
309
plasma_error
(
"PLASMA_Set"
,
"negative inner block size"
);
310
return
PLASMA_ERR_ILLEGAL_VALUE
;
311
}
312
if
(value > plasma->
nb
) {
313
plasma_error
(
"PLASMA_Set"
,
"inner block larger than tile"
);
314
return
PLASMA_ERR_ILLEGAL_VALUE
;
315
}
316
/* if (plasma->nb % value != 0) { */
317
/* plasma_error("PLASMA_Set", "inner block does not divide tile"); */
318
/* return PLASMA_ERR_ILLEGAL_VALUE; */
319
/* } */
320
plasma->
ib
= value;
321
/* Calculate T, L tile size and round up to cache line size */
322
/* round up for the smallest type (float) - will hold for all */
323
plasma->
ibnbsize
= plasma->
ib
* plasma->
nb
;
// * sizeof(float);
324
// plasma->ibnbsize = roundup(plasma->ibnbsize, CACHE_LINE_SIZE);
325
// plasma->ibnbsize /= sizeof(float);
326
327
if
( plasma->
autotuning_enabled
) {
328
plasma->
autotuning_enabled
=
PLASMA_FALSE
;
329
plasma_warning
(
"PLASMA_Set"
,
"autotuning has been automatically disabled\n"
);
330
}
331
break
;
332
case
PLASMA_SCHEDULING_MODE
:
333
if
(value !=
PLASMA_STATIC_SCHEDULING
&& value !=
PLASMA_DYNAMIC_SCHEDULING
) {
334
plasma_error
(
"PLASMA_Set"
,
"illegal value of PLASMA_SCHEDULING_MODE"
);
335
return
PLASMA_ERR_ILLEGAL_VALUE
;
336
}
337
plasma->
scheduling
= value;
338
break
;
339
case
PLASMA_HOUSEHOLDER_MODE
:
340
if
(value !=
PLASMA_FLAT_HOUSEHOLDER
&& value !=
PLASMA_TREE_HOUSEHOLDER
) {
341
plasma_error
(
"PLASMA_Set"
,
"illegal value of PLASMA_HOUSEHOLDER_MODE"
);
342
return
PLASMA_ERR_ILLEGAL_VALUE
;
343
}
344
plasma->
householder
= value;
345
break
;
346
case
PLASMA_HOUSEHOLDER_SIZE
:
347
if
(value <= 0) {
348
plasma_error
(
"PLASMA_Set"
,
"negative householder size"
);
349
return
PLASMA_ERR_ILLEGAL_VALUE
;
350
}
351
plasma->
rhblock
= value;
352
break
;
353
case
PLASMA_TRANSLATION_MODE
:
354
if
(value !=
PLASMA_INPLACE
&& value !=
PLASMA_OUTOFPLACE
) {
355
plasma_error
(
"PLASMA_Set"
,
"illegal value of PLASMA_TRANSLATION_MODE"
);
356
return
PLASMA_ERR_ILLEGAL_VALUE
;
357
}
358
plasma->
translation
= value;
359
break
;
360
default
:
361
plasma_error
(
"PLASMA_Set"
,
"unknown parameter"
);
362
return
PLASMA_ERR_ILLEGAL_VALUE
;
363
}
364
return
PLASMA_SUCCESS
;
365
}
366
367
/***************************************************************************/
391
int
PLASMA_Get
(
PLASMA_enum
param,
int
*value)
392
{
393
plasma_context_t
*
plasma
;
394
395
plasma =
plasma_context_self
();
396
if
(plasma == NULL) {
397
plasma_fatal_error
(
"PLASMA_Get"
,
"PLASMA not initialized"
);
398
return
PLASMA_ERR_NOT_INITIALIZED
;
399
}
400
switch
(param) {
401
case
PLASMA_TILE_SIZE
:
402
*value = plasma->
nb
;
403
return
PLASMA_SUCCESS
;
404
case
PLASMA_INNER_BLOCK_SIZE
:
405
*value = plasma->
ib
;
406
return
PLASMA_SUCCESS
;
407
case
PLASMA_SCHEDULING_MODE
:
408
*value = plasma->
scheduling
;
409
return
PLASMA_SUCCESS
;
410
case
PLASMA_HOUSEHOLDER_MODE
:
411
*value = plasma->
householder
;
412
return
PLASMA_SUCCESS
;
413
case
PLASMA_HOUSEHOLDER_SIZE
:
414
*value = plasma->
rhblock
;
415
return
PLASMA_SUCCESS
;
416
case
PLASMA_TRANSLATION_MODE
:
417
*value = plasma->
translation
;
418
return
PLASMA_SUCCESS
;
419
default
:
420
plasma_error
(
"PLASMA_Get"
,
"unknown parameter"
);
421
return
PLASMA_ERR_ILLEGAL_VALUE
;
422
}
423
}
plasma_2.4.5
control
context.c
Generated on Mon Jul 9 2012 12:44:58 for PLASMA by
1.8.1