Mercurial > hg > Gears > GearsAgda
annotate src/parallel_execution/worker.c @ 227:991f3d1ce072
fix worker
author | ikkun |
---|---|
date | Fri, 20 Jan 2017 19:12:29 +0900 |
parents | 77faa28128b4 |
children | a1fb3f2d1a36 |
rev | line source |
---|---|
95
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1 #include <libkern/OSAtomic.h> |
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2 |
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
3 #include "context.h" |
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
4 #include "origin_cs.h" |
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
5 |
183 | 6 union Data* createWorker(struct Context* context) { |
7 struct Worker* worker = &ALLOCATE(context, Worker)->Worker; | |
222
77faa28128b4
Add taskSend for TaskManager
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
217
diff
changeset
|
8 worker->execute = C_executeWorker; |
77faa28128b4
Add taskSend for TaskManager
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
217
diff
changeset
|
9 worker->taskSend = C_taskSendWorker; |
77faa28128b4
Add taskSend for TaskManager
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
217
diff
changeset
|
10 worker->taskReceive = C_taskReceiveWorker; |
77faa28128b4
Add taskSend for TaskManager
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
217
diff
changeset
|
11 worker->shutdown = C_shutdownWorker; |
183 | 12 return (union Data*)(worker); |
13 } | |
14 | |
227 | 15 __code taskSendWorker(struct Context* context) { |
222
77faa28128b4
Add taskSend for TaskManager
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
217
diff
changeset
|
16 } |
77faa28128b4
Add taskSend for TaskManager
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
217
diff
changeset
|
17 |
227 | 18 __code taskSendWorker_stub(struct Context* context) { |
19 goto taskSendWorker(context); | |
20 } | |
21 | |
22 __code executeWorker(struct Context* context, Worker* worker) { | |
222
77faa28128b4
Add taskSend for TaskManager
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
217
diff
changeset
|
23 worker->next = worker->taskReceive; |
77faa28128b4
Add taskSend for TaskManager
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
217
diff
changeset
|
24 goto meta(context, task->code); |
77faa28128b4
Add taskSend for TaskManager
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
217
diff
changeset
|
25 } |
77faa28128b4
Add taskSend for TaskManager
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
217
diff
changeset
|
26 |
227 | 27 __code executeWorker_stub(struct Context* context) { |
28 Worker* worker = &Gearef(context,Worker); | |
29 goto extcuteWorker(context,worker); | |
30 } | |
31 | |
32 __code taskReceiveWorker(struct Context* context, Worker* worker) { | |
33 Queue* queue = &Gearef(context,queue); | |
34 queue->queue = worker->tasks; | |
35 queue->next = C_getTask1; | |
36 goto meta(context, queue->take); | |
37 } | |
38 | |
39 __code taskReceiveWorker_stub(struct Context* context) { | |
40 Worker* worker = Gearef(context,Worker).worker; | |
41 goto taskReceiveWorker(context,queue); | |
222
77faa28128b4
Add taskSend for TaskManager
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
217
diff
changeset
|
42 } |
77faa28128b4
Add taskSend for TaskManager
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
217
diff
changeset
|
43 |
169
ea7b11f3e717
Using Queue Interface
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
149
diff
changeset
|
44 __code getTask1(struct Context* context, struct Queue* queue) { |
173 | 45 queue->next = C_getTask2; |
169
ea7b11f3e717
Using Queue Interface
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
149
diff
changeset
|
46 goto meta(context, queue->take); |
ea7b11f3e717
Using Queue Interface
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
149
diff
changeset
|
47 } |
109
059b26a250cc
Change put_queue process
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
103
diff
changeset
|
48 |
169
ea7b11f3e717
Using Queue Interface
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
149
diff
changeset
|
49 __code getTask1_stub(struct Context* context) { |
189 | 50 goto getTask1(context,/* &context->data[D_ActiveQueue]->Queue*/ NULL); |
95
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
51 } |
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
52 |
169
ea7b11f3e717
Using Queue Interface
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
149
diff
changeset
|
53 __code getTask2(struct Context* context, struct Task* task, struct Node* node) { |
173 | 54 context->next = C_getTask1; |
189 | 55 goto meta(context, C_getTask2); |
169
ea7b11f3e717
Using Queue Interface
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
149
diff
changeset
|
56 } |
ea7b11f3e717
Using Queue Interface
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
149
diff
changeset
|
57 |
ea7b11f3e717
Using Queue Interface
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
149
diff
changeset
|
58 __code getTask2_stub(struct Context* context) { |
217
c34e6aa10967
Fix DataGear access name
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
189
diff
changeset
|
59 goto getTask2(context, /*&(context->data[D_ActiveQueue]->Queue.data->Task)*/ NULL, &context->data[D_Node]->Node); |
95
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
60 } |
101 | 61 |
62 #ifdef USE_CUDA | |
98 | 63 __code twiceGpu(struct Context* context) { |
64 cuMemcpyHtoDAsync(context,context,context,context->stream); | |
65 cuLaunchkanel(); | |
66 cuMemcpyDtoHAsync(); | |
67 } | |
101 | 68 #endif |
227 | 69 |
70 __code shutdownWorker(struct Context* context) { | |
71 | |
72 } |