Mercurial > hg > Members > Moririn
changeset 377:b4677965afa7
Fix
author | Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 18 Jul 2017 17:52:22 +0900 |
parents | b46f38645587 |
children | 9049c19036fd |
files | src/parallel_execution/CMakeLists.txt src/parallel_execution/examples/swap.cbc src/parallel_execution/generate_stub.pl src/parallel_execution/test/oneDimIterator_test.cbc |
diffstat | 4 files changed, 122 insertions(+), 78 deletions(-) [+] |
line wrap: on
line diff
--- a/src/parallel_execution/CMakeLists.txt Tue Jul 18 16:35:48 2017 +0900 +++ b/src/parallel_execution/CMakeLists.txt Tue Jul 18 17:52:22 2017 +0900 @@ -104,7 +104,7 @@ TARGET oneDimIterator_test SOURCES - test/oneDimIterator_test.cbc examples/swap.cbc examples/InitIntegerDataGears.cbc CPUWorker.cbc TaskManagerImpl.cbc SingleLinkedQueue.cbc SynchronizedQueue.cbc OneDimIterator.cbc TimeImpl.cbc + test/oneDimIterator_test.cbc examples/InitIntegerDataGears.cbc CPUWorker.cbc TaskManagerImpl.cbc SingleLinkedQueue.cbc SynchronizedQueue.cbc OneDimIterator.cbc TimeImpl.cbc ) GearsCommand(
--- a/src/parallel_execution/examples/swap.cbc Tue Jul 18 16:35:48 2017 +0900 +++ b/src/parallel_execution/examples/swap.cbc Tue Jul 18 17:52:22 2017 +0900 @@ -1,38 +1,29 @@ #include "../../context.h" #include <stdio.h> -//__code swap(struct SortArray sortArray, struct Integer* block, struct Integer* first, struct Integer* i, __code next(struct SortArray* output, ...)) { -// int position = i->value/block->value; -// int index = i->value+block->value*position; -// -// block->value = (first->value == 1)? ((block->value<<1)*(position+1))-(index%block->value)-1 : index+block->value; -// -// if (sortArray->array[block] < sortArray->array[index]) { -// int Integer *tmp = sortArray->array[index]; -// sortArray->array[index] = sortArray->array[block]; -// sortArray->array[block] = tmp; -// } -// -// *O_output = output; -// goto meta(context, next); -//} -// -//__code swap_stub(struct Context* context) { -// SortArray** O_output = (struct SortArray **)&context->data[context->odg]; -// goto swap(context, -// &context->data[context->idg]->SortArray, -// &context->data[context->idg+1]->Integer, -// &context->data[context->idg+2]->Integer, -// &context->data[context->idg+3]->Integer, -// context->next, -// O_output); -//} + +__code swap(struct SortArray sortArray, struct Integer* block, struct Integer* first, struct Integer* i, __code next(struct SortArray* output, ...)) { + int position = i->value/block->value; + int index = i->value+block->value*position; + + block->value = (first->value == 1)? ((block->value<<1)*(position+1))-(index%block->value)-1 : index+block->value; -__code printIterator(__code next(...)) { - printf("test\n"); + if (sortArray->array[block] < sortArray->array[index]) { + int Integer *tmp = sortArray->array[index]; + sortArray->array[index] = sortArray->array[block]; + sortArray->array[block] = tmp; + } + + *O_output = output; goto meta(context, next); } -__code printIterator_stub(struct Context* context) { - goto printIterator(context, - context->next); +__code swap_stub(struct Context* context) { + SortArray** O_output = (struct SortArray **)&context->data[context->odg]; + goto swap(context, + &context->data[context->idg]->SortArray, + &context->data[context->idg+1]->Integer, + &context->data[context->idg+2]->Integer, + &context->data[context->idg+3]->Integer, + context->next, + O_output); }
--- a/src/parallel_execution/generate_stub.pl Tue Jul 18 16:35:48 2017 +0900 +++ b/src/parallel_execution/generate_stub.pl Tue Jul 18 17:52:22 2017 +0900 @@ -38,21 +38,59 @@ my %outputArgs; # continuation's output variables my %dataGear; my %dataGearName; +my %generic; +my %dataGearVarType; my $implementation; my $interface; +# interface definision +# +# typedef struct Stack<Type, Impl>{ +# 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*, ...)); +# __code pop2(Impl* stack, Type** data, Type** data1, __code next(Type**, Type**, ...)); +# __code isEmpty(Impl* stack, __code next(...), __code whenEmpty(...)); +# __code get(Impl* stack, Type** data, __code next(...)); +# __code get2(Impl* stack,..., __code next(...)); +# __code next(...); +# } Stack; +# +# calling example +# +# goto nodeStack->push((union Data*)node, stackTest3); +# +# generated meta level code +# +# Gearef(context, Stack)->stack = nodeStack->stack; +# Gearef(context, Stack)->data = (union Data*)node; +# Gearef(context, Stack)->next = C_stackTest3; +# goto meta(context, nodeStack->push); + sub getDataGear { my ($filename) = @_; my ($codeGearName, $name, $inTypedef); open my $fd,"<",$filename or die("can't open $filename $!"); while (<$fd>) { if (! $inTypedef) { - if (/^typedef struct (\w+)/) { + if (/^typedef struct (\w+)\s*<(.*)>/) { $inTypedef = 1; $name = $1; $dataGear{$name} = $_; $var{$name} = {}; $code{$name} = {}; + $generic{$name} = \split(/,/,$2); + } elsif (/^typedef struct (\w+)/) { + $inTypedef = 1; + $name = $1; + $dataGear{$name} = $_; + $var{$name} = {}; + $code{$name} = {}; + $generic{$name} = []; } elsif (/^(\w+)(\*)+ create(\w+)\(/) { if (defined $interface) { die "duplicate interface $interface\n"; @@ -74,8 +112,29 @@ $ttype = $2; } $var{$name}->{$tname} = $ttype; - } elsif (/\_\_code (\w+)\(/) { - $code{$name}->{$1} = 1; + } elsif (/^\_\_code (\w+)\((.*)\)(.*)/) { + my $args = $2; + my $method = $1; + $code{$name}->{$method} = []; + while($args) { + if ($args =~ s/(^\s*,\s*)//) { + } + # continuation case + if ($args =~ s/^(\s)*\_\_code\s+(\w+)\(([^)]*)\)//) { + my $next = $2; + my @args = split(/,/,$3); + push(@{$code{$name}->{$method}},$next); + } elsif ($args =~ s/^(struct|union) (\w+)(\*)+\s(\w+)//) { + my $structType = $1; + my $typeName = $2; + my $varName = $4; + my $typeField = lcfirst($typeName); + push(@{$code{$name}->{$method}},$varName); + } elsif ($args =~ s/(.*,)//) { + } else { + last; + } + } } if (/^}/) { $inTypedef = 0; @@ -99,6 +158,7 @@ return 0 if ( $n eq $varname1); } push @{$dataGearVar{$codeGearName}}, $varname1; + push @{$dataGearVarType{$codeGearName}}, $typeName; if ($typeName eq $implementation) { # get implementation $dataGearName{$codeGearName} .= "\t$typeName* $varName = ($typeName*)GearImpl(context, $interface, $varName);\n"; @@ -253,6 +313,31 @@ print $fd $outputVar{$codeGearName}; } next; + } elsif (/^(.*)goto (\w+)\-\>(\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 $method = $3; + my @args = split(/,/,$4); + my @types = @{$dataGearVarType{$codeGearName}}; + my $ntype; + for my $v (@{$dataGearVar{$codeGearName}}) { + my $t = shift @types; + if ($v eq $next) { + $ntype = $t; + } + } + print $fd "\tGearef(context, $ntype)->$next = $next->$next;\n"; + # Put interface argument + my $prot = $code{$ntype}->{$method}; + for my $arg (@args) { + my $p = shift @$prot; + next if ($p eq $arg); + print $fd "\tGearef(context, $ntype)->$p = $arg;\n"; + } + print $fd "${prev}goto meta(context, $next->$next->$ntype.$method);\n"; + next; } elsif (/^(.*)goto (\w+)\((.*)\);/) { # handling goto statement # convert it to the meta call form with two arugments, that is context and enum Code
--- a/src/parallel_execution/test/oneDimIterator_test.cbc Tue Jul 18 16:35:48 2017 +0900 +++ b/src/parallel_execution/test/oneDimIterator_test.cbc Tue Jul 18 17:52:22 2017 +0900 @@ -69,49 +69,6 @@ goto meta(context, time->time->Time.start); } -//__code createTask1(struct LoopCounter* loopCounter, struct TaskManager* taskManager) { -// int waitFlag = 0; -// struct SortArray* inputSortArray = &ALLOCATE_DATA_GEAR(context, sortArray)->sortArray; -// inputSortArray->array = array; -// for (int i=2; i <= length; i=2*i) { -// int first = 1; -// lastOne = (length <= i*2) ? true : false; -// for (int j=i>>1; 0 < j; j=j>>1) { -// struct SortArray* outputSortArray = &ALLOCATE_DATA_GEAR(context, sortArray)->sortArray; -// outputSortArray->array = array; -// for(int k=0; 0 < length/2; k++) { -// struct Context* task = NEW(struct Context); -// struct Integer* integer1 = &ALLOCATE_DATA_GEAR(context, Integer)->Integer; -// struct Integer* integer2 = &ALLOCATE_DATA_GEAR(context, Integer)->Integer; -// struct Integer* integer3 = &ALLOCATE_DATA_GEAR(context, Integer)->Integer; -// integer1->value = j; -// integer2->value = first; -// integer3->value = k; -// -// task->next = C_swap; -// if (waitFlag) { -// task->idgCount = length/2; -// } else { -// task->idgCount = 0; -// } -// task->idg = task->dataNum; -// task->data[task->idg] = (union Data*)inputSortArray; -// task->data[task->idg+1] = (union Data*)integer1; -// task->data[task->idg+2] = (union Data*)integer2; -// task->data[task->idg+3] = (union Data*)integer3; -// task->maxIdg = task->idg + 4; -// task->odg = task->maxIdg; -// task->data[task->odg] = outputSortArray; -// task->maxOdg = task->odg + 1; -// first = 0; -// } -// inputSortArray = outputSortArray; -// } -// waitFlag = 1; -// } -// goto meta(context, taskManager->taskManager->TaskManager.shutdown); -//} - __code createTask1(struct LoopCounter* loopCounter, struct TaskManager* taskManager, struct Time* time) { int i = loopCounter->i; @@ -129,6 +86,7 @@ struct Context** tasks = (struct Context**)ALLOC_ARRAY(context, Context, 1); struct Context* task = NEW(struct Context); initContext(task); + task->iterate = 0; task->iterator = createOneDimIterator(context, 10); task->next = C_printIterator; task->idgCount = 0; @@ -163,3 +121,13 @@ goto start_code(main_context); } + +__code printIterator(__code next(...)) { + printf("test\n"); + goto meta(context, next); +} + +__code printIterator_stub(struct Context* context) { + goto printIterator(context, + context->next); +}