Mercurial > hg > Gears > GearsAgda
annotate src/parallel_execution/worker.c @ 248:1ede5390cda2
Fix segmentation fault but not multi thread running
author | Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 25 Jan 2017 16:55:53 +0900 |
parents | ce262b2c1daf |
children | cd3486e4ba70 |
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 |
235 | 6 static void start_worker(Worker* worker); |
233 | 7 |
236 | 8 union Data* createCPUWorker(struct Context* context, int id, Queue* queue) { |
233 | 9 struct Worker* worker = ALLOC(context, Worker); |
10 struct CPUWorker* cpuWorker = ALLOC(context, CPUWorker); | |
232 | 11 worker->worker = (union Data*)cpuWorker; |
244 | 12 worker->tasks = queue; |
232 | 13 cpuWorker->id = id; |
222
77faa28128b4
Add taskSend for TaskManager
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
217
diff
changeset
|
14 worker->taskReceive = C_taskReceiveWorker; |
77faa28128b4
Add taskSend for TaskManager
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
217
diff
changeset
|
15 worker->shutdown = C_shutdownWorker; |
235 | 16 pthread_create(&worker->worker->CPUWorker.thread, NULL, (void*)&start_worker, worker); |
183 | 17 return (union Data*)(worker); |
18 } | |
19 | |
235 | 20 static void start_worker(Worker* worker) { |
21 CPUWorker* cpuWorker = (CPUWorker*)worker->worker; | |
22 cpuWorker->context = NEW(struct Context); | |
23 initContext(cpuWorker->context); | |
247
ce262b2c1daf
Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
244
diff
changeset
|
24 Gearef(cpuWorker->context, Worker)->worker = (union Data*)worker; |
235 | 25 goto meta(cpuWorker->context, C_taskReceiveWorker); |
233 | 26 } |
27 | |
247
ce262b2c1daf
Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
244
diff
changeset
|
28 __code taskReceiveWorker(struct Context* context, Worker* worker, Queue* queue) { |
ce262b2c1daf
Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
244
diff
changeset
|
29 queue->queue = (union Data*)worker->tasks; |
248
1ede5390cda2
Fix segmentation fault but not multi thread running
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
247
diff
changeset
|
30 queue->next = C_getTask; |
1ede5390cda2
Fix segmentation fault but not multi thread running
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
247
diff
changeset
|
31 goto meta(context, worker->tasks->take); |
227 | 32 } |
33 | |
34 __code taskReceiveWorker_stub(struct Context* context) { | |
248
1ede5390cda2
Fix segmentation fault but not multi thread running
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
247
diff
changeset
|
35 CPUWorker* cpuWorker = (CPUWorker *)GearImpl(context, Worker, worker); |
1ede5390cda2
Fix segmentation fault but not multi thread running
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
247
diff
changeset
|
36 pthread_cond_wait(&cpuWorker->cond, &cpuWorker->mutex); |
247
ce262b2c1daf
Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
244
diff
changeset
|
37 goto taskReceiveWorker(context, &Gearef(context, Worker)->worker->Worker, Gearef(context, Queue)); |
222
77faa28128b4
Add taskSend for TaskManager
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
217
diff
changeset
|
38 } |
77faa28128b4
Add taskSend for TaskManager
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
217
diff
changeset
|
39 |
248
1ede5390cda2
Fix segmentation fault but not multi thread running
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
247
diff
changeset
|
40 __code getTask(struct Context* context, Worker* worker, struct Context* task) { |
240 | 41 if (!task) |
236 | 42 return; // end thread |
230 | 43 task->worker = worker; |
248
1ede5390cda2
Fix segmentation fault but not multi thread running
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
247
diff
changeset
|
44 context->next = C_taskReceiveWorker; // set CG after task exec |
230 | 45 goto meta(task, task->next); |
169
ea7b11f3e717
Using Queue Interface
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
149
diff
changeset
|
46 } |
109
059b26a250cc
Change put_queue process
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
103
diff
changeset
|
47 |
248
1ede5390cda2
Fix segmentation fault but not multi thread running
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
247
diff
changeset
|
48 __code getTask_stub(struct Context* context) { |
247
ce262b2c1daf
Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
244
diff
changeset
|
49 Worker* worker = &Gearef(context,Worker)->worker->Worker; |
ce262b2c1daf
Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
244
diff
changeset
|
50 Context* task = &Gearef(context, Queue)->data->context; |
248
1ede5390cda2
Fix segmentation fault but not multi thread running
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
247
diff
changeset
|
51 goto getTask(context, worker, task); |
95
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
52 } |
101 | 53 |
54 #ifdef USE_CUDA | |
98 | 55 __code twiceGpu(struct Context* context) { |
56 cuMemcpyHtoDAsync(context,context,context,context->stream); | |
57 cuLaunchkanel(); | |
58 cuMemcpyDtoHAsync(); | |
59 } | |
101 | 60 #endif |
227 | 61 |
232 | 62 __code shutdownWorker(struct Context* context, CPUWorker* worker) { |
230 | 63 } |
227 | 64 |
230 | 65 __code shutdownWorker_stub(struct Context* context) { |
232 | 66 CPUWorker* worker = (CPUWorker *)GearImpl(context, Worker, worker); |
230 | 67 goto shutdownWorker(context,worker); |
227 | 68 } |