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