# HG changeset patch # User mir3636 # Date 1486034876 -32400 # Node ID 23767f714f4aae90aa562a7b5d45f7d457cd62f2 # Parent 9d671e63df74d9d9b20783709662cdc76ea2e1a4 fix generate_stub diff -r 9d671e63df74 -r 23767f714f4a src/parallel_execution/CMakeLists.txt --- a/src/parallel_execution/CMakeLists.txt Thu Feb 02 18:29:50 2017 +0900 +++ b/src/parallel_execution/CMakeLists.txt Thu Feb 02 20:27:56 2017 +0900 @@ -40,27 +40,20 @@ TARGET twice SOURCES - main.c rb_tree.c stack.c origin_cs.c allocate.c compare.c worker.c dependency.c time.c twice.c taskManager.c queue.c + main.cbc RedBlackTree.cbc SingleLinkedStack.cbc CPUWorker.cbc time.cbc twice.cbc TaskManagerImpl.cbc SingleLinkedQueue.cbc SynchronizedQueue.cbc +) + +GearsCommand( + TARGET + queue_test + SOURCES + test/queue_test.c SingleLinkedQueue.cbc ) GearsCommand( TARGET stack_test SOURCES - origin_cs.c test/stack_test.c stack.c + test/stack_test.c SingleLinkedStack.cbc ) -GearsCommand( - TARGET - queue_test - SOURCES - origin_cs.c test/queue_test.c queue.c -) - -GearsCommand( - TARGET - cbc_stack_test - SOURCES - origin_cs.c test/cbc_stack_test.c SingleLinkedStack.cbc -) - diff -r 9d671e63df74 -r 23767f714f4a src/parallel_execution/CPUWorker.cbc --- a/src/parallel_execution/CPUWorker.cbc Thu Feb 02 18:29:50 2017 +0900 +++ b/src/parallel_execution/CPUWorker.cbc Thu Feb 02 20:27:56 2017 +0900 @@ -1,7 +1,6 @@ #include -#include "context.h" -#include "origin_cs.h" +#include "../context.h" static void start_worker(Worker* worker); diff -r 9d671e63df74 -r 23767f714f4a src/parallel_execution/TaskManagerImpl.cbc --- a/src/parallel_execution/TaskManagerImpl.cbc Thu Feb 02 18:29:50 2017 +0900 +++ b/src/parallel_execution/TaskManagerImpl.cbc Thu Feb 02 20:27:56 2017 +0900 @@ -1,5 +1,5 @@ #include "../context.h" -#include "../origin_cs.h" + #include void createWorkers(struct Context* context, TaskManager* taskManeger, TaskManagerImpl* taskManagerImpl); diff -r 9d671e63df74 -r 23767f714f4a src/parallel_execution/context.h --- a/src/parallel_execution/context.h Thu Feb 02 18:29:50 2017 +0900 +++ b/src/parallel_execution/context.h Thu Feb 02 20:27:56 2017 +0900 @@ -256,4 +256,12 @@ typedef union Data Data; #include "c/typedefData.h" + +#include "c/extern.h" + +extern __code start_code(struct Context* context); +extern __code exit_code(struct Context* context); +extern __code meta(struct Context* context, enum Code next); +extern void initContext(struct Context* context); + #endif diff -r 9d671e63df74 -r 23767f714f4a src/parallel_execution/generate_context.pl --- a/src/parallel_execution/generate_context.pl Thu Feb 02 18:29:50 2017 +0900 +++ b/src/parallel_execution/generate_context.pl Thu Feb 02 20:27:56 2017 +0900 @@ -118,7 +118,7 @@ } for my $impl ( sort keys %constructor ) { my ($interface, $constructorArgs) = @{$constructor{$impl}}; - print $fd "extern $interface create${impl}($constructorArgs);\n"; + print $fd "extern ${interface}* create${impl}($constructorArgs);\n"; } print $fd "\n"; @@ -138,12 +138,6 @@ #include #include "../context.h" -#include "extern.h" - -extern __code start_code(struct Context* context); -extern __code exit_code(struct Context* context); -extern __code meta(struct Context* context, enum Code next); -extern void initContext(struct Context* context); void initContext(struct Context* context) { context->heapLimit = sizeof(union Data)*ALLOCATE_SIZE; @@ -197,6 +191,8 @@ // end $context_c EOFEOF + print $fd $meta_call; + open my $fd,">","$ddir/enumData.h" or die("can't open $ddir/enumData.h $!"); print $fd "enum DataType {\n"; print $fd " D_Code,\n"; diff -r 9d671e63df74 -r 23767f714f4a src/parallel_execution/generate_stub.pl --- a/src/parallel_execution/generate_stub.pl Thu Feb 02 18:29:50 2017 +0900 +++ b/src/parallel_execution/generate_stub.pl Thu Feb 02 20:27:56 2017 +0900 @@ -149,11 +149,12 @@ my $prevCodeGearName; my $inTypedef = 0; + my $inStub = 0; my %stub; my $codeGearName; while (<$in>) { - if (! $inTypedef) { + if (! $inTypedef && ! $inStub) { if (/^typedef struct (\w+) {/) { $inTypedef = 1; } elsif (/^\_\_code (\w+)\((.*)\)(.*)/) { @@ -162,6 +163,7 @@ my $tail = $3; if ($codeGearName =~ /_stub$/) { # don't touch already existing stub + $inStub = 1; $stub{$codeGearName} = 1; print $fd $_; next; @@ -170,10 +172,10 @@ # stub is generated just before next CodeGear if (defined $stub{$prevCodeGearName."_stub"}) { undef $prevCodeGearName; - print $fd $_; - next; + } else { + &generateStub($fd,$prevCodeGearName,$dataGearName{$prevCodeGearName}); + $stub{$prevCodeGearName."_stub"} = 1; } - $stub{$prevCodeGearName."_stub"} = &generateStub($fd,$prevCodeGearName,$dataGearName{$prevCodeGearName}); } # analyzing CodeGear argument # these arguments are extract from current context's arugment DataGear Interface @@ -239,24 +241,27 @@ } next; } elsif (/^(.*)goto (\w+)\((.*)\);/) { - # handling got 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; my @args = split(/,/,$3); - # 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 (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"; + } + print $fd "${prev}goto meta(context, $next);\n"; + next; } - print $fd "${prev}goto meta(context, $next);\n"; - next; } else { s/new\s+(\w+)\(\)/\&ALLOCATE(context, \1)->\1/g; # replacing new } # gather type name and type } elsif (/^}/) { + $inStub = 0; $inTypedef = 0; } print $fd $_; diff -r 9d671e63df74 -r 23767f714f4a src/parallel_execution/main.cbc --- a/src/parallel_execution/main.cbc Thu Feb 02 18:29:50 2017 +0900 +++ b/src/parallel_execution/main.cbc Thu Feb 02 20:27:56 2017 +0900 @@ -2,12 +2,7 @@ #include #include -#include "context.h" -#include "origin_cs.h" - -extern union Data* createRedBlackTree(struct Context* context); -extern union Data* createTaskManager(struct Context* context, int numCPU, int numGPU, int numIO); -extern void allocator(struct Context* context); +#include "../context.h" int cpu_num = 1; int length = 102400; @@ -29,7 +24,7 @@ } } -__code initDataGears(struct Context* context, struct LoopCounter* loopCounter, struct TaskManager* taskManager) { +__code initDataGears(struct LoopCounter* loopCounter, struct TaskManager* taskManager) { loopCounter->tree = &createRedBlackTree(context)->Tree; loopCounter->i = 0; taskManager->taskManager = (union Data*)&createTaskManager(context, cpu_num, 0, 0)->TaskManager; @@ -40,7 +35,7 @@ goto initDataGears(context, Gearef(context, LoopCounter), Gearef(context, TaskManager)); } -__code code1(struct Context* context, struct Time* time) { +__code code1(struct Time* time) { printf("cpus:\t\t%d\n", cpu_num); printf("length:\t\t%d\n", length); printf("length/task:\t%d\n", length/split); @@ -59,7 +54,7 @@ goto code1(context, Gearef(context, Time)); } -__code code2(struct Context* context, struct Array* array, struct LoopCounter* loopCounter) { +__code code2(struct Array* array, struct LoopCounter* loopCounter) { int i = loopCounter->i; if (i < length) { @@ -79,7 +74,7 @@ goto code2(context, &context->data[D_Node]->Node.value->Array, &context->data[D_LoopCounter]->LoopCounter); } -__code createData1(struct Context* context, struct Allocate* allocate, struct LoopCounter* loopCounter) { +__code createData1(struct Allocate* allocate, struct LoopCounter* loopCounter) { int i = loopCounter->i; if ((length/split*i) < length) { @@ -94,7 +89,7 @@ goto createData1(context, Gearef(context, Allocate), Gearef(context, LoopCounter)); } -__code createData2(struct Context* context, struct LoopCounter* loopCounter, struct Array* array, struct Node* node, Tree* tree) { +__code createData2(struct LoopCounter* loopCounter, struct Array* array, struct Node* node, Tree* tree) { int i = loopCounter->i; array->index = i; @@ -121,7 +116,7 @@ Gearef(context, Tree)); } -__code createTask1(struct Context* context, struct LoopCounter* loopCounter, struct TaskManager* taskManager) { +__code createTask1(struct LoopCounter* loopCounter, struct TaskManager* taskManager) { int i = loopCounter->i; if ((length/split*i) < length) { @@ -139,7 +134,7 @@ Gearef(context, TaskManager)); } -__code createTask2(struct Context* context, LoopCounter* loopCounter, TaskManager* taskManager,struct Context* task, Array* array) { +__code createTask2(LoopCounter* loopCounter, TaskManager* taskManager,struct Context* task, Array* array) { int i = loopCounter->i; if ((length/split*i) < length) { diff -r 9d671e63df74 -r 23767f714f4a src/parallel_execution/test/cbc_stack_test.c --- a/src/parallel_execution/test/cbc_stack_test.c Thu Feb 02 18:29:50 2017 +0900 +++ b/src/parallel_execution/test/cbc_stack_test.c Thu Feb 02 20:27:56 2017 +0900 @@ -1,6 +1,4 @@ -#include "../stack.h" #include "../context.h" -#include "../origin_cs.h" #include __code stack_test1(struct Context* context, struct Task* task, struct Stack* stack) { diff -r 9d671e63df74 -r 23767f714f4a src/parallel_execution/test/stack_test.c --- a/src/parallel_execution/test/stack_test.c Thu Feb 02 18:29:50 2017 +0900 +++ b/src/parallel_execution/test/stack_test.c Thu Feb 02 20:27:56 2017 +0900 @@ -1,6 +1,5 @@ -#include "../stack.h" #include "../context.h" -#include "../origin_cs.h" +#include "../c/extern.h" #include __code stack_test1(struct Context* context, struct Task* task, struct Stack* stack) { diff -r 9d671e63df74 -r 23767f714f4a src/parallel_execution/time.cbc --- a/src/parallel_execution/time.cbc Thu Feb 02 18:29:50 2017 +0900 +++ b/src/parallel_execution/time.cbc Thu Feb 02 20:27:56 2017 +0900 @@ -1,10 +1,9 @@ #include #include -#include "context.h" -#include "origin_cs.h" +#include "../context.h" -__code start_time(struct Context* context, struct Time* time) { +__code start_time(struct Time* time) { struct timeval tv; gettimeofday(&tv, NULL); @@ -17,7 +16,7 @@ goto start_time(context, &context->data[D_Time]->Time); } -__code end_time(struct Context* context, struct Time* time) { +__code end_time(struct Time* time) { struct timeval tv; gettimeofday(&tv, NULL); diff -r 9d671e63df74 -r 23767f714f4a src/parallel_execution/twice.cbc --- a/src/parallel_execution/twice.cbc Thu Feb 02 18:29:50 2017 +0900 +++ b/src/parallel_execution/twice.cbc Thu Feb 02 20:27:56 2017 +0900 @@ -1,9 +1,8 @@ #include -#include "context.h" -#include "origin_cs.h" +#include "../context.h" -__code twice(struct Context* context, struct LoopCounter* loopCounter, int index, int prefix, int* array, struct Context* workerContext) { +__code twice(struct LoopCounter* loopCounter, int index, int prefix, int* array, struct Context* workerContext) { int i = loopCounter->i; if (i < prefix) { array[i+index*prefix] = array[i+index*prefix]*2;