annotate src/parallel_execution/CPUWorker.cbc @ 278:23767f714f4a

fix generate_stub
author mir3636
date Thu, 02 Feb 2017 20:27:56 +0900
parents 9d671e63df74
children 2c2e4e597eb0
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
277
9d671e63df74 generate extern
mir3636
parents: 272
diff changeset
7 Worker* createCPUWorker(struct Context* context, int id, Queue* queue, enum Code next) {
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;
mir3636
parents:
diff changeset
24 goto meta(cpuWorker->context, C_taskReceiveWorker);
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 CPUWorker* cpuWorker = (CPUWorker *)GearImpl(context, Worker, worker);
mir3636
parents:
diff changeset
35 pthread_cond_wait(&cpuWorker->cond, &cpuWorker->mutex);
mir3636
parents:
diff changeset
36 goto taskReceiveWorker(context, &Gearef(context, Worker)->worker->Worker, Gearef(context, Queue));
mir3636
parents:
diff changeset
37 }
mir3636
parents:
diff changeset
38
mir3636
parents:
diff changeset
39 __code getTask(struct Worker* worker, struct Context* task) {
mir3636
parents:
diff changeset
40 if (!task)
mir3636
parents:
diff changeset
41 return; // end thread
mir3636
parents:
diff changeset
42 task->worker = worker;
mir3636
parents:
diff changeset
43 context->next = C_taskReceiveWorker; // set CG after task exec
mir3636
parents:
diff changeset
44 goto meta(task, task->next);
mir3636
parents:
diff changeset
45 }
mir3636
parents:
diff changeset
46
mir3636
parents:
diff changeset
47 __code getTask_stub(struct Context* context) {
mir3636
parents:
diff changeset
48 Worker* worker = &Gearef(context,Worker)->worker->Worker;
mir3636
parents:
diff changeset
49 struct Context* task = &Gearef(context, Queue)->data->Context;
mir3636
parents:
diff changeset
50 goto getTask(context, worker, task);
mir3636
parents:
diff changeset
51 }
mir3636
parents:
diff changeset
52
mir3636
parents:
diff changeset
53 #ifdef USE_CUDA
mir3636
parents:
diff changeset
54 __code twiceGpu() {
mir3636
parents:
diff changeset
55 cuMemcpyHtoDAsync(context,context,context,context->stream);
mir3636
parents:
diff changeset
56 cuLaunchkanel();
mir3636
parents:
diff changeset
57 cuMemcpyDtoHAsync();
mir3636
parents:
diff changeset
58 }
mir3636
parents:
diff changeset
59 #endif
mir3636
parents:
diff changeset
60
mir3636
parents:
diff changeset
61 __code shutdownWorker(struct CPUWorker* worker) {
mir3636
parents:
diff changeset
62 }
mir3636
parents:
diff changeset
63