Mercurial > hg > GearsTemplate
changeset 280:2c2e4e597eb0
generate no compile errors
author | mir3636 |
---|---|
date | Fri, 03 Feb 2017 17:47:27 +0900 |
parents | b5e8fce400a5 |
children | ceb8735aefb0 |
files | src/parallel_execution/CMakeLists.txt src/parallel_execution/CPUWorker.cbc src/parallel_execution/RedBlackTree.cbc src/parallel_execution/SingleLinkedQueue.cbc src/parallel_execution/SingleLinkedStack.cbc src/parallel_execution/SynchronizedQueue.cbc src/parallel_execution/TaskManager.cbc src/parallel_execution/TaskManagerImpl.cbc src/parallel_execution/generate_context.pl src/parallel_execution/generate_stub.pl src/parallel_execution/main.cbc src/parallel_execution/test/queue_test.c src/parallel_execution/test/stack_test.c |
diffstat | 13 files changed, 65 insertions(+), 51 deletions(-) [+] |
line wrap: on
line diff
--- a/src/parallel_execution/CMakeLists.txt Fri Feb 03 03:25:57 2017 +0900 +++ b/src/parallel_execution/CMakeLists.txt Fri Feb 03 17:47:27 2017 +0900 @@ -40,7 +40,7 @@ TARGET twice SOURCES - main.cbc RedBlackTree.cbc SingleLinkedStack.cbc CPUWorker.cbc time.cbc twice.cbc TaskManagerImpl.cbc SingleLinkedQueue.cbc SynchronizedQueue.cbc + main.cbc RedBlackTree.cbc compare.c SingleLinkedStack.cbc CPUWorker.cbc time.cbc twice.cbc TaskManagerImpl.cbc SingleLinkedQueue.cbc SynchronizedQueue.cbc ) GearsCommand(
--- a/src/parallel_execution/CPUWorker.cbc Fri Feb 03 03:25:57 2017 +0900 +++ b/src/parallel_execution/CPUWorker.cbc Fri Feb 03 17:47:27 2017 +0900 @@ -4,7 +4,7 @@ static void start_worker(Worker* worker); -Worker* createCPUWorker(struct Context* context, int id, Queue* queue, enum Code next) { +Worker* createCPUWorker(struct Context* context, int id, Queue* queue) { struct Worker* worker = new Worker(); struct CPUWorker* cpuWorker = new CPUWorker(); worker->worker = (union Data*)cpuWorker; @@ -56,6 +56,10 @@ cuLaunchkanel(); cuMemcpyDtoHAsync(); } + +__code twiceGpu_stub() { +} + #endif __code shutdownWorker(struct CPUWorker* worker) {
--- a/src/parallel_execution/RedBlackTree.cbc Fri Feb 03 03:25:57 2017 +0900 +++ b/src/parallel_execution/RedBlackTree.cbc Fri Feb 03 17:47:27 2017 +0900 @@ -1,7 +1,6 @@ #include <stdio.h> #include "../context.h" -#include "../origin_cs.h" extern enum Relational compare(struct Node* node1, struct Node* node2); @@ -44,10 +43,10 @@ if (root) { traverse->current = root; traverse->result = compare(traverse->current, node); - goto C_replaceNode(...); + goto meta(context, C_replaceNode); } - goto C_insertNode(...); + goto meta(context, C_insertNode); } __code putRedBlackTree_stub(struct Context* context) { @@ -93,9 +92,9 @@ traverse->newNode = newnewNode; if (traverse->current) { traverse->result = compare(traverse->current, node); - goto C_replaceNode(...); + goto meta(context, C_replaceNode); } - goto C_insertNode(...); + goto meta(context, C_insertNode); } @@ -132,10 +131,10 @@ if (parent != NULL) { traverse->parent = parent; traverse->grandparent = grandparent; - goto C_insertCase2(...); + goto meta(context, C_insertCase2); } traverse->root->color = Black; - goto C_stackClear(...); + goto meta(context, C_stackClear); } __code insertCase1_stub(struct Context* context) { @@ -147,9 +146,9 @@ __code insertCase2(struct RedBlackTree* traverse) { if (traverse->parent->color == Black) { - goto C_stackClear(...); + goto meta(context, C_stackClear); } - goto C_insertCase3(...); + goto meta(context, C_insertCase3); } __code insertCase2_stub(struct Context* context) { @@ -174,7 +173,7 @@ nodeStack->next = C_insertCase1; goto meta(context, traverse->nodeStack->pop2); } - goto C_insertCase4(...); + goto meta(context, C_insertCase4); } __code insertCase3_stub(struct Context* context) { @@ -207,7 +206,7 @@ goto meta(context, nodeStack->pop); } - goto C_insertCase5(...); + goto meta(context, C_insertCase5); } __code insertCase4_stub(struct Context* context) { @@ -237,9 +236,9 @@ rotateTree->next = C_stackClear; if ((current == parent->left) && (parent == grandparent->left)) - goto C_rotateRight(...); + goto meta(context, C_rotateRight); else - goto C_rotateLeft(...); + goto meta(context, C_rotateLeft); } __code insertCase51_stub(struct Context* context) { @@ -350,7 +349,7 @@ if (traverse->root) { traverse->current = traverse->root; - goto C_search(...); + goto meta(context, C_search); } goto next(...); @@ -374,7 +373,7 @@ } if (traverse->current) - goto C_search(...); + goto meta(context, C_search); goto next(...); }
--- a/src/parallel_execution/SingleLinkedQueue.cbc Fri Feb 03 03:25:57 2017 +0900 +++ b/src/parallel_execution/SingleLinkedQueue.cbc Fri Feb 03 17:47:27 2017 +0900 @@ -1,9 +1,8 @@ #include "../context.h" -#include "../origin_cs.h" #include <stdio.h> Queue* createSingleLinkedQueue(struct Context* context) { - struct Queue* queue = new Stack(); + struct Queue* queue = new Queue(); struct SingleLinkedQueue* singleLinkedQueue = new SingleLinkedQueue(); queue->queue = (union Data*)singleLinkedQueue; singleLinkedQueue->top = NULL;
--- a/src/parallel_execution/SingleLinkedStack.cbc Fri Feb 03 03:25:57 2017 +0900 +++ b/src/parallel_execution/SingleLinkedStack.cbc Fri Feb 03 17:47:27 2017 +0900 @@ -1,5 +1,4 @@ #include "../context.h" -#include "../origin_cs.h" #include <stdio.h> // typedef struct SingleLinkedStack {
--- a/src/parallel_execution/SynchronizedQueue.cbc Fri Feb 03 03:25:57 2017 +0900 +++ b/src/parallel_execution/SynchronizedQueue.cbc Fri Feb 03 17:47:27 2017 +0900 @@ -1,5 +1,5 @@ -#include "../queue.h" -#include "../origin_cs.h" +#include "../context.h" + #include <stdio.h> Queue* createSynchronizedQueue(struct Context* context) { @@ -48,12 +48,12 @@ if (queue->top) { struct Element* top = queue->top; if (__sync_bool_compare_and_swap(&queue->top, top, top->next)) { - *data = top->data; + data = top->data; } else { goto meta(context, C_takeSynchronizedQueue); } } else { - *data = NULL; + data = NULL; } goto next(data, ...); }
--- a/src/parallel_execution/TaskManager.cbc Fri Feb 03 03:25:57 2017 +0900 +++ b/src/parallel_execution/TaskManager.cbc Fri Feb 03 17:47:27 2017 +0900 @@ -1,4 +1,4 @@ -typedef struct TaskMabager<Impl>{ +typedef struct TaskManager<Impl>{ union Data* taskManager; __code createTask(struct TaskManager* taskManager); __code spawn(Impl* taskManager, struct Queue* queue, struct Context* task, __code next(...));
--- a/src/parallel_execution/TaskManagerImpl.cbc Fri Feb 03 03:25:57 2017 +0900 +++ b/src/parallel_execution/TaskManagerImpl.cbc Fri Feb 03 17:47:27 2017 +0900 @@ -4,7 +4,7 @@ void createWorkers(struct Context* context, TaskManager* taskManeger, TaskManagerImpl* taskManagerImpl); -TaskManager* createTaskManager(struct Context* context, int numCPU, int numGPU, int numIO) { +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 @@ -18,8 +18,8 @@ taskManager->shutdown = C_shutdownTaskManager; struct TaskManagerImpl* taskManagerImpl = new TaskManagerImpl(); taskManager->taskManager = (union Data*)taskManagerImpl; - taskManagerImpl -> activeQueue = &createSingleLinkedQueue(context)->Queue; - taskManagerImpl -> taskQueue = &createSingleLinkedQueue(context)->Queue; + taskManagerImpl -> activeQueue = createSingleLinkedQueue(context); + taskManagerImpl -> taskQueue = createSingleLinkedQueue(context); taskManagerImpl -> numWorker = taskManager->maxCPU; createWorkers(context, taskManager, taskManagerImpl); return taskManager; @@ -29,18 +29,18 @@ int i = 0; taskManagerImpl->workers = (Worker**)ALLOC_ARRAY(context, Worker, taskManager->maxCPU); for (;i<taskManager->gpu;i++) { - Queue* queue = &createSynchronizedQueue(context)->Queue; + Queue* queue = createSynchronizedQueue(context); taskManagerImpl->workers[i] = (Worker*)createCPUWorker(context, i, queue); } for (;i<taskManager->cpu;i++) { #ifdef USE_CUDA #else - Queue* queue = &createSynchronizedQueue(context)->Queue; + Queue* queue = createSynchronizedQueue(context); taskManagerImpl->workers[i] = (Worker*)createCPUWorker(context, i, queue); #endif } for (;i<taskManager->maxCPU;i++) { - Queue* queue = &createSynchronizedQueue(context)->Queue; + Queue* queue = createSynchronizedQueue(context); taskManagerImpl->workers[i] = (Worker*)createCPUWorker(context, i, queue); } } @@ -48,7 +48,7 @@ __code createTask(struct TaskManager* taskManager) { taskManager->context = NEW(struct Context); initContext(taskManager->context); - goto C_setWorker(...); + goto meta(context, C_setWorker); } __code setWorker(struct TaskManagerImpl* taskManager, struct Context* task, __code next(...)) { @@ -59,6 +59,11 @@ goto next(...); } +__code setWorker_stub(struct Context* context) { + TaskManagerImpl* taskManager = (TaskManagerImpl*)GearImpl(context, TaskManager, taskManager); + goto setWorker(context, taskManager, Gearef(context, TaskManager)->context, Gearef(context, TaskManager)->next); +} + __code spawnTaskManager(struct TaskManagerImpl* taskManager, struct Queue* queue, struct Context* task, __code next(...)) { if (task->idgCount == 0) { // enqueue activeQueue @@ -85,7 +90,7 @@ __code spawnTaskManager1(struct TaskManagerImpl* taskManager) { pthread_mutex_unlock(&taskManager->mutex); - goto C_taskSend(...); + goto meta(context, C_taskSend); } __code spawnTaskManager1_stub(struct Context* context) { @@ -124,7 +129,7 @@ goto meta(context, tasks->put); pthread_join(taskManagerImpl->workers[i]->worker->CPUWorker.thread, NULL); loopCounter->i++; - goto C_shutdownTaskManager(...); + goto meta(context, C_shutdownTaskManager); } loopCounter->i = 0;
--- a/src/parallel_execution/generate_context.pl Fri Feb 03 03:25:57 2017 +0900 +++ b/src/parallel_execution/generate_context.pl Fri Feb 03 17:47:27 2017 +0900 @@ -150,6 +150,9 @@ $code_init + context->code[C_start_code] = start_code_stub; + context->code[C_exit_code] = exit_code_stub; + #include "dataGearInit.c" // context->data[D_ActiveQueue] = createSynchronizedQueue(context); @@ -165,7 +168,7 @@ my $meta_call = <<"EOFEOF"; __code meta(struct Context* context, enum Code next) { - // printf("meta %d\n",next); + // printf("meta %d\\n",next); goto (context->code[next])(context); } @@ -188,7 +191,7 @@ goto exit_code(context); } -// end $context_c +// end context_c EOFEOF print $fd $meta_call;
--- a/src/parallel_execution/generate_stub.pl Fri Feb 03 03:25:57 2017 +0900 +++ b/src/parallel_execution/generate_stub.pl Fri Feb 03 17:47:27 2017 +0900 @@ -68,7 +68,12 @@ # gather type name and type $dataGear{$name} .= $_; if (/^\s*(.*)\s+(\w+);$/ ) { - $var{$name}->{$2} = $1; + my $ttype = $1; + my $tname = $2; + if ($ttype =~ /^(union|struct) (\w+)/) { + $ttype = $2; + } + $var{$name}->{$tname} = $ttype; } elsif (/\_\_code (\w+)\(/) { $code{$name}->{$1} = 1; } @@ -101,13 +106,16 @@ for my $ivar (keys %{$var{$interface}}) { # input data gear field if ($varName eq $ivar) { - if ($output) { - $dataGearName{$codeGearName} .= "\t$typeName** O_$varName = &Gearef(context, $interface)->$varName;\n"; - $outputVar{$codeGearName} .= "\t$typeName* $varName;\n"; + if ($typeName eq $var{$interface}->{$ivar}) { + if ($output) { + $dataGearName{$codeGearName} .= "\t$typeName** O_$varName = &Gearef(context, $interface)->$varName;\n"; + $outputVar{$codeGearName} .= "\t$typeName* $varName;\n"; + return 1; + } + + $dataGearName{$codeGearName} .= "\t$typeName* $varName = Gearef(context, $interface)->$varName;\n"; return 1; } - $dataGearName{$codeGearName} .= "\t$typeName* $varName = Gearef(context, $interface)->$varName;\n"; - return 1; } } for my $cName (keys %{$code{$interface}}) { @@ -192,9 +200,9 @@ $newArgs .= $1; } # continuation case - if ($args =~ s/^\_\_code\s+(\w+)\(([^)]*)\)//) { - my $next = $1; - my @args = split(/,/,$2); + if ($args =~ s/^(\s)*\_\_code\s+(\w+)\(([^)]*)\)//) { + my $next = $2; + my @args = split(/,/,$3); if ( &generateStubArgs($codeGearName, $next, "Code", $next, $interface,0) ) { $newArgs .= "enum Code $next"; }
--- a/src/parallel_execution/main.cbc Fri Feb 03 03:25:57 2017 +0900 +++ b/src/parallel_execution/main.cbc Fri Feb 03 17:47:27 2017 +0900 @@ -27,7 +27,7 @@ __code initDataGears(struct LoopCounter* loopCounter, struct TaskManager* taskManager) { loopCounter->tree = createRedBlackTree(context); loopCounter->i = 0; - taskManager->taskManager = (union Data*)createTaskManager(context, cpu_num, 0, 0); + taskManager->taskManager = (union Data*)createTaskManagerImpl(context, cpu_num, 0, 0); goto meta(context, C_createTask1); }
--- a/src/parallel_execution/test/queue_test.c Fri Feb 03 03:25:57 2017 +0900 +++ b/src/parallel_execution/test/queue_test.c Fri Feb 03 17:47:27 2017 +0900 @@ -1,6 +1,4 @@ -#include "../queue.h" #include "../context.h" -#include "../origin_cs.h" #include <assert.h> __code queueTest1(struct Context* context, struct Task* task, struct Queue* queue) { @@ -11,7 +9,7 @@ } __code queueTest1_stub(struct Context* context) { - Queue* queue = &createSingleLinkedQueue(context)->Queue; + Queue* queue = createSingleLinkedQueue(context); context->data[D_Queue]->Queue.queue = (union Data*)queue; SingleLinkedQueue* singleLinkedQueue = &context->data[D_Queue]->Queue.queue->Queue.queue->SingleLinkedQueue; assert(singleLinkedQueue->top == NULL);
--- a/src/parallel_execution/test/stack_test.c Fri Feb 03 03:25:57 2017 +0900 +++ b/src/parallel_execution/test/stack_test.c Fri Feb 03 17:47:27 2017 +0900 @@ -1,5 +1,4 @@ #include "../context.h" -#include "../c/extern.h" #include <assert.h> __code stack_test1(struct Context* context, struct Task* task, struct Stack* stack) { @@ -11,7 +10,7 @@ __code stack_test1_stub(struct Context* context) { Task* task = &ALLOCATE(context, Task)->Task; - struct Stack* stack = &(createSingleLinkedStack(context)->Stack); + Stack* stack = createSingleLinkedStack(context); assert(stack->stack->SingleLinkedStack.top == NULL); context->data[D_Stack]->Stack.stack = (union Data*)stack; goto stack_test1(context,