Mercurial > hg > Members > Moririn
diff src/parallel_execution/CPUWorke.cbc @ 272:68cf983475e7
fix
author | mir3636 |
---|---|
date | Mon, 30 Jan 2017 17:35:19 +0900 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/parallel_execution/CPUWorke.cbc Mon Jan 30 17:35:19 2017 +0900 @@ -0,0 +1,64 @@ +#include <libkern/OSAtomic.h> + +#include "context.h" +#include "origin_cs.h" + +static void start_worker(Worker* worker); + +Worker* createCPUWorker(struct Context* context, int id, Queue* queue) { + struct Worker* worker = new Worker(); + struct CPUWorker* cpuWorker = new CPUWorker(); + worker->worker = (union Data*)cpuWorker; + worker->tasks = queue; + cpuWorker->id = id; + worker->taskReceive = C_taskReceiveWorker; + worker->shutdown = C_shutdownWorker; + pthread_create(&worker->worker->CPUWorker.thread, NULL, (void*)&start_worker, worker); + return worker; +} + +static void start_worker(Worker* worker) { + CPUWorker* cpuWorker = (CPUWorker*)worker->worker; + cpuWorker->context = NEW(struct Context); + initContext(cpuWorker->context); + Gearef(cpuWorker->context, Worker)->worker = (union Data*)worker; + goto meta(cpuWorker->context, C_taskReceiveWorker); +} + +__code taskReceiveWorker(struct Worker* worker,struct Queue* queue) { + queue->queue = (union Data*)worker->tasks; + queue->next = C_getTask; + goto meta(context, worker->tasks->take); +} + +__code taskReceiveWorker_stub(struct Context* context) { + CPUWorker* cpuWorker = (CPUWorker *)GearImpl(context, Worker, worker); + pthread_cond_wait(&cpuWorker->cond, &cpuWorker->mutex); + goto taskReceiveWorker(context, &Gearef(context, Worker)->worker->Worker, Gearef(context, Queue)); +} + +__code getTask(struct Worker* worker, struct Context* task) { + if (!task) + return; // end thread + task->worker = worker; + context->next = C_taskReceiveWorker; // set CG after task exec + goto meta(task, task->next); +} + +__code getTask_stub(struct Context* context) { + Worker* worker = &Gearef(context,Worker)->worker->Worker; + struct Context* task = &Gearef(context, Queue)->data->Context; + goto getTask(context, worker, task); +} + +#ifdef USE_CUDA +__code twiceGpu() { + cuMemcpyHtoDAsync(context,context,context,context->stream); + cuLaunchkanel(); + cuMemcpyDtoHAsync(); +} +#endif + +__code shutdownWorker(struct CPUWorker* worker) { +} +