Mercurial > hg > Members > Moririn
changeset 461:6b71cf5b1c22
Change Interface files from cbc to header
author | Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 20 Dec 2017 17:54:15 +0900 |
parents | 57c715bd6283 |
children | 8d7e5d48cad3 |
files | src/parallel_execution/Atomic.cbc src/parallel_execution/Atomic.h src/parallel_execution/CodeGear.cbc src/parallel_execution/CodeGear.h src/parallel_execution/Executor.cbc src/parallel_execution/Executor.h src/parallel_execution/Iterator.cbc src/parallel_execution/Iterator.h src/parallel_execution/MultiDimIterator.cbc src/parallel_execution/Queue.cbc src/parallel_execution/Queue.h src/parallel_execution/Semaphore.cbc src/parallel_execution/Semaphore.h src/parallel_execution/Stack.cbc src/parallel_execution/Stack.h src/parallel_execution/TaskManager.cbc src/parallel_execution/TaskManager.h src/parallel_execution/TaskManagerImpl.cbc src/parallel_execution/Time.cbc src/parallel_execution/Time.h src/parallel_execution/Tree.cbc src/parallel_execution/Tree.h src/parallel_execution/Worker.cbc src/parallel_execution/Worker.h src/parallel_execution/context.h src/parallel_execution/generate_stub.pl |
diffstat | 26 files changed, 322 insertions(+), 349 deletions(-) [+] |
line wrap: on
line diff
--- a/src/parallel_execution/Atomic.cbc Sat Dec 16 06:04:32 2017 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,9 +0,0 @@ -typedef struct Atomic<Impl>{ - union Data* atomic; - union Data** ptr; - union Data* oldData; - union Data* newData; - __code checkAndSet(Impl* atomic, union Data** ptr, union Data* oldData, union Data* newData, __code next(...), __code fail(...)); - __code next(...); - __code fail(...); -} Atomic;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/parallel_execution/Atomic.h Wed Dec 20 17:54:15 2017 +0900 @@ -0,0 +1,9 @@ +typedef struct Atomic<Impl>{ + union Data* atomic; + union Data** ptr; + union Data* oldData; + union Data* newData; + __code checkAndSet(Impl* atomic, union Data** ptr, union Data* oldData, union Data* newData, __code next(...), __code fail(...)); + __code next(...); + __code fail(...); +} Atomic;
--- a/src/parallel_execution/CodeGear.cbc Sat Dec 16 06:04:32 2017 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,8 +0,0 @@ -typedef struct CodeGear<Impl>{ - union Data* codeGear; - enum Code code; - __code code(struct Integer* input1, struct Integer* input2, __code next(struct Integer* output, ...)); - __code setInfo(struct Context* codeGear, union Data** dataGears, __code next(...)); - union Data* dataGears[10]; - __code next(...); -} CodeGear;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/parallel_execution/CodeGear.h Wed Dec 20 17:54:15 2017 +0900 @@ -0,0 +1,8 @@ +typedef struct CodeGear<Impl>{ + union Data* codeGear; + enum Code code; + __code code(struct Integer* input1, struct Integer* input2, __code next(struct Integer* output, ...)); + __code setInfo(struct Context* codeGear, union Data** dataGears, __code next(...)); + union Data* dataGears[10]; + __code next(...); +} CodeGear;
--- a/src/parallel_execution/Executor.cbc Sat Dec 16 06:04:32 2017 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,7 +0,0 @@ -typedef struct Executor<Type, Impl>{ - Type* Executor; - struct Context* task; - __code read(Impl* executor, struct Context* task, __code next(...)); - __code exec(Impl* executor, struct Context* task, __code next(...)); - __code write(Impl* executor, struct Context* task, __code next(...)); -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/parallel_execution/Executor.h Wed Dec 20 17:54:15 2017 +0900 @@ -0,0 +1,7 @@ +typedef struct Executor<Type, Impl>{ + Type* Executor; + struct Context* task; + __code read(Impl* executor, struct Context* task, __code next(...)); + __code exec(Impl* executor, struct Context* task, __code next(...)); + __code write(Impl* executor, struct Context* task, __code next(...)); +}
--- a/src/parallel_execution/Iterator.cbc Sat Dec 16 06:04:32 2017 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,9 +0,0 @@ -typedef struct Iterator<Impl>{ - union Data* iterator; - struct Context* task; - int numGPU; - __code exec(Impl* iterator, struct TaskManager* taskManager, struct Context* task, int numGPU, __code next(...)); - __code barrier(Impl* iterator, struct Context* task, __code next(...), __code whenWait(...)); - __code whenWait(...); - __code next(...); -} Iterator;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/parallel_execution/Iterator.h Wed Dec 20 17:54:15 2017 +0900 @@ -0,0 +1,9 @@ +typedef struct Iterator<Impl>{ + union Data* iterator; + struct Context* task; + int numGPU; + __code exec(Impl* iterator, struct Context* task, int numGPU, __code next(...)); + __code barrier(Impl* iterator, struct Context* task, __code next(...), __code whenWait(...)); + __code whenWait(...); + __code next(...); +} Iterator;
--- a/src/parallel_execution/MultiDimIterator.cbc Sat Dec 16 06:04:32 2017 +0900 +++ b/src/parallel_execution/MultiDimIterator.cbc Wed Dec 20 17:54:15 2017 +0900 @@ -52,45 +52,39 @@ return task1; } -__code execMultiDimIterator(struct MultiDimIterator* iterator, struct TaskManager* taskManager, struct Context* task, int numGPU, __code next(...)) { +__code execMultiDimIterator(struct MultiDimIterator* iterator, struct Context* task, int numGPU, __code next(...)) { // No GPU device if (numGPU == 0) { goto meta(context, C_execMultiDimIterator1); } task->iterate = 1; task->gpu = 1; - taskManager->taskManager = (union Data*)task->taskManager; - taskManager->task = task; - taskManager->next = next; - goto meta(context, task->taskManager->spawn); + struct TaskManager* taskManager = task->taskManager; + goto taskManager->spawn(task, next(...)); } __code execMultiDimIterator_stub(struct Context* context) { MultiDimIterator* iterator = (MultiDimIterator*)GearImpl(context, Iterator, iterator); - TaskManager* taskManager = Gearef(context, TaskManager); Context* task = Gearef(context, Iterator)->task; int numGPU = Gearef(context, Iterator)->numGPU; enum Code next = Gearef(context, Iterator)->next; - goto execMultiDimIterator(context, iterator, taskManager, task, numGPU, next); + goto execMultiDimIterator(context, iterator, task, numGPU, next); } -__code execMultiDimIterator1(struct MultiDimIterator* iterator, struct TaskManager* taskManager, struct Context* task, __code next(...)) { +__code execMultiDimIterator1(struct MultiDimIterator* iterator, struct Context* task, __code next(...)) { int x = iterator->counterX; int y = iterator->counterY; int z = iterator->counterZ; struct Context* iterateTask = createMultiDimIterateTask(task, x, y, z); - taskManager->taskManager = (union Data*)task->taskManager; - taskManager->task = iterateTask; - taskManager->next = C_execMultiDimIterator2; - goto meta(context, task->taskManager->spawn); + struct TaskManager* taskManager = task->taskManager; + goto taskManager->spawn(iterateTask, next(...)); } __code execMultiDimIterator1_stub(struct Context* context) { MultiDimIterator* iterator = (MultiDimIterator*)GearImpl(context, Iterator, iterator); - TaskManager* taskManager = Gearef(context, TaskManager); Context* task = Gearef(context, Iterator)->task; enum Code next = Gearef(context, Iterator)->next; - goto execMultiDimIterator1(context, iterator, taskManager, task, next); + goto execMultiDimIterator1(context, iterator, task, next); } __code execMultiDimIterator2(struct MultiDimIterator* iterator, struct Context* task, __code next(...)) {
--- a/src/parallel_execution/Queue.cbc Sat Dec 16 06:04:32 2017 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,10 +0,0 @@ -typedef struct Queue<Impl>{ - union Data* queue; - union Data* data; - __code whenEmpty(...); - __code clear(Impl* queue, __code next(...)); - __code put(Impl* queue, union Data* data, __code next(...)); - __code take(Impl* queue, __code next(union Data*, ...)); - __code isEmpty(Impl* queue, __code next(...), __code whenEmpty(...)); - __code next(...); -} Queue;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/parallel_execution/Queue.h Wed Dec 20 17:54:15 2017 +0900 @@ -0,0 +1,10 @@ +typedef struct Queue<Impl>{ + union Data* queue; + union Data* data; + __code whenEmpty(...); + __code clear(Impl* queue, __code next(...)); + __code put(Impl* queue, union Data* data, __code next(...)); + __code take(Impl* queue, __code next(union Data*, ...)); + __code isEmpty(Impl* queue, __code next(...), __code whenEmpty(...)); + __code next(...); +} Queue;
--- a/src/parallel_execution/Semaphore.cbc Sat Dec 16 06:04:32 2017 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,6 +0,0 @@ -typedef struct Semaphore<Impl>{ - union Data* semaphore; - __code p(Impl* semaphore, __code next(...)); - __code v(Impl* semaphore, __code next(...)); - __code next(...); -} Semaphore;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/parallel_execution/Semaphore.h Wed Dec 20 17:54:15 2017 +0900 @@ -0,0 +1,6 @@ +typedef struct Semaphore<Impl>{ + union Data* semaphore; + __code p(Impl* semaphore, __code next(...)); + __code v(Impl* semaphore, __code next(...)); + __code next(...); +} Semaphore;
--- a/src/parallel_execution/Stack.cbc Sat Dec 16 06:04:32 2017 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,17 +0,0 @@ -typedef struct Stack<Type, Impl>{ - union Data* stack; - union Data* data; - union Data* data1; - /* Type* stack; */ - /* Type* data; */ - /* Type* data1; */ - __code whenEmpty(...); - __code clear(Impl* stack,__code next(...)); - __code push(Impl* stack,Type* data, __code next(...)); - __code pop(Impl* stack, __code next(Type* data, ...)); - __code pop2(Impl* stack, __code next(Type* data, Type* data1, ...)); - __code isEmpty(Impl* stack, __code next(...), __code whenEmpty(...)); - __code get(Impl* stack, __code next(Type* data, ...)); - __code get2(Impl* stack, __code next(Type* data, Type* data1, ...)); - __code next(...); -} Stack;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/parallel_execution/Stack.h Wed Dec 20 17:54:15 2017 +0900 @@ -0,0 +1,17 @@ +typedef struct Stack<Type, Impl>{ + union Data* stack; + union Data* data; + union Data* data1; + /* Type* stack; */ + /* Type* data; */ + /* Type* data1; */ + __code whenEmpty(...); + __code clear(Impl* stack,__code next(...)); + __code push(Impl* stack,Type* data, __code next(...)); + __code pop(Impl* stack, __code next(Type* data, ...)); + __code pop2(Impl* stack, __code next(Type* data, Type* data1, ...)); + __code isEmpty(Impl* stack, __code next(...), __code whenEmpty(...)); + __code get(Impl* stack, __code next(Type* data, ...)); + __code get2(Impl* stack, __code next(Type* data, Type* data1, ...)); + __code next(...); +} Stack;
--- a/src/parallel_execution/TaskManager.cbc Sat Dec 16 06:04:32 2017 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,18 +0,0 @@ -typedef struct TaskManager<Impl>{ - union Data* taskManager; - struct Context* task; - struct Context** tasks; - __code spawn(Impl* taskManager, struct Queue* queue, struct Context* task, __code next(...)); - __code spawnTasks(Impl* taskManagerImpl, struct Context** tasks, __code next1(...), struct TaskManager* taskManager); - __code setWaitTask(Impl* taskManagerImpl, struct Context* task, __code next(...)); - __code shutdown(Impl* taskManagerImpl, __code next(...), struct TaskManager* taskManager, struct Queue* queue); - __code incrementTaskCount(Impl* taskManagerImpl, __code next(...)); - __code decrementTaskCount(Impl* taskManagerImpl, __code next(...)); - __code next(...); - __code next1(...); - int worker; - int cpu; - int gpu; - int io; - int maxCPU; -} TaskManager;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/parallel_execution/TaskManager.h Wed Dec 20 17:54:15 2017 +0900 @@ -0,0 +1,13 @@ +typedef struct TaskManager<Impl>{ + union Data* taskManager; + struct Context* task; + struct Context** tasks; + __code spawn(Impl* taskManager, struct Context* task, __code next(...)); + __code spawnTasks(Impl* taskManagerImpl, struct Context** tasks, __code next1(...)); + __code setWaitTask(Impl* taskManagerImpl, struct Context* task, __code next(...)); + __code shutdown(Impl* taskManagerImpl, __code next(...)); + __code incrementTaskCount(Impl* taskManagerImpl, __code next(...)); + __code decrementTaskCount(Impl* taskManagerImpl, __code next(...)); + __code next(...); + __code next1(...); +} TaskManager;
--- a/src/parallel_execution/TaskManagerImpl.cbc Sat Dec 16 06:04:32 2017 +0900 +++ b/src/parallel_execution/TaskManagerImpl.cbc Wed Dec 20 17:54:15 2017 +0900 @@ -1,19 +1,16 @@ #include "../context.h" +#include "./TaskManager.h" +#include "./Iterator.h" +#include "./Queue.h" +#include "./Worker.h" #include <stdio.h> #include <unistd.h> -void createWorkers(struct Context* context, TaskManager* taskManeger, TaskManagerImpl* taskManagerImpl); +void createWorkers(struct Context* context, TaskManagerImpl* taskManager); TaskManager* createTaskManagerImpl(struct Context* context, int numCPU, int numGPU, int numIO) { struct TaskManager* taskManager = new TaskManager(); - // 0...numIO-1 IOProcessor - // numIO...numIO+numGPU-1 GPUProcessor - // numIO+numGPU...numIO+numGPU+numCPU-1 CPUProcessor - taskManager->io = 0; - taskManager->gpu = numIO; - taskManager->cpu = numIO+numGPU; - taskManager->maxCPU = numIO+numGPU+numCPU; taskManager->spawnTasks = C_spawnTasksTaskManagerImpl; taskManager->spawn = C_spawnTaskManagerImpl; taskManager->shutdown = C_shutdownTaskManagerImpl; @@ -21,36 +18,43 @@ taskManager->decrementTaskCount = C_decrementTaskCountTaskManagerImpl; taskManager->setWaitTask = C_setWaitTaskTaskManagerImpl; struct TaskManagerImpl* taskManagerImpl = new TaskManagerImpl(); + // 0...numIO-1 IOProcessor + // numIO...numIO+numGPU-1 GPUProcessor + // numIO+numGPU...numIO+numGPU+numCPU-1 CPUProcessor + taskManagerImpl->io = 0; + taskManagerImpl->gpu = numIO; + taskManagerImpl->cpu = numIO+numGPU; + taskManagerImpl->maxCPU = numIO+numGPU+numCPU; taskManagerImpl->taskQueue = createSingleLinkedQueue(context); - taskManagerImpl->numWorker = taskManager->maxCPU; - taskManagerImpl->sendGPUWorkerIndex = taskManager->gpu; - taskManagerImpl->sendCPUWorkerIndex = taskManager->cpu; + taskManagerImpl->numWorker = taskManagerImpl->maxCPU; + taskManagerImpl->sendGPUWorkerIndex = taskManagerImpl->gpu; + taskManagerImpl->sendCPUWorkerIndex = taskManagerImpl->cpu; taskManagerImpl->taskCount = 0; taskManagerImpl->loopCounter = new LoopCounter(); taskManagerImpl->loopCounter -> i = 0; - createWorkers(context, taskManager, taskManagerImpl); + createWorkers(context, taskManagerImpl); taskManager->taskManager = (union Data*)taskManagerImpl; return taskManager; } -void createWorkers(struct Context* context, TaskManager* taskManager, TaskManagerImpl* taskManagerImpl) { +void createWorkers(struct Context* context, TaskManagerImpl* taskManager) { int i = 0; - taskManagerImpl->workers = (Worker**)ALLOCATE_PTR_ARRAY(context, Worker, taskManager->maxCPU); + taskManager->workers = (Worker**)ALLOCATE_PTR_ARRAY(context, Worker, taskManager->maxCPU); for (;i<taskManager->gpu;i++) { Queue* queue = createSynchronizedQueue(context); - taskManagerImpl->workers[i] = (Worker*)createCPUWorker(context, i, queue); + taskManager->workers[i] = (Worker*)createCPUWorker(context, i, queue); } for (;i<taskManager->cpu;i++) { Queue* queue = createSynchronizedQueue(context); #ifdef USE_CUDAWorker - taskManagerImpl->workers[i] = (Worker*)createCUDAWorker(context, i, queue,0); + taskManager->workers[i] = (Worker*)createCUDAWorker(context, i, queue,0); #else - taskManagerImpl->workers[i] = (Worker*)createCPUWorker(context, i, queue); + taskManager->workers[i] = (Worker*)createCPUWorker(context, i, queue); #endif } for (;i<taskManager->maxCPU;i++) { Queue* queue = createSynchronizedQueue(context); - taskManagerImpl->workers[i] = (Worker*)createCPUWorker(context, i, queue); + taskManager->workers[i] = (Worker*)createCPUWorker(context, i, queue); } } @@ -74,19 +78,17 @@ Queue* tasks = Gearef(context, TaskManager)->tasks; enum Code next1 = Gearef(context, TaskManager)->next1; goto spawnTasksTaskManagerImpl1(context, taskManager, tasks, next1); -} +} __code spawnTasksTaskManagerImpl2(struct TaskManagerImpl* taskManagerImpl, struct Context* task, struct TaskManager* taskManager) { - task->taskManager = &taskManager->taskManager->TaskManager; - taskManager->task = task; - taskManager->next = C_spawnTasksTaskManagerImpl; - goto meta(context, C_setWaitTaskTaskManagerImpl); + task->taskManager = taskManager; + goto taskManager->setWaitTask(task, spawnTasksTaskManagerImpl); } __code spawnTasksTaskManagerImpl2_stub(struct Context* context) { TaskManagerImpl* taskManagerImpl = (TaskManagerImpl*)GearImpl(context, TaskManager, taskManager); Context* task = (struct Context*)Gearef(context, Queue)->data; - TaskManager* taskManager = Gearef(context, TaskManager); + TaskManager* taskManager = &Gearef(context, TaskManager)->taskManager->TaskManager; goto spawnTasksTaskManagerImpl2(context, taskManagerImpl, task, taskManager); } @@ -111,7 +113,7 @@ Context* task = (struct Context*)Gearef(context, Queue)->data; TaskManager* taskManager = Gearef(context, TaskManager); goto spawnTasksTaskManagerImpl5(context, taskManagerImpl, task, taskManager); -} +} __code setWaitTaskTaskManagerImpl(struct TaskManagerImpl* taskManager, struct Context* task, __code next(...)) { int i = taskManager->loopCounter->i; @@ -129,9 +131,9 @@ TaskManagerImpl* taskManager = (TaskManagerImpl*)GearImpl(context, TaskManager, taskManager); struct Context* task = Gearef(context, TaskManager)->task; goto setWaitTaskTaskManagerImpl(context, - taskManager, - task, - Gearef(context, TaskManager)->next); + taskManager, + task, + Gearef(context, TaskManager)->next); } __code incrementTaskCountTaskManagerImpl(struct TaskManagerImpl* taskManager, __code next(...)) { @@ -144,65 +146,47 @@ goto next(...); } -__code spawnTaskManagerImpl(struct TaskManagerImpl* taskManagerImpl, struct Iterator* iterator, struct TaskManager* taskManager, struct Context* task, __code next(...)) { +__code spawnTaskManagerImpl(struct TaskManagerImpl* taskManager, struct Context* task, __code next(...)) { if (task->idgCount == 0) { + // iterator task is normal task until spawned if(task->iterator != NULL && task->iterate == 0) { - iterator->iterator = (union Data*)task->iterator; - iterator->task = task; - iterator->next = next; - iterator->numGPU = taskManager->cpu - taskManager->gpu; - pthread_mutex_unlock(&taskManagerImpl->mutex); - goto meta(context, task->iterator->exec); + pthread_mutex_unlock(&taskManager->mutex); + struct Iterator* iterator = task->iterator; + goto iterator->exec(task, taskManager->cpu - taskManager->gpu, next(...)); } goto meta(context, C_taskSend); } - pthread_mutex_unlock(&taskManagerImpl->mutex); + pthread_mutex_unlock(&taskManager->mutex); goto next(...); } -__code spawnTaskManagerImpl_stub(struct Context* context) { - TaskManagerImpl* taskManager = (TaskManagerImpl*)GearImpl(context, TaskManager, taskManager); - pthread_mutex_lock(&taskManager->mutex); - goto spawnTaskManagerImpl(context, - taskManager, - Gearef(context, Iterator), - &Gearef(context, TaskManager)->taskManager->TaskManager, - Gearef(context, TaskManager)->task, - Gearef(context, TaskManager)->next); -} - -__code taskSend(struct TaskManagerImpl* taskManagerImpl, struct Queue* queue, struct TaskManager* taskManager, struct Context* task, __code next(...)) { +__code taskSend(struct TaskManagerImpl* taskManager, struct Context* task, __code next(...)) { // set workerId if (task->gpu) { - task->workerId = taskManagerImpl->sendGPUWorkerIndex; - if(++taskManagerImpl->sendGPUWorkerIndex >= taskManager->cpu) { - taskManagerImpl->sendGPUWorkerIndex = taskManager->gpu; + task->workerId = taskManager->sendGPUWorkerIndex; + if(++taskManager->sendGPUWorkerIndex >= taskManager->cpu) { + taskManager->sendGPUWorkerIndex = taskManager->gpu; } } else { - task->workerId = taskManagerImpl->sendCPUWorkerIndex; - if(++taskManagerImpl->sendCPUWorkerIndex >= taskManager->maxCPU) { - taskManagerImpl->sendCPUWorkerIndex = taskManager->cpu; + task->workerId = taskManager->sendCPUWorkerIndex; + if(++taskManager->sendCPUWorkerIndex >= taskManager->maxCPU) { + taskManager->sendCPUWorkerIndex = taskManager->cpu; } } - struct Queue* tasks = taskManagerImpl->workers[task->workerId]->tasks; - queue->queue = (union Data*)tasks; - queue->data = (union Data*)task; - queue->next = next; - pthread_mutex_unlock(&taskManagerImpl->mutex); - goto meta(context, tasks->put); + pthread_mutex_unlock(&taskManager->mutex); + struct Queue* queue = taskManager->workers[task->workerId]->tasks; + goto queue->put(task, next(...)); } __code taskSend_stub(struct Context* context) { TaskManagerImpl* taskManager = (TaskManagerImpl*)GearImpl(context, TaskManager, taskManager); goto taskSend(context, - taskManager, - Gearef(context, Queue), - &Gearef(context, TaskManager)->taskManager->TaskManager, - Gearef(context, TaskManager)->task, - Gearef(context, TaskManager)->next); + taskManager, + Gearef(context, TaskManager)->task, + Gearef(context, TaskManager)->next); } -__code shutdownTaskManagerImpl(struct TaskManagerImpl* taskManager, __code next(...), struct Queue* queue) { +__code shutdownTaskManagerImpl(struct TaskManagerImpl* taskManager, __code next(...)) { if (taskManager->taskCount != 0) { usleep(1000); goto meta(context, C_shutdownTaskManagerImpl); @@ -210,10 +194,7 @@ int i = taskManager->loopCounter->i; if (i < taskManager->numWorker) { struct Queue* tasks = taskManager->workers[i]->tasks; - queue->queue = (union Data*)tasks; - queue->data = NULL; - queue->next = C_shutdownTaskManagerImpl1; - goto meta(context, tasks->put); + goto tasks->put(NULL, shutdownTaskManagerImpl1); } taskManager->loopCounter->i = 0; @@ -223,9 +204,8 @@ __code shutdownTaskManagerImpl_stub(struct Context* context) { TaskManagerImpl* taskManagerImpl = (TaskManagerImpl*)GearImpl(context, TaskManager, taskManager); goto shutdownTaskManagerImpl(context, - taskManagerImpl, - Gearef(context, TaskManager)->next, - Gearef(context, Queue)); + taskManagerImpl, + Gearef(context, TaskManager)->next); } __code shutdownTaskManagerImpl1(TaskManagerImpl* taskManager) {
--- a/src/parallel_execution/Time.cbc Sat Dec 16 06:04:32 2017 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,7 +0,0 @@ -typedef struct Time<Impl>{ - union Data* time; - __code start(Impl* time, __code next(...)); - __code end(Impl* time, __code next(...)); - __code next(...); -} Queue; -
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/parallel_execution/Time.h Wed Dec 20 17:54:15 2017 +0900 @@ -0,0 +1,7 @@ +typedef struct Time<Impl>{ + union Data* time; + __code start(Impl* time, __code next(...)); + __code end(Impl* time, __code next(...)); + __code next(...); +} Queue; +
--- a/src/parallel_execution/Tree.cbc Sat Dec 16 06:04:32 2017 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,12 +0,0 @@ -typedef struct Tree<Type, Impl>{ - /* future Code */ - /* Type* tree; */ - /* Type* node; */ - union Data* tree; - struct Node* node; - __code put(Impl* tree,Type* node, __code next(...)); - // __code get(Impl* tree, __code next(...)); - // __code removeRedBlackTree(); - // __code clearRedBlackTree(); - __code next(...); -} Tree;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/parallel_execution/Tree.h Wed Dec 20 17:54:15 2017 +0900 @@ -0,0 +1,12 @@ +typedef struct Tree<Type, Impl>{ + /* future Code */ + /* Type* tree; */ + /* Type* node; */ + union Data* tree; + struct Node* node; + __code put(Impl* tree,Type* node, __code next(...)); + // __code get(Impl* tree, __code next(...)); + // __code removeRedBlackTree(); + // __code clearRedBlackTree(); + __code next(...); +} Tree;
--- a/src/parallel_execution/Worker.cbc Sat Dec 16 06:04:32 2017 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,7 +0,0 @@ -typedef struct Worker<Impl>{ - union Data* worker; - __code taskReseive(struct Worker* worker,struct Queue* queue); - __code shutdown(Impl* worker); - __code next(...); - struct Queue* queue; -} Worker;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/parallel_execution/Worker.h Wed Dec 20 17:54:15 2017 +0900 @@ -0,0 +1,7 @@ +typedef struct Worker<Impl>{ + union Data* worker; + __code taskReseive(struct Worker* worker,struct Queue* queue); + __code shutdown(Impl* worker); + __code next(...); + struct Queue* queue; +} Worker;
--- a/src/parallel_execution/context.h Sat Dec 16 06:04:32 2017 +0900 +++ b/src/parallel_execution/context.h Wed Dec 20 17:54:15 2017 +0900 @@ -155,11 +155,6 @@ struct Context* task; struct Queue* tasks; union Data* data; - int worker; - int cpu; - int gpu; - int io; - int maxCPU; } TaskManager; struct TaskManagerImpl { enum Code next; @@ -172,6 +167,10 @@ struct Queue* taskQueue; struct Worker** workers; struct LoopCounter* loopCounter; + int cpu; + int gpu; + int io; + int maxCPU; } TaskManagerImpl; struct Worker { union Data* worker;
--- a/src/parallel_execution/generate_stub.pl Sat Dec 16 06:04:32 2017 +0900 +++ b/src/parallel_execution/generate_stub.pl Wed Dec 20 17:54:15 2017 +0900 @@ -26,7 +26,7 @@ } } -for my $fn (@ARGV) { +for my $fn (@ARGV) { next if ($fn !~ /\.cbc$/); &getDataGear($fn); &generateDataGear($fn); @@ -95,19 +95,13 @@ $generic{$name} = []; } elsif (/^(\w+)(\*)+ create(\w+)\(/) { if (defined $interface) { - die "duplicate interface $interface\n"; + die "duplicate interface $interface\n"; } $interface = $1; $implementation = $3; if ( -f "$interface.cbc") { &getDataGear("$interface.cbc"); } - } elsif (/\s*\=\s*(.*)create(\w+)\((.*)\);$/) { - #my $intfn = ucfirst($2); - my $impln = $2; - if ( -f "$impln.cbc") { - &getCodeGear("$impln.cbc"); - } } elsif(/^(.*)par goto (\w+)\((.*)\)/) { my $codeGearName = $2; if ($filename =~ /^(.*)\/(.*)/) { @@ -116,6 +110,14 @@ if ( -f "$codeGearName.cbc") { &getCodeGear("$codeGearName.cbc"); } + } elsif(/^#include "(.*)"/) { + # interface include + my $interfaceHeader = $1; + next if ($interfaceHeader =~ /context.h/); + if (-f $interfaceHeader) { + &getDataGear("$interfaceHeader"); + &getCodeGear("$interfaceHeader"); + } } next; } @@ -133,6 +135,7 @@ $inTypedef = 0; } } + } sub getCodeGear { @@ -143,26 +146,28 @@ if (/^(\w+)(\*)+ create(\w+)\(/) { $name = $1; $impln = $3; + } elsif(/^typedef struct (.*)<.*>\s*{/) { + $name = $1; } if (defined $name) { - if (/^\_\_code (\w+)$impln\((.*)\)(.*)/) { + if (/^\s*\_\_code (\w+)\((.*)\);/) { my $args = $2; my $method = $1; $code{$name}->{$method} = []; while($args) { - if ($args =~ s/(^\s*,\s*)//) { - } + # replace comma + $args =~ s/(^\s*,\s*)//; # continuation case if ($args =~ s/^(\s)*\_\_code\s+(\w+)\(([^)]*)\)//) { my $next = $2; my @args = split(/,/,$3); - push(@{$code{$name}->{$method}},"\_\_code $next"); - } elsif ($args =~ s/^(struct|union) (\w+)(\*)+\s(\w+)//) { + push(@{$code{$name}->{$method}},"\_\_code $next"); + } elsif ($args =~ s/^(struct|union)?\s*(\w+)(\*)?+\s(\w+)//) { my $structType = $1; my $typeName = $2; my $varName = $4; my $typeField = lcfirst($typeName); - push(@{$code{$name}->{$method}},"$typeName $varName"); + push(@{$code{$name}->{$method}},"$typeName $varName"); } elsif ($args =~ s/(.*,)//) { } else { last; @@ -207,7 +212,7 @@ sub generateStubArgs { my($codeGearName, $varName, $typeName, $typeField, $interface,$output) = @_; - my $varname1 = $output?"O_$varName":$varName; + my $varname1 = $output?"O_$varName":$varName; for my $n ( @{$dataGearVar{$codeGearName}} ) { # we already have it return 0 if ( $n eq $varname1); @@ -219,7 +224,7 @@ $dataGearName{$codeGearName} .= "\t$typeName* $varName = ($typeName*)GearImpl(context, $interface, $varName);\n"; } else { for my $ivar (keys %{$var{$interface}}) { - # input data gear field + # input data gear field if ($varName eq $ivar) { if ($typeName eq $var{$interface}->{$ivar}) { if ($output) { @@ -358,7 +363,7 @@ $newArgs .= $&; # assuming no duplicate &generateStubArgs($codeGearName, $varName, $typeName, $typeField, $interface,0); } elsif ($args =~ s/(.*,)//) { - $newArgs .= $1; + $newArgs .= $1; } else { $newArgs .= $args; last; @@ -379,7 +384,7 @@ } next; } elsif (/^(.*)goto (\w+)\-\>(\w+)\((.*)\);/) { - # handling goto statement + # handling goto statement # convert it to the meta call form with two arugments, that is context and enum Code my $prev = $1; my $next = $2; @@ -418,7 +423,7 @@ } else { print $fd "\tGearef(context, $ntype)->$pName = C_$arg;\n"; } - } elsif ($pType =~ s/Data$//){ + } elsif ($pType =~ s/Data$//){ print $fd "\tGearef(context, $ntype)->$pName = (union Data*) $arg;\n"; } else { print $fd "\tGearef(context, $ntype)->$pName = $arg;\n"; @@ -432,141 +437,141 @@ # convert it to the parallel my $prev = $1; my $codeGearName = $2; - my $args = $3; + my $args = $3; my $inputCount = $codeGear{$codeGearName}->{'input'}; my $outputCount = $codeGear{$codeGearName}->{'output'}; my @iterateCounts; # parse examples 'par goto(.., iterate(10), exit);' - if ($args =~ /iterate\((.*)?\),/) { - @iterateCounts = split(/,/,$1);; - $inputCount--; - } - # replace iterate keyword - $args =~ s/iterate\((.*)?\),//; - my @dataGears = split(/,\s*/, $args); - my $nextCodeGear = pop(@dataGears); - if (! $inParGoto) { - $inParGoto = 1; - print $fd "${prev}struct Element* element;\n"; - } - my $initTask = << "EOFEOF"; - ${prev}context->task = NEW(struct Context); - ${prev}initContext(context->task); - ${prev}context->task->next = C_$codeGearName; - ${prev}context->task->idgCount = $inputCount; - ${prev}context->task->idg = context->task->dataNum; - ${prev}context->task->maxIdg = context->task->idg + $inputCount; - ${prev}context->task->odg = context->task->maxIdg; - ${prev}context->task->maxOdg = context->task->odg + $outputCount; + if ($args =~ /iterate\((.*)?\),/) { + @iterateCounts = split(/,/,$1);; + $inputCount--; + } + # replace iterate keyword + $args =~ s/iterate\((.*)?\),//; + my @dataGears = split(/,\s*/, $args); + my $nextCodeGear = pop(@dataGears); + if (! $inParGoto) { + $inParGoto = 1; + print $fd "${prev}struct Element* element;\n"; + } + my $initTask = << "EOFEOF"; + ${prev}context->task = NEW(struct Context); + ${prev}initContext(context->task); + ${prev}context->task->next = C_$codeGearName; + ${prev}context->task->idgCount = $inputCount; + ${prev}context->task->idg = context->task->dataNum; + ${prev}context->task->maxIdg = context->task->idg + $inputCount; + ${prev}context->task->odg = context->task->maxIdg; + ${prev}context->task->maxOdg = context->task->odg + $outputCount; EOFEOF - print $fd $initTask; - if (@iterateCounts) { - print $fd "${prev}context->task->iterate = 0;\n"; - my $len = @iterateCounts; - if ($len == 1) { - print $fd "${prev}context->task->iterator = createMultiDimIterator(context, $iterateCounts[0], 1, 1);\n"; - } elsif ($len == 2) { - print $fd "${prev}context->task->iterator = createMultiDimIterator(context, $iterateCounts[0], $iterateCounts[1], 1);\n"; - } elsif ($len == 3) { - print $fd "${prev}context->task->iterator = createMultiDimIterator(context, $iterateCounts[0], $iterateCounts[1], $iterateCounts[2]);\n"; - } - } - for my $dataGear (@dataGears) { - print $fd "${prev}GET_META($dataGear)->wait = createSynchronizedQueue(context);\n"; - } - for my $i (0..$inputCount-1) { - print $fd "${prev}context->task->data[context->task->idg+$i] = (union Data*)@dataGears[$i];\n"; - } + print $fd $initTask; + if (@iterateCounts) { + print $fd "${prev}context->task->iterate = 0;\n"; + my $len = @iterateCounts; + if ($len == 1) { + print $fd "${prev}context->task->iterator = createMultiDimIterator(context, $iterateCounts[0], 1, 1);\n"; + } elsif ($len == 2) { + print $fd "${prev}context->task->iterator = createMultiDimIterator(context, $iterateCounts[0], $iterateCounts[1], 1);\n"; + } elsif ($len == 3) { + print $fd "${prev}context->task->iterator = createMultiDimIterator(context, $iterateCounts[0], $iterateCounts[1], $iterateCounts[2]);\n"; + } + } + for my $dataGear (@dataGears) { + print $fd "${prev}GET_META($dataGear)->wait = createSynchronizedQueue(context);\n"; + } + for my $i (0..$inputCount-1) { + print $fd "${prev}context->task->data[context->task->idg+$i] = (union Data*)@dataGears[$i];\n"; + } - for my $i (0..$outputCount-1) { - print $fd "${prev}context->task->data[context->task->odg+$i] = (union Data*)@dataGears[$inputCount+$i];\n"; - } - my $putTask = << "EOFEOF"; - ${prev}element = &ALLOCATE(context, Element)->Element; - ${prev}element->next = NULL; - ${prev}element->data = (union Data*)context->task; - ${prev}context->tasks->queue->SingleLinkedQueue.last->next = element; - ${prev}context->tasks->queue->SingleLinkedQueue.last = element; + for my $i (0..$outputCount-1) { + print $fd "${prev}context->task->data[context->task->odg+$i] = (union Data*)@dataGears[$inputCount+$i];\n"; + } + my $putTask = << "EOFEOF"; + ${prev}element = &ALLOCATE(context, Element)->Element; + ${prev}element->next = NULL; + ${prev}element->data = (union Data*)context->task; + ${prev}context->tasks->queue->SingleLinkedQueue.last->next = element; + ${prev}context->tasks->queue->SingleLinkedQueue.last = element; EOFEOF - print $fd $putTask; - next; - } elsif (/^(.*)goto (\w+)\((.*)\);/) { - # handling goto statement - # convert it to the meta call form with two arugments, that is context and enum Code - my $prev = $1; - my $next = $2; - my @args = split(/, /,$3); - my $v = 0; - for my $n ( @{$dataGearVar{$codeGearName}} ) { - # continuation arguments - $v = 1 if ( $n eq $next); - } - if ($v || defined $code{$interface}->{$next}) { - # write continuation's arguments into the interface arguments - # we may need a commit for a shared DataGear - for my $arg ( @{$outputArgs{$codeGearName}->{$next}} ) { - my $v = shift(@args); - print $fd "\t*O_$arg = $v;\n"; - } - if ($inParGoto) { - print $fd "${prev}taskManager->tasks = context->tasks;\n"; - print $fd "${prev}taskManager->next1 = C_$next;\n"; - print $fd "${prev}goto meta(context, C_$next);\n"; - } else { - print $fd "${prev}goto meta(context, $next);\n"; - } - next; - } - if ($inParGoto) { - print $fd "${prev}taskManager->tasks = context->tasks;\n"; - print $fd "${prev}taskManager->next1 = C_$next;\n"; - print $fd "${prev}goto meta(context, C_$next);\n"; - next; - } elsif ($next eq "meta") { - print $fd $_; - next; - } else { - print $fd "${prev}goto meta(context, C_$next);\n"; - next; - } - } elsif(/^.*(struct|union)?\s(\w+)\*\s(\w+)\s?[=;]/) { - my $type = $2; - my $varName = $3; - $localVarType{$varName} = $type; - s/new\s+(\w+)\(\)/\&ALLOCATE(context, \1)->\1/g; # replacing new - } - elsif(/^}/) { - $inParGoto = 0; - } else { - s/new\s+(\w+)\(\)/\&ALLOCATE(context, \1)->\1/g; # replacing new - } - # gather type name and type - } elsif ($inMain) { - if (/^(.*)goto start_code\(main_context\);/) { - print $fd $_; - next; - } elsif (/^(.*)goto (\w+)\((.*)\);/) { - my $prev = $1; - my $next = $2; - print $fd "${prev}struct Context* main_context = NEW(struct Context);\n"; - print $fd "${prev}initContext(main_context);\n"; - print $fd "${prev}main_context->next = C_$next;\n"; - print $fd "${prev}goto start_code(main_context);\n"; - next; - } - } - if (/^}/) { - $inStub = 0; - $inTypedef = 0; - $inMain = 0; - } - print $fd $_; - } - if (defined $prevCodeGearName) { - if (!defined $stub{$prevCodeGearName."_stub"}) { - $stub{$prevCodeGearName."_stub"} = &generateStub($fd,$prevCodeGearName,$dataGearName{$codeGearName}); - } - } + print $fd $putTask; + next; + } elsif (/^(.*)goto (\w+)\((.*)\);/) { + # handling goto statement + # convert it to the meta call form with two arugments, that is context and enum Code + my $prev = $1; + my $next = $2; + my @args = split(/, /,$3); + my $v = 0; + for my $n ( @{$dataGearVar{$codeGearName}} ) { + # continuation arguments + $v = 1 if ( $n eq $next); + } + if ($v || defined $code{$interface}->{$next}) { + # write continuation's arguments into the interface arguments + # we may need a commit for a shared DataGear + for my $arg ( @{$outputArgs{$codeGearName}->{$next}} ) { + my $v = shift(@args); + print $fd "\t*O_$arg = $v;\n"; + } + if ($inParGoto) { + print $fd "${prev}taskManager->tasks = context->tasks;\n"; + print $fd "${prev}taskManager->next1 = C_$next;\n"; + print $fd "${prev}goto meta(context, C_$next);\n"; + } else { + print $fd "${prev}goto meta(context, $next);\n"; + } + next; + } + if ($inParGoto) { + print $fd "${prev}taskManager->tasks = context->tasks;\n"; + print $fd "${prev}taskManager->next1 = C_$next;\n"; + print $fd "${prev}goto meta(context, C_$next);\n"; + next; + } elsif ($next eq "meta") { + print $fd $_; + next; + } else { + print $fd "${prev}goto meta(context, C_$next);\n"; + next; + } + } elsif(/^.*(struct|union)?\s(\w+)\*\s(\w+)\s?[=;]/) { + my $type = $2; + my $varName = $3; + $localVarType{$varName} = $type; + s/new\s+(\w+)\(\)/\&ALLOCATE(context, \1)->\1/g; # replacing new + } + elsif(/^}/) { + $inParGoto = 0; + } else { + s/new\s+(\w+)\(\)/\&ALLOCATE(context, \1)->\1/g; # replacing new + } + # gather type name and type + } elsif ($inMain) { + if (/^(.*)goto start_code\(main_context\);/) { + print $fd $_; + next; + } elsif (/^(.*)goto (\w+)\((.*)\);/) { + my $prev = $1; + my $next = $2; + print $fd "${prev}struct Context* main_context = NEW(struct Context);\n"; + print $fd "${prev}initContext(main_context);\n"; + print $fd "${prev}main_context->next = C_$next;\n"; + print $fd "${prev}goto start_code(main_context);\n"; + next; + } + } + if (/^}/) { + $inStub = 0; + $inTypedef = 0; + $inMain = 0; + } + print $fd $_; + } + if (defined $prevCodeGearName) { + if (!defined $stub{$prevCodeGearName."_stub"}) { + $stub{$prevCodeGearName."_stub"} = &generateStub($fd,$prevCodeGearName,$dataGearName{$codeGearName}); + } + } } # end