annotate src/parallel_execution/worker.c @ 244:d1567718f12c

Fix error
author Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
date Wed, 25 Jan 2017 01:48:47 +0900
parents 9f3f8ed6ed9f
children ce262b2c1daf
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
05e61405cc88 fix worker compile error
mir3636
parents: 233
diff changeset
6 static void start_worker(Worker* worker);
233
06133afb3b5b create worker start_code
mir3636
parents: 232
diff changeset
7
236
865179a0a56d fix taskManager
ikkun
parents: 235
diff changeset
8 union Data* createCPUWorker(struct Context* context, int id, Queue* queue) {
233
06133afb3b5b create worker start_code
mir3636
parents: 232
diff changeset
9 struct Worker* worker = ALLOC(context, Worker);
06133afb3b5b create worker start_code
mir3636
parents: 232
diff changeset
10 struct CPUWorker* cpuWorker = ALLOC(context, CPUWorker);
232
123b0d277b84 worker interface
mir3636
parents: 230
diff changeset
11 worker->worker = (union Data*)cpuWorker;
244
d1567718f12c Fix error
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 242
diff changeset
12 worker->tasks = queue;
232
123b0d277b84 worker interface
mir3636
parents: 230
diff changeset
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
05e61405cc88 fix worker compile error
mir3636
parents: 233
diff changeset
16 pthread_create(&worker->worker->CPUWorker.thread, NULL, (void*)&start_worker, worker);
183
mir3636
parents: 175
diff changeset
17 return (union Data*)(worker);
mir3636
parents: 175
diff changeset
18 }
mir3636
parents: 175
diff changeset
19
235
05e61405cc88 fix worker compile error
mir3636
parents: 233
diff changeset
20 static void start_worker(Worker* worker) {
05e61405cc88 fix worker compile error
mir3636
parents: 233
diff changeset
21 CPUWorker* cpuWorker = (CPUWorker*)worker->worker;
05e61405cc88 fix worker compile error
mir3636
parents: 233
diff changeset
22 cpuWorker->context = NEW(struct Context);
05e61405cc88 fix worker compile error
mir3636
parents: 233
diff changeset
23 initContext(cpuWorker->context);
242
9f3f8ed6ed9f Add sendTask
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 240
diff changeset
24 pthread_cond_wait(&cpuWorker->cond, &cpuWorker->mutex);
235
05e61405cc88 fix worker compile error
mir3636
parents: 233
diff changeset
25 goto meta(cpuWorker->context, C_taskReceiveWorker);
233
06133afb3b5b create worker start_code
mir3636
parents: 232
diff changeset
26 }
06133afb3b5b create worker start_code
mir3636
parents: 232
diff changeset
27
244
d1567718f12c Fix error
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 242
diff changeset
28 __code taskReceiveWorker(struct Context* context, Worker* worker) {
230
a1fb3f2d1a36 fix worker
ikkun
parents: 227
diff changeset
29 Queue* queue = worker->tasks;
227
991f3d1ce072 fix worker
ikkun
parents: 222
diff changeset
30 queue->next = C_getTask1;
991f3d1ce072 fix worker
ikkun
parents: 222
diff changeset
31 goto meta(context, queue->take);
991f3d1ce072 fix worker
ikkun
parents: 222
diff changeset
32 }
991f3d1ce072 fix worker
ikkun
parents: 222
diff changeset
33
991f3d1ce072 fix worker
ikkun
parents: 222
diff changeset
34 __code taskReceiveWorker_stub(struct Context* context) {
244
d1567718f12c Fix error
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 242
diff changeset
35 goto taskReceiveWorker(context, Gearef(context, Worker));
222
77faa28128b4 Add taskSend for TaskManager
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 217
diff changeset
36 }
77faa28128b4 Add taskSend for TaskManager
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 217
diff changeset
37
230
a1fb3f2d1a36 fix worker
ikkun
parents: 227
diff changeset
38 __code getTask1(struct Context* context, Worker* worker, struct Context* task) {
240
864bb372f37f Add spawnTask1
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 237
diff changeset
39 if (!task)
236
865179a0a56d fix taskManager
ikkun
parents: 235
diff changeset
40 return; // end thread
230
a1fb3f2d1a36 fix worker
ikkun
parents: 227
diff changeset
41 task->worker = worker;
a1fb3f2d1a36 fix worker
ikkun
parents: 227
diff changeset
42 goto meta(task, task->next);
169
ea7b11f3e717 Using Queue Interface
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 149
diff changeset
43 }
109
059b26a250cc Change put_queue process
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 103
diff changeset
44
169
ea7b11f3e717 Using Queue Interface
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 149
diff changeset
45 __code getTask1_stub(struct Context* context) {
230
a1fb3f2d1a36 fix worker
ikkun
parents: 227
diff changeset
46 Worker* worker = Gearef(context,Worker);
244
d1567718f12c Fix error
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 242
diff changeset
47 Context* task = &worker->tasks->data->context;
230
a1fb3f2d1a36 fix worker
ikkun
parents: 227
diff changeset
48 goto getTask1(context,worker,task);
95
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 }
101
8987cf13d5bb Add Allocate macro
innparusu
parents: 98
diff changeset
50
8987cf13d5bb Add Allocate macro
innparusu
parents: 98
diff changeset
51 #ifdef USE_CUDA
98
d400948dbbab add Cuda infomation to context
ikkun
parents: 95
diff changeset
52 __code twiceGpu(struct Context* context) {
d400948dbbab add Cuda infomation to context
ikkun
parents: 95
diff changeset
53 cuMemcpyHtoDAsync(context,context,context,context->stream);
d400948dbbab add Cuda infomation to context
ikkun
parents: 95
diff changeset
54 cuLaunchkanel();
d400948dbbab add Cuda infomation to context
ikkun
parents: 95
diff changeset
55 cuMemcpyDtoHAsync();
d400948dbbab add Cuda infomation to context
ikkun
parents: 95
diff changeset
56 }
101
8987cf13d5bb Add Allocate macro
innparusu
parents: 98
diff changeset
57 #endif
227
991f3d1ce072 fix worker
ikkun
parents: 222
diff changeset
58
232
123b0d277b84 worker interface
mir3636
parents: 230
diff changeset
59 __code shutdownWorker(struct Context* context, CPUWorker* worker) {
230
a1fb3f2d1a36 fix worker
ikkun
parents: 227
diff changeset
60 }
227
991f3d1ce072 fix worker
ikkun
parents: 222
diff changeset
61
230
a1fb3f2d1a36 fix worker
ikkun
parents: 227
diff changeset
62 __code shutdownWorker_stub(struct Context* context) {
232
123b0d277b84 worker interface
mir3636
parents: 230
diff changeset
63 CPUWorker* worker = (CPUWorker *)GearImpl(context, Worker, worker);
230
a1fb3f2d1a36 fix worker
ikkun
parents: 227
diff changeset
64 goto shutdownWorker(context,worker);
227
991f3d1ce072 fix worker
ikkun
parents: 222
diff changeset
65 }