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
quark.h
Go to the documentation of this file.
1
16
#ifndef QUARK_H
17
#define QUARK_H
18
19
#include <limits.h>
20
#include <stdio.h>
21
22
#if defined( _WIN32 )
23
/* This must be included before INPUT is defined below, otherwise we
24
have a name clash/problem */
25
#include <windows.h>
26
#include <limits.h>
27
#else
28
#include <inttypes.h>
29
#endif
30
31
#include "
quark_unpack_args.h
"
32
33
#if defined(c_plusplus) || defined(__cplusplus)
34
extern
"C"
{
35
#endif
36
37
//#define DBGPRINTF(args...) if (0) {};
38
/* #define DBGPRINTF(args...) { fprintf(stderr,"%s:%d: [%s] ",__FILE__,__LINE__,__FUNCTION__); fprintf(stderr, args); } */
39
//#define LOGPRINTF(args...) { fprintf(stderr,"%s:%d: [%s] ",__FILE__,__LINE__,__FUNCTION__); fprintf(stderr, args); }
40
// #define DBGPRINTF(args...) { fprintf(stderr, args); }
41
42
#define QUARK_SUCCESS 0
43
#define QUARK_ERR -1
44
#define QUARK_ERR_UNEXPECTED -1
45
#define QUARK_ERR_NOT_SUPPORTED -2
46
47
/* Data items can be: */
48
/* INPUT, OUTPUT, INOUT: these data items create dependencies */
49
/* VALUE: these data items get copied over */
50
/* NODEP: these data items get copied over, and are not used for dependencies */
51
/* SCRATCH: these data items can be allocated (and deallocted) by the scheduler when tasks execute */
52
typedef
enum
{
QINPUT
=0x01,
OUTPUT
=0x02,
INOUT
=0x03,
VALUE
=0x04,
NODEP
=0x05,
SCRATCH
=0x06 }
quark_direction_t
;
53
#define INPUT 0x01
54
55
/* Data locality flag; ie keep data on the same core if possible */
56
#define LOCALITY ( 1 << 3 )
57
#define NOLOCALITY 0x00
58
59
/* A data address with a sequence of ACCUMULATOR dependencies will allow the related tasks to be reordered */
60
#define ACCUMULATOR ( 1 << 4 )
61
#define NOACCUMULATOR 0x00
62
63
/* A data address with a sequence of GATHERV dependencies will allow the related tasks to be run in parallel */
64
#define GATHERV ( 1 << 5 )
65
#define NOGATHERV 0x00
66
67
/* The following are task level flags, that can be either provided as additional arguments to the task, or via SET functions */
68
/* The task label; should be provided as a null terminated string */
69
#define TASK_LABEL ( 1 << 6 )
70
#define TASKLABEL ( 1 << 6 )
/* depreciated label */
71
/* The task color; should be provided as a null terminated string */
72
#define TASK_COLOR ( 1 << 7 )
73
#define TASKCOLOR ( 1 << 7 )
/* depreciated label */
74
/* The priority of the task, provided as an integer */
75
#define TASK_PRIORITY ( 1 << 8 )
76
/* Lock the task to a specific thread number (0 ... NTHREADS-1), provided as an integer */
77
#define TASK_LOCK_TO_THREAD ( 1 << 9 )
78
/* The sequence pointer to be associated with the task, provided as a pointer */
79
#define TASK_SEQUENCE ( 1 << 10 )
80
/* An integere for the number of threads require */
81
#define TASK_THREAD_COUNT ( 1 << 11 )
82
/* Lock the task to a thead mask (0 ... NTHREADS-1) bits long, provided as a character array (byte array) */
83
// #define TASK_LOCK_TO_THREAD_MASK ( 1 << 12 )
84
85
/* The range for priority values */
86
#define QUARK_TASK_MIN_PRIORITY 0
87
#define QUARK_TASK_MAX_PRIORITY INT_MAX
88
89
/* Definition of structure holding scheduler information */
90
typedef
struct
quark_s
Quark
;
91
92
/* Structure holding task information */
93
typedef
struct
quark_task_s
Quark_Task
;
94
95
/* Create a type for setting task flags */
96
struct
quark_task_flags_s
{
97
int
task_priority
;
98
int
task_lock_to_thread
;
99
char
*
task_color
;
100
char
*
task_label
;
101
void
*
task_sequence
;
102
int
task_thread_count
;
103
// char *task_lock_to_thread_mask;
104
};
105
106
typedef
struct
quark_task_flags_s
Quark_Task_Flags
;
107
/* Static initializer for Quark_Task_Flags_t */
108
#define Quark_Task_Flags_Initializer { (int)0, (int)-1, (char *)NULL, (char *)NULL, (void *)NULL, (int)1 }
109
110
/* Setup scheduler data structures, assumes threads are managed seperately */
111
Quark
*
QUARK_Setup
(
int
num_threads);
112
113
/* Setup scheduler data structures, spawn worker threads, start the workers working */
114
Quark
*
QUARK_New
(
int
num_threads);
115
116
/* Add a task, called by the master process (thread_rank 0) */
117
unsigned
long
long
QUARK_Insert_Task
(
Quark
* quark,
void
(*
function
) (
Quark
*),
Quark_Task_Flags
*task_flags, ...);
118
119
/* Main work loop, called externally by everyone but the master
120
* (master manages this internally to the insert_task and waitall
121
* routines). Each worker thread can call work_main_loop( quark,
122
* thread_rank), where thread rank is 1...NUMTHREADS ) */
123
void
QUARK_Worker_Loop
(
Quark
*quark,
int
thread_rank);
124
125
/* Finish work and return. Workers do not exit */
126
void
QUARK_Barrier
(
Quark
* quark);
127
128
/* Just wait for current tasks to complete, the scheduler and
129
* strutures remain as is... should allow for repeated use of the
130
* scheduler. The workers return from their loops.*/
131
void
QUARK_Waitall
(
Quark
* quark);
132
133
/* Delete scheduler, shutdown threads, finish everything, free structures */
134
void
QUARK_Delete
(
Quark
* quark);
135
136
/* Free scheduling data structures */
137
void
QUARK_Free
(
Quark
* quark);
138
139
/* Cancel a specific task */
140
int
QUARK_Cancel_Task
(
Quark
*quark,
unsigned
long
long
taskid);
141
142
/* Returns a pointer to the list of arguments, used when unpacking the
143
arguments; Returna a pointer to icl_list_t, so icl_list.h will need
144
bo included if you use this function */
145
void
*
QUARK_Args_List
(
Quark
*quark);
146
147
/* Return a pointer to an argument. The variable last_arg should be
148
NULL on the first call, then each subsequent call will used
149
last_arg to get the the next argument. */
150
void
*
QUARK_Args_Pop
(
void
*args_list,
void
**last_arg);
151
152
/* Utility function returning rank of the current thread */
153
int
QUARK_Thread_Rank
(
Quark
*quark);
154
155
/* Packed task interface */
156
/* Create a task data structure to hold arguments */
157
Quark_Task
*
QUARK_Task_Init
(
Quark
* quark,
void
(*
function
) (
Quark
*),
Quark_Task_Flags
*task_flags );
158
159
/* Add (or pack) the arguments into a task data structure (make sure of the correct order) */
160
void
QUARK_Task_Pack_Arg
(
Quark
*quark,
Quark_Task
*task,
int
arg_size,
void
*arg_ptr,
int
arg_flags );
161
162
/* Insert the packed task data strucure into the scheduler for execution */
163
unsigned
long
long
QUARK_Insert_Task_Packed
(
Quark
* quark,
Quark_Task
*task );
164
165
/* Unsupported function for debugging purposes; execute task AT ONCE */
166
unsigned
long
long
QUARK_Execute_Task
(
Quark
* quark,
void
(*
function
) (
Quark
*),
Quark_Task_Flags
*task_flags, ...);
167
168
/* Get the label (if any) associated with the current task; used for printing and debugging */
169
char
*
QUARK_Get_Task_Label
(
Quark
*quark);
170
171
/* Method for setting task flags */
172
Quark_Task_Flags
*
QUARK_Task_Flag_Set
(
Quark_Task_Flags
*flags,
int
flag, intptr_t val );
173
174
/* Type for task sequences */
175
typedef
struct
Quark_sequence_s
Quark_Sequence
;
176
177
/* Create a seqeuence structure, to hold sequences of tasks */
178
Quark_Sequence
*
QUARK_Sequence_Create
(
Quark
*quark );
179
180
/* Called by worker, cancel any pending tasks, and mark sequence so that it does not accept any more tasks */
181
int
QUARK_Sequence_Cancel
(
Quark
*quark,
Quark_Sequence
*sequence );
182
183
/* Destroy a sequence structure, cancelling any pending tasks */
184
Quark_Sequence
*
QUARK_Sequence_Destroy
(
Quark
*quark,
Quark_Sequence
*sequence );
185
186
/* Wait for a sequence of tasks to complete */
187
int
QUARK_Sequence_Wait
(
Quark
*quark,
Quark_Sequence
*sequence );
188
189
/* Get the sequence information associated the current task/worker, this was provided when the tasks was created */
190
Quark_Sequence
*
QUARK_Get_Sequence
(
Quark
*quark);
191
192
193
#if defined(c_plusplus) || defined(__cplusplus)
194
}
195
#endif
196
197
#endif
/* QUARK.H */
magma-1.2.0
exp
quark
include
quark.h
Generated on Mon May 21 2012 16:42:20 for MAGMA by
1.8.1