annotate src/parallel_execution/CPUWorke.cbc @ 272:68cf983475e7

fix
author mir3636
date Mon, 30 Jan 2017 17:35:19 +0900
parents
children
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
mir3636
parents:
diff changeset
3 #include "context.h"
mir3636
parents:
diff changeset
4 #include "origin_cs.h"
mir3636
parents:
diff changeset
5
mir3636
parents:
diff changeset
6 static void start_worker(Worker* worker);
mir3636
parents:
diff changeset
7
mir3636
parents:
diff changeset
8 Worker* createCPUWorker(struct Context* context, int id, Queue* queue) {
mir3636
parents:
diff changeset
9 struct Worker* worker = new Worker();
mir3636
parents:
diff changeset
10 struct CPUWorker* cpuWorker = new CPUWorker();
mir3636
parents:
diff changeset
11 worker->worker = (union Data*)cpuWorker;
mir3636
parents:
diff changeset
12 worker->tasks = queue;
mir3636
parents:
diff changeset
13 cpuWorker->id = id;
mir3636
parents:
diff changeset
14 worker->taskReceive = C_taskReceiveWorker;
mir3636
parents:
diff changeset
15 worker->shutdown = C_shutdownWorker;
mir3636
parents:
diff changeset
16 pthread_create(&worker->worker->CPUWorker.thread, NULL, (void*)&start_worker, worker);
mir3636
parents:
diff changeset
17 return worker;
mir3636
parents:
diff changeset
18 }
mir3636
parents:
diff changeset
19
mir3636
parents:
diff changeset
20 static void start_worker(Worker* worker) {
mir3636
parents:
diff changeset
21 CPUWorker* cpuWorker = (CPUWorker*)worker->worker;
mir3636
parents:
diff changeset
22 cpuWorker->context = NEW(struct Context);
mir3636
parents:
diff changeset
23 initContext(cpuWorker->context);
mir3636
parents:
diff changeset
24 Gearef(cpuWorker->context, Worker)->worker = (union Data*)worker;
mir3636
parents:
diff changeset
25 goto meta(cpuWorker->context, C_taskReceiveWorker);
mir3636
parents:
diff changeset
26 }
mir3636
parents:
diff changeset
27
mir3636
parents:
diff changeset
28 __code taskReceiveWorker(struct Worker* worker,struct Queue* queue) {
mir3636
parents:
diff changeset
29 queue->queue = (union Data*)worker->tasks;
mir3636
parents:
diff changeset
30 queue->next = C_getTask;
mir3636
parents:
diff changeset
31 goto meta(context, worker->tasks->take);
mir3636
parents:
diff changeset
32 }
mir3636
parents:
diff changeset
33
mir3636
parents:
diff changeset
34 __code taskReceiveWorker_stub(struct Context* context) {
mir3636
parents:
diff changeset
35 CPUWorker* cpuWorker = (CPUWorker *)GearImpl(context, Worker, worker);
mir3636
parents:
diff changeset
36 pthread_cond_wait(&cpuWorker->cond, &cpuWorker->mutex);
mir3636
parents:
diff changeset
37 goto taskReceiveWorker(context, &Gearef(context, Worker)->worker->Worker, Gearef(context, Queue));
mir3636
parents:
diff changeset
38 }
mir3636
parents:
diff changeset
39
mir3636
parents:
diff changeset
40 __code getTask(struct Worker* worker, struct Context* task) {
mir3636
parents:
diff changeset
41 if (!task)
mir3636
parents:
diff changeset
42 return; // end thread
mir3636
parents:
diff changeset
43 task->worker = worker;
mir3636
parents:
diff changeset
44 context->next = C_taskReceiveWorker; // set CG after task exec
mir3636
parents:
diff changeset
45 goto meta(task, task->next);
mir3636
parents:
diff changeset
46 }
mir3636
parents:
diff changeset
47
mir3636
parents:
diff changeset
48 __code getTask_stub(struct Context* context) {
mir3636
parents:
diff changeset
49 Worker* worker = &Gearef(context,Worker)->worker->Worker;
mir3636
parents:
diff changeset
50 struct Context* task = &Gearef(context, Queue)->data->Context;
mir3636
parents:
diff changeset
51 goto getTask(context, worker, task);
mir3636
parents:
diff changeset
52 }
mir3636
parents:
diff changeset
53
mir3636
parents:
diff changeset
54 #ifdef USE_CUDA
mir3636
parents:
diff changeset
55 __code twiceGpu() {
mir3636
parents:
diff changeset
56 cuMemcpyHtoDAsync(context,context,context,context->stream);
mir3636
parents:
diff changeset
57 cuLaunchkanel();
mir3636
parents:
diff changeset
58 cuMemcpyDtoHAsync();
mir3636
parents:
diff changeset
59 }
mir3636
parents:
diff changeset
60 #endif
mir3636
parents:
diff changeset
61
mir3636
parents:
diff changeset
62 __code shutdownWorker(struct CPUWorker* worker) {
mir3636
parents:
diff changeset
63 }
mir3636
parents:
diff changeset
64