Mercurial > hg > Members > Moririn
annotate src/parallel_execution/CPUWorker.cbc @ 288:f1b0cc555b6e
Add odgCommit
author | Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 06 Feb 2017 04:04:25 +0900 |
parents | a3448b0f0a56 |
children | 3d70e21a3902 |
rev | line source |
---|---|
272 | 1 #include <libkern/OSAtomic.h> |
2 | |
278 | 3 #include "../context.h" |
272 | 4 |
5 static void start_worker(Worker* worker); | |
6 | |
280 | 7 Worker* createCPUWorker(struct Context* context, int id, Queue* queue) { |
272 | 8 struct Worker* worker = new Worker(); |
9 struct CPUWorker* cpuWorker = new CPUWorker(); | |
10 worker->worker = (union Data*)cpuWorker; | |
11 worker->tasks = queue; | |
12 cpuWorker->id = id; | |
13 worker->taskReceive = C_taskReceiveWorker; | |
14 worker->shutdown = C_shutdownWorker; | |
15 pthread_create(&worker->worker->CPUWorker.thread, NULL, (void*)&start_worker, worker); | |
16 return worker; | |
17 } | |
18 | |
19 static void start_worker(Worker* worker) { | |
20 CPUWorker* cpuWorker = (CPUWorker*)worker->worker; | |
21 cpuWorker->context = NEW(struct Context); | |
22 initContext(cpuWorker->context); | |
23 Gearef(cpuWorker->context, Worker)->worker = (union Data*)worker; | |
282
a3448b0f0a56
Add input data gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
280
diff
changeset
|
24 goto meta(cpuWorker->context, worker->taskReceive); |
272 | 25 } |
26 | |
27 __code taskReceiveWorker(struct Worker* worker,struct Queue* queue) { | |
28 queue->queue = (union Data*)worker->tasks; | |
29 queue->next = C_getTask; | |
30 goto meta(context, worker->tasks->take); | |
31 } | |
32 | |
33 __code taskReceiveWorker_stub(struct Context* context) { | |
34 goto taskReceiveWorker(context, &Gearef(context, Worker)->worker->Worker, Gearef(context, Queue)); | |
35 } | |
36 | |
37 __code getTask(struct Worker* worker, struct Context* task) { | |
38 if (!task) | |
39 return; // end thread | |
40 task->worker = worker; | |
288 | 41 task->next = C_odgCommit; // set CG after task exec |
272 | 42 goto meta(task, task->next); |
43 } | |
44 | |
45 __code getTask_stub(struct Context* context) { | |
46 Worker* worker = &Gearef(context,Worker)->worker->Worker; | |
47 struct Context* task = &Gearef(context, Queue)->data->Context; | |
48 goto getTask(context, worker, task); | |
49 } | |
50 | |
288 | 51 __code odgCommit(struct LoopCounter* loopCounter, struct Queue* queue, struct Context* task) { |
52 int i = loopCounter->i ; | |
53 if(task->odg + i < task->maxOdg) { | |
54 queue->queue = (union Data*)GET_WAIT_LIST(task->data[task->odg+i]); | |
55 queue->next = C_odgCommit1; | |
56 goto meta(context, queue->queue->Queue.take); | |
57 } | |
58 loopCounter->i = 0; | |
59 goto meta(context, C_taskReceiveWorker); | |
60 } | |
61 | |
62 __code odgCommit_stub(struct Context* context) { | |
63 struct Context* workerContext = context->worker->worker->CPUWorker.context; | |
64 goto odgCommit(workerContext, | |
65 Gearef(workerContext, LoopCounter), | |
66 Gearef(workerContext, Queue), | |
67 context); | |
68 } | |
69 | |
70 __code odgCommit1(struct TaskManager* taskManager, struct Context* task) { | |
71 if(__sync_fetch_and_sub(&task->idgCount, 1)) { | |
72 if(task->idgCount == 0) { | |
73 taskManager->taskManager = (union Data*)task->taskManager; | |
74 taskManager->context = task; | |
75 taskManager->next = C_odgCommit; | |
76 goto meta(context, task->taskManager->spawn); | |
77 } | |
78 } else { | |
79 goto meta(context, C_odgCommit1); | |
80 } | |
81 } | |
82 | |
83 __code odgCommit1_stub(struct Context* context) { | |
84 struct Context* task = &Gearef(context, Queue)->data->Context; | |
85 goto odgCommit1(context, | |
86 Gearef(context, TaskManager), | |
87 task); | |
88 | |
89 } | |
90 | |
272 | 91 #ifdef USE_CUDA |
92 __code twiceGpu() { | |
93 cuMemcpyHtoDAsync(context,context,context,context->stream); | |
94 cuLaunchkanel(); | |
95 cuMemcpyDtoHAsync(); | |
96 } | |
280 | 97 |
98 __code twiceGpu_stub() { | |
99 } | |
100 | |
272 | 101 #endif |
102 | |
103 __code shutdownWorker(struct CPUWorker* worker) { | |
104 } |