Mercurial > hg > Gears > GearsAgda
changeset 272:68cf983475e7
fix
author | mir3636 |
---|---|
date | Mon, 30 Jan 2017 17:35:19 +0900 |
parents | f2dd6356eff2 |
children | 08d0f920dad2 |
files | src/parallel_execution/CPUWorke.c src/parallel_execution/CPUWorke.cbc src/parallel_execution/SingleLinkedQueue.cbc |
diffstat | 3 files changed, 65 insertions(+), 74 deletions(-) [+] |
line wrap: on
line diff
--- a/src/parallel_execution/CPUWorke.c Mon Jan 30 15:02:08 2017 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,73 +0,0 @@ -#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 = &ALLOCATE(context, Worker)->Worker; - struct CPUWorker* cpuWorker = &ALLOCATE(context, CPUWorker)->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(context, meta); -} - -__code taskReceiveWorker(struct Context *context,struct Worker* worker,struct Queue* queue) { - queue->queue = (union Data*)worker->tasks; - queue->next = C_getTask; - goto meta(context, meta); -} - -__code taskReceiveWorker_stub(struct Context* context) { - CPUWorker* cpuWorker = (CPUWorker *)GearImpl(context, Worker, worker); - pthread_cond_wait(&cpuWorker->cond, &cpuWorker->mutex); - goto meta(context, taskReceiveWorker); -} - -__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(context, meta); -} - -__code getTask_stub(struct Context* context) { - Worker* worker = &Gearef(context,Worker)->worker->Worker; - struct Context* task = &Gearef(context, Queue)->data->Context; - goto meta(context, getTask); -} - -#ifdef USE_CUDA -__code twiceGpu(struct Context *context,struct Context* context) { - cuMemcpyHtoDAsync(context,context,context,context->stream); - cuLaunchkanel(); - cuMemcpyDtoHAsync(); -} -#endif - -__code twiceGpu_stub (struct Context* context) { - Context* context = Gearef(context, Context); - goto twiceGpu(context, context); -} - -__code shutdownWorker(struct Context *context,struct CPUWorker* worker) { -} -__code shutdownWorker_stub (struct Context* context) { - CPUWorker* worker = (CPUWorker*)GearImpl(context, Worker, worker); - goto shutdownWorker(context, worker); -} -
--- /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) { +} +
--- a/src/parallel_execution/SingleLinkedQueue.cbc Mon Jan 30 15:02:08 2017 +0900 +++ b/src/parallel_execution/SingleLinkedQueue.cbc Mon Jan 30 17:35:19 2017 +0900 @@ -50,7 +50,7 @@ goto next(...); } -__code takeSingleLinkedQueue(struct SingleLinkedQueue* queue, _code next(union Data* data, ...)) { +__code takeSingleLinkedQueue(struct SingleLinkedQueue* queue, __code next(union Data* data, ...)) { if (queue->top) { data = queue->top->data; queue->top = queue->top->next;