Mercurial > hg > Members > Moririn
annotate src/parallel_execution/context.h @ 435:af0ec811b20e
Add CUDAExecutor
author | Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sat, 04 Nov 2017 04:14:36 +0900 |
parents | b75badf42701 |
children | 08a93fc2f0d3 |
rev | line source |
---|---|
86 | 1 /* Context definition for llrb example */ |
132 | 2 #ifndef CONTEXT_H |
3 #define CONTEXT_H | |
207
7470b8382672
Fix compile error to stack_test
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
194
diff
changeset
|
4 #include <stdlib.h> |
86 | 5 #include <pthread.h> |
304
9755206813cb
helper_string.h for ANSI C
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
302
diff
changeset
|
6 #ifdef USE_CUDAWorker |
98 | 7 #include <cuda.h> |
101 | 8 #endif |
86 | 9 |
95
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
10 #define ALLOCATE_SIZE 20000000 |
101 | 11 #define NEW(type) (type*)(calloc(1, sizeof(type))) |
12 #define NEWN(n, type) (type*)(calloc(n, sizeof(type))) | |
13 | |
133 | 14 #define ALLOC_DATA(context, dseg) ({\ |
434
b75badf42701
Define Executor to context
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
431
diff
changeset
|
15 Meta* meta = (Meta*)context->heap;\ |
148
473b7d990a1f
fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
147
diff
changeset
|
16 meta->type = D_##dseg;\ |
434
b75badf42701
Define Executor to context
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
431
diff
changeset
|
17 meta->size = sizeof(dseg);\ |
430
35b37fe8d3a7
Add size member in struct Meta
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
429
diff
changeset
|
18 meta->len = 1;\ |
434
b75badf42701
Define Executor to context
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
431
diff
changeset
|
19 context->heap += sizeof(Meta);\ |
b75badf42701
Define Executor to context
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
431
diff
changeset
|
20 context->data[D_##dseg] = context->heap; context->heap += sizeof(dseg); (dseg *)context->data[D_##dseg]; }) |
101 | 21 |
133 | 22 #define ALLOC_DATA_TYPE(context, dseg, t) ({\ |
434
b75badf42701
Define Executor to context
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
431
diff
changeset
|
23 Meta* meta = (Meta*)context->heap;\ |
148
473b7d990a1f
fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
147
diff
changeset
|
24 meta->type = D_##t;\ |
434
b75badf42701
Define Executor to context
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
431
diff
changeset
|
25 meta->size = sizeof(t);\ |
430
35b37fe8d3a7
Add size member in struct Meta
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
429
diff
changeset
|
26 meta->len = 1;\ |
434
b75badf42701
Define Executor to context
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
431
diff
changeset
|
27 context->heap += sizeof(Meta);\ |
b75badf42701
Define Executor to context
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
431
diff
changeset
|
28 context->data[D_##dseg] = context->heap; context->heap += sizeof(t); (t *)context->data[D_##dseg]; }) |
86 | 29 |
132 | 30 #define ALLOCATE(context, t) ({ \ |
434
b75badf42701
Define Executor to context
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
431
diff
changeset
|
31 Meta* meta = (Meta*)context->heap;\ |
b75badf42701
Define Executor to context
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
431
diff
changeset
|
32 context->heap += sizeof(Meta);\ |
133 | 33 union Data* data = context->heap; \ |
434
b75badf42701
Define Executor to context
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
431
diff
changeset
|
34 context->heap += sizeof(t); \ |
148
473b7d990a1f
fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
147
diff
changeset
|
35 meta->type = D_##t; \ |
434
b75badf42701
Define Executor to context
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
431
diff
changeset
|
36 meta->size = sizeof(t); \ |
430
35b37fe8d3a7
Add size member in struct Meta
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
429
diff
changeset
|
37 meta->len = 1;\ |
133 | 38 data; }) |
132 | 39 |
430
35b37fe8d3a7
Add size member in struct Meta
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
429
diff
changeset
|
40 #define ALLOCATE_ARRAY(context, t, length) ({ \ |
434
b75badf42701
Define Executor to context
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
431
diff
changeset
|
41 Meta* meta = (Meta*)context->heap;\ |
b75badf42701
Define Executor to context
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
431
diff
changeset
|
42 context->heap += sizeof(Meta);\ |
404
c5cd9888bf2a
Fix bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
402
diff
changeset
|
43 union Data* data = context->heap; \ |
434
b75badf42701
Define Executor to context
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
431
diff
changeset
|
44 context->heap += sizeof(t)*length; \ |
404
c5cd9888bf2a
Fix bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
402
diff
changeset
|
45 meta->type = D_##t; \ |
434
b75badf42701
Define Executor to context
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
431
diff
changeset
|
46 meta->size = sizeof(t)*length; \ |
430
35b37fe8d3a7
Add size member in struct Meta
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
429
diff
changeset
|
47 meta->len = length; \ |
404
c5cd9888bf2a
Fix bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
402
diff
changeset
|
48 data; }) |
c5cd9888bf2a
Fix bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
402
diff
changeset
|
49 |
430
35b37fe8d3a7
Add size member in struct Meta
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
429
diff
changeset
|
50 #define ALLOCATE_PTR_ARRAY(context, dseg, length) ({\ |
434
b75badf42701
Define Executor to context
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
431
diff
changeset
|
51 Meta* meta = (Meta*)context->heap;\ |
b75badf42701
Define Executor to context
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
431
diff
changeset
|
52 context->heap += sizeof(Meta);\ |
236 | 53 union Data* data = context->heap; \ |
434
b75badf42701
Define Executor to context
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
431
diff
changeset
|
54 context->heap += sizeof(dseg *)*length; \ |
236 | 55 meta->type = D_##dseg; \ |
434
b75badf42701
Define Executor to context
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
431
diff
changeset
|
56 meta->size = sizeof(dseg *)*length; \ |
430
35b37fe8d3a7
Add size member in struct Meta
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
429
diff
changeset
|
57 meta->len = length; \ |
236 | 58 data; }) |
59 | |
327
534601ed8c50
Running dependency example for single thread and single task
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
326
diff
changeset
|
60 #define ALLOCATE_DATA_GEAR(context, t) ({ \ |
534601ed8c50
Running dependency example for single thread and single task
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
326
diff
changeset
|
61 union Data* data = ALLOCATE(context, t); \ |
434
b75badf42701
Define Executor to context
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
431
diff
changeset
|
62 Meta* meta = GET_META(data); \ |
327
534601ed8c50
Running dependency example for single thread and single task
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
326
diff
changeset
|
63 meta->wait = createSingleLinkedQueue(context); \ |
534601ed8c50
Running dependency example for single thread and single task
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
326
diff
changeset
|
64 data; }) |
534601ed8c50
Running dependency example for single thread and single task
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
326
diff
changeset
|
65 |
430
35b37fe8d3a7
Add size member in struct Meta
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
429
diff
changeset
|
66 #define ALLOC(context, t) (&ALLOCATE(context, t)->t) |
35b37fe8d3a7
Add size member in struct Meta
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
429
diff
changeset
|
67 |
434
b75badf42701
Define Executor to context
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
431
diff
changeset
|
68 #define GET_META(dseg) ((Meta*)(((void*)dseg) - sizeof(Meta))) |
288 | 69 #define GET_TYPE(dseg) (GET_META(dseg)->type) |
352
3e01e963eb2d
Fix compile error for calc example but not work
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
344
diff
changeset
|
70 #define GET_SIZE(dseg) (GET_META(dseg)->size) |
430
35b37fe8d3a7
Add size member in struct Meta
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
429
diff
changeset
|
71 #define GET_LEN(dseg) (GET_META(dseg)->len) |
288 | 72 #define GET_WAIT_LIST(dseg) (GET_META(dseg)->wait) |
132 | 73 |
149 | 74 #define Gearef(context, t) (&(context)->data[D_##t]->t) |
186 | 75 |
434
b75badf42701
Define Executor to context
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
431
diff
changeset
|
76 // (SingleLinkedStack *)context->data[D_Stack]->Stack.stack->Stack.stack |
232 | 77 |
78 #define GearImpl(context, intf, name) (Gearef(context, intf)->name->intf.name) | |
79 | |
186 | 80 #include "c/enumCode.h" |
86 | 81 |
82 enum Relational { | |
83 EQ, | |
84 GT, | |
85 LT, | |
86 }; | |
87 | |
186 | 88 #include "c/enumData.h" |
86 | 89 |
90 struct Context { | |
91 enum Code next; | |
230 | 92 struct Worker* worker; |
93 struct TaskManager* taskManager; | |
86 | 94 int codeNum; |
95 __code (**code) (struct Context*); | |
96 void* heapStart; | |
97 void* heap; | |
98 long heapLimit; | |
87 | 99 int dataNum; |
236 | 100 int idgCount; //number of waiting dataGear |
326
f23f6d0aa4e9
Add examples/calc.cbc and build but not work
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
320
diff
changeset
|
101 int idg; |
f23f6d0aa4e9
Add examples/calc.cbc and build but not work
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
320
diff
changeset
|
102 int maxIdg; |
282
a3448b0f0a56
Add input data gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
278
diff
changeset
|
103 int odg; |
288 | 104 int maxOdg; |
242 | 105 int workerId; |
410
85b0ddbf458e
Fix CudaWorker
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
406
diff
changeset
|
106 int gpu; // GPU task |
406
9b35e6581b5c
Use task member of context by par goto meta
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
405
diff
changeset
|
107 struct Context* task; |
398
fc4fcd441700
Fix spanwTasks
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
397
diff
changeset
|
108 struct Queue* tasks; |
308 | 109 #ifdef USE_CUDAWorker |
110 int num_exec; | |
111 CUmodule module; | |
112 CUfunction function; | |
309 | 113 #endif |
86 | 114 union Data **data; |
372
d6ce4273e7d1
Add dimension task spawn
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
369
diff
changeset
|
115 |
d6ce4273e7d1
Add dimension task spawn
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
369
diff
changeset
|
116 /* multi dimension parameter */ |
374
fb50cf8aa615
Add Iterator Interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
372
diff
changeset
|
117 int iterate; |
fb50cf8aa615
Add Iterator Interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
372
diff
changeset
|
118 struct Iterator* iterator; |
86 | 119 }; |
120 | |
121 union Data { | |
133 | 122 struct Meta { |
123 enum DataType type; | |
236 | 124 long size; |
430
35b37fe8d3a7
Add size member in struct Meta
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
429
diff
changeset
|
125 long len; |
176 | 126 struct Queue* wait; // tasks waiting this dataGear |
133 | 127 } meta; |
259
195518ab62fc
fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
254
diff
changeset
|
128 struct Context Context; |
95
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
129 struct Time { |
364
a0a3301bac4d
Add Time interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
362
diff
changeset
|
130 union Data* time; |
a0a3301bac4d
Add Time interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
362
diff
changeset
|
131 enum Code start; |
a0a3301bac4d
Add Time interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
362
diff
changeset
|
132 enum Code end; |
102 | 133 enum Code next; |
364
a0a3301bac4d
Add Time interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
362
diff
changeset
|
134 } Time; |
a0a3301bac4d
Add Time interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
362
diff
changeset
|
135 struct TimeImpl { |
95
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
136 double time; |
364
a0a3301bac4d
Add Time interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
362
diff
changeset
|
137 } TimeImpl; |
86 | 138 struct LoopCounter { |
139 int i; | |
217
c34e6aa10967
Fix DataGear access name
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
207
diff
changeset
|
140 } LoopCounter; |
176 | 141 struct TaskManager { |
320
f730761bb044
non CUDA case clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
316
diff
changeset
|
142 #ifdef USE_CUDA_MAIN_THREAD |
f730761bb044
non CUDA case clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
316
diff
changeset
|
143 volatile |
f730761bb044
non CUDA case clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
316
diff
changeset
|
144 #endif |
f730761bb044
non CUDA case clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
316
diff
changeset
|
145 union Data* taskManager; |
234 | 146 enum Code spawn; // start NEW context on the worker |
398
fc4fcd441700
Fix spanwTasks
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
397
diff
changeset
|
147 enum Code spawnTasks; // start NEW tasks on the worker |
176 | 148 enum Code shutdown; |
405
8915fce522b3
Fix shutdown TaskManager
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
404
diff
changeset
|
149 enum Code incrementTaskCount; |
8915fce522b3
Fix shutdown TaskManager
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
404
diff
changeset
|
150 enum Code decrementTaskCount; |
184 | 151 enum Code next; |
353
b07078bd1f2c
Add spawn Tasks to TaskManagerImpl
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
352
diff
changeset
|
152 enum Code next1; |
233 | 153 enum Code task; |
154 struct Context* context; | |
398
fc4fcd441700
Fix spanwTasks
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
397
diff
changeset
|
155 struct Queue* tasks; |
326
f23f6d0aa4e9
Add examples/calc.cbc and build but not work
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
320
diff
changeset
|
156 union Data* data; |
233 | 157 int worker; |
158 int cpu; | |
159 int gpu; | |
160 int io; | |
237 | 161 int maxCPU; |
184 | 162 } TaskManager; |
182 | 163 struct TaskManagerImpl { |
388 | 164 enum Code next; |
233 | 165 int numWorker; |
410
85b0ddbf458e
Fix CudaWorker
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
406
diff
changeset
|
166 int sendCPUWorkerIndex; |
85b0ddbf458e
Fix CudaWorker
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
406
diff
changeset
|
167 int sendGPUWorkerIndex; |
405
8915fce522b3
Fix shutdown TaskManager
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
404
diff
changeset
|
168 int taskCount; |
239 | 169 pthread_mutex_t mutex; |
184 | 170 struct Queue* activeQueue; |
171 struct Queue* taskQueue; | |
244 | 172 struct Worker** workers; |
352
3e01e963eb2d
Fix compile error for calc example but not work
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
344
diff
changeset
|
173 struct LoopCounter* loopCounter; |
184 | 174 } TaskManagerImpl; |
86 | 175 struct Worker { |
232 | 176 union Data* worker; |
222
77faa28128b4
Add taskSend for TaskManager
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
218
diff
changeset
|
177 enum Code taskReceive; |
176 | 178 enum Code shutdown; |
230 | 179 enum Code next; |
244 | 180 struct Queue* tasks; |
411
0eba9a04633f
Work CUDAtwice
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
410
diff
changeset
|
181 pthread_t thread; |
288 | 182 struct TaskManager* taskManager; |
184 | 183 } Worker; |
232 | 184 struct CPUWorker { |
242 | 185 pthread_mutex_t mutex; |
186 pthread_cond_t cond; | |
232 | 187 struct Context* context; |
188 int id; | |
189 } CPUWorker; | |
302 | 190 #ifdef USE_CUDAWorker |
191 struct CUDAWorker { | |
316
54d203daf06b
CUDAtwice.cbc is called.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
309
diff
changeset
|
192 CUdevice device; |
54d203daf06b
CUDAtwice.cbc is called.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
309
diff
changeset
|
193 CUcontext cuCtx; |
233 | 194 pthread_t thread; |
232 | 195 struct Context* context; |
196 int id; | |
197 struct Queue* tasks; | |
198 int runFlag; | |
199 enum Code next; | |
305 | 200 int num_stream; |
201 CUstream *stream; | |
202 } CUDAWorker; | |
187 | 203 #else |
302 | 204 struct CUDAWorker { |
305 | 205 } CUDAWorker; |
101 | 206 #endif |
177 | 207 struct Main { |
208 enum Code code; | |
209 enum Code next; | |
210 struct Queue* args; | |
185 | 211 } Main; |
169
ea7b11f3e717
Using Queue Interface
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
168
diff
changeset
|
212 // Queue Interface |
90 | 213 struct Queue { |
136 | 214 union Data* queue; |
167 | 215 union Data* data; |
216 enum Code whenEmpty; | |
217 enum Code clear; | |
218 enum Code put; | |
219 enum Code take; | |
220 enum Code isEmpty; | |
130 | 221 enum Code next; |
184 | 222 } Queue; |
167 | 223 struct SingleLinkedQueue { |
224 struct Element* top; | |
225 struct Element* last; | |
184 | 226 } SingleLinkedQueue; |
282
a3448b0f0a56
Add input data gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
278
diff
changeset
|
227 struct SynchronizedQueue { |
a3448b0f0a56
Add input data gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
278
diff
changeset
|
228 struct Element* top; |
a3448b0f0a56
Add input data gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
278
diff
changeset
|
229 struct Element* last; |
a3448b0f0a56
Add input data gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
278
diff
changeset
|
230 } SynchronizedQueue; |
132 | 231 // Stack Interface |
130 | 232 struct Stack { |
132 | 233 union Data* stack; |
130 | 234 union Data* data; |
133 | 235 union Data* data1; |
169
ea7b11f3e717
Using Queue Interface
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
168
diff
changeset
|
236 enum Code whenEmpty; |
145
cc071cf1ba85
add stack clear interface
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
144
diff
changeset
|
237 enum Code clear; |
130 | 238 enum Code push; |
239 enum Code pop; | |
133 | 240 enum Code pop2; |
130 | 241 enum Code isEmpty; |
134
2eccf4564efe
fix stack call in rb_tree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
242 enum Code get; |
133 | 243 enum Code get2; |
130 | 244 enum Code next; |
194 | 245 } Stack; |
132 | 246 // Stack implementations |
247 struct SingleLinkedStack { | |
248 struct Element* top; | |
194 | 249 } SingleLinkedStack; |
132 | 250 struct ArrayStack { |
251 int size; | |
252 int limit; | |
253 struct Element* array; | |
194 | 254 } ArrayStack; |
132 | 255 // Stack implementation end |
90 | 256 struct Element { |
114
d05b9937aa95
Change element data from Task to Data
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
257 union Data* data; |
90 | 258 struct Element* next; |
194 | 259 } Element; |
86 | 260 struct Array { |
381
b81492c74d2b
Create examples directory
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
379
diff
changeset
|
261 int size; |
b81492c74d2b
Create examples directory
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
379
diff
changeset
|
262 int prefix; |
b81492c74d2b
Create examples directory
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
379
diff
changeset
|
263 int* array; |
194 | 264 } Array; |
86 | 265 struct Tree { |
166 | 266 union Data* tree; |
267 struct Node* node; | |
150 | 268 enum Code put; |
269 enum Code get; | |
270 enum Code remove; | |
171 | 271 enum Code clear; |
150 | 272 enum Code next; |
166 | 273 } Tree; |
172 | 274 struct RedBlackTree { |
150 | 275 struct Node* root; |
122 | 276 struct Node* current; // reading node of original tree |
138 | 277 struct Node* previous; // parent of reading node of original tree |
124 | 278 struct Node* newNode; // writing node of new tree |
143
34a7a21edc36
recude stack get using traverse field
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
138
diff
changeset
|
279 struct Node* parent; |
34a7a21edc36
recude stack get using traverse field
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
138
diff
changeset
|
280 struct Node* grandparent; |
132 | 281 struct Stack* nodeStack; |
86 | 282 int result; |
172 | 283 } RedBlackTree; |
147 | 284 struct RotateTree { |
285 enum Code next; | |
172 | 286 struct RedBlackTree* traverse; |
147 | 287 struct Tree* tree; |
217
c34e6aa10967
Fix DataGear access name
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
207
diff
changeset
|
288 } RotateTree; |
86 | 289 struct Node { |
290 int key; // comparable data segment | |
90 | 291 union Data* value; |
86 | 292 struct Node* left; |
293 struct Node* right; | |
294 // need to balancing | |
295 enum Color { | |
296 Red, | |
297 Black, | |
298 } color; | |
217
c34e6aa10967
Fix DataGear access name
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
207
diff
changeset
|
299 } Node; |
286 | 300 struct Semaphore { |
301 union Data* semaphore; | |
302 enum Code p; | |
303 enum Code v; | |
304 enum Code next; | |
305 } Semaphore; | |
306 struct SemaphoreImpl { | |
307 int value; | |
308 pthread_mutex_t mutex; | |
309 pthread_cond_t cond; | |
310 } SemaphoreImpl; | |
86 | 311 struct Allocate { |
312 enum Code next; | |
313 long size; | |
217
c34e6aa10967
Fix DataGear access name
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
207
diff
changeset
|
314 } Allocate; |
326
f23f6d0aa4e9
Add examples/calc.cbc and build but not work
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
320
diff
changeset
|
315 struct Integer { |
f23f6d0aa4e9
Add examples/calc.cbc and build but not work
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
320
diff
changeset
|
316 int value; |
f23f6d0aa4e9
Add examples/calc.cbc and build but not work
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
320
diff
changeset
|
317 } Integer; |
404
c5cd9888bf2a
Fix bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
402
diff
changeset
|
318 struct SortArray { |
c5cd9888bf2a
Fix bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
402
diff
changeset
|
319 struct Integer *array; //Array arrayじゃできない? |
379
2744cb933ebc
Fix compile error for bitonicSort but not work
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
375
diff
changeset
|
320 int loopCounter; |
404
c5cd9888bf2a
Fix bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
402
diff
changeset
|
321 int block; |
c5cd9888bf2a
Fix bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
402
diff
changeset
|
322 int first; |
383
300c18700ca5
Add split to bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
381
diff
changeset
|
323 int prefix; |
374
fb50cf8aa615
Add Iterator Interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
372
diff
changeset
|
324 } SortArray; |
fb50cf8aa615
Add Iterator Interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
372
diff
changeset
|
325 struct Iterator { |
375
ad44fdb11433
Fix compile error but not work
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
374
diff
changeset
|
326 union Data* iterator; |
ad44fdb11433
Fix compile error but not work
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
374
diff
changeset
|
327 struct Context* task; |
410
85b0ddbf458e
Fix CudaWorker
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
406
diff
changeset
|
328 int numGPU; |
374
fb50cf8aa615
Add Iterator Interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
372
diff
changeset
|
329 enum Code exec; |
fb50cf8aa615
Add Iterator Interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
372
diff
changeset
|
330 enum Code barrier; |
fb50cf8aa615
Add Iterator Interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
372
diff
changeset
|
331 enum Code whenWait; |
fb50cf8aa615
Add Iterator Interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
372
diff
changeset
|
332 enum Code next; |
fb50cf8aa615
Add Iterator Interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
372
diff
changeset
|
333 } Iterator; |
402
e958a409943c
Change iterator implement from oneDim to multiDim
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
398
diff
changeset
|
334 struct MultiDimIterator { |
374
fb50cf8aa615
Add Iterator Interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
372
diff
changeset
|
335 int x; |
402
e958a409943c
Change iterator implement from oneDim to multiDim
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
398
diff
changeset
|
336 int y; |
e958a409943c
Change iterator implement from oneDim to multiDim
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
398
diff
changeset
|
337 int z; |
374
fb50cf8aa615
Add Iterator Interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
372
diff
changeset
|
338 int count; |
402
e958a409943c
Change iterator implement from oneDim to multiDim
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
398
diff
changeset
|
339 int counterX; |
e958a409943c
Change iterator implement from oneDim to multiDim
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
398
diff
changeset
|
340 int counterY; |
e958a409943c
Change iterator implement from oneDim to multiDim
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
398
diff
changeset
|
341 int counterZ; |
e958a409943c
Change iterator implement from oneDim to multiDim
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
398
diff
changeset
|
342 } MultiDimIterator; |
e958a409943c
Change iterator implement from oneDim to multiDim
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
398
diff
changeset
|
343 struct MultiDim { |
e958a409943c
Change iterator implement from oneDim to multiDim
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
398
diff
changeset
|
344 int x; |
e958a409943c
Change iterator implement from oneDim to multiDim
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
398
diff
changeset
|
345 int y; |
e958a409943c
Change iterator implement from oneDim to multiDim
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
398
diff
changeset
|
346 int z; |
e958a409943c
Change iterator implement from oneDim to multiDim
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
398
diff
changeset
|
347 } MultiDim; |
434
b75badf42701
Define Executor to context
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
431
diff
changeset
|
348 struct Executor { |
b75badf42701
Define Executor to context
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
431
diff
changeset
|
349 struct Executor* executor; |
b75badf42701
Define Executor to context
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
431
diff
changeset
|
350 struct Context* task; |
b75badf42701
Define Executor to context
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
431
diff
changeset
|
351 enum Code read; |
b75badf42701
Define Executor to context
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
431
diff
changeset
|
352 enum Code exec; |
b75badf42701
Define Executor to context
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
431
diff
changeset
|
353 enum Code write; |
b75badf42701
Define Executor to context
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
431
diff
changeset
|
354 enum Code next; |
b75badf42701
Define Executor to context
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
431
diff
changeset
|
355 } Executor; |
b75badf42701
Define Executor to context
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
431
diff
changeset
|
356 #ifdef USE_CUDAWorker |
435
af0ec811b20e
Add CUDAExecutor
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
434
diff
changeset
|
357 struct CUDAExecutor { |
431
b3359544adbb
Edit cudaExec but not work
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
430
diff
changeset
|
358 void** kernelParams; |
435
af0ec811b20e
Add CUDAExecutor
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
434
diff
changeset
|
359 CUDABuffer* buffer; |
af0ec811b20e
Add CUDAExecutor
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
434
diff
changeset
|
360 } CUDAExecutor; |
af0ec811b20e
Add CUDAExecutor
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
434
diff
changeset
|
361 CudevicePtr CudevicePtr; |
434
b75badf42701
Define Executor to context
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
431
diff
changeset
|
362 #else |
435
af0ec811b20e
Add CUDAExecutor
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
434
diff
changeset
|
363 struct CUDAExecutor { |
af0ec811b20e
Add CUDAExecutor
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
434
diff
changeset
|
364 } CUDAExecutor; |
434
b75badf42701
Define Executor to context
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
431
diff
changeset
|
365 #endif |
435
af0ec811b20e
Add CUDAExecutor
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
434
diff
changeset
|
366 struct CUDABuffer { |
431
b3359544adbb
Edit cudaExec but not work
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
430
diff
changeset
|
367 int inputLen; |
b3359544adbb
Edit cudaExec but not work
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
430
diff
changeset
|
368 int outputLen; |
b3359544adbb
Edit cudaExec but not work
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
430
diff
changeset
|
369 union Data** inputData; |
b3359544adbb
Edit cudaExec but not work
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
430
diff
changeset
|
370 union Data** outputData; |
435
af0ec811b20e
Add CUDAExecutor
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
434
diff
changeset
|
371 } CUDABuffer; |
254 | 372 }; // union Data end this is necessary for context generator |
114
d05b9937aa95
Change element data from Task to Data
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
373 |
259
195518ab62fc
fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
254
diff
changeset
|
374 typedef union Data Data; |
195518ab62fc
fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
254
diff
changeset
|
375 |
186 | 376 #include "c/typedefData.h" |
278 | 377 |
378 #include "c/extern.h" | |
379 | |
380 extern __code start_code(struct Context* context); | |
381 extern __code exit_code(struct Context* context); | |
382 extern __code meta(struct Context* context, enum Code next); | |
398
fc4fcd441700
Fix spanwTasks
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
397
diff
changeset
|
383 extern __code par_meta(struct Context* context, enum Code spawns, enum Code next); |
278 | 384 extern void initContext(struct Context* context); |
385 | |
132 | 386 #endif |