Mercurial > hg > GearsTemplate
changeset 376:b46f38645587
Run oneDimIterator_test
author | Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 18 Jul 2017 16:35:48 +0900 |
parents | ad44fdb11433 |
children | b4677965afa7 |
files | src/parallel_execution/CMakeLists.txt src/parallel_execution/OneDimIterator.cbc src/parallel_execution/TaskManagerImpl.cbc src/parallel_execution/examples/bitonicSort.cbc src/parallel_execution/generate_stub.pl src/parallel_execution/test/oneDimIterator_test.cbc |
diffstat | 6 files changed, 178 insertions(+), 89 deletions(-) [+] |
line wrap: on
line diff
--- a/src/parallel_execution/CMakeLists.txt Tue Jul 18 16:13:11 2017 +0900 +++ b/src/parallel_execution/CMakeLists.txt Tue Jul 18 16:35:48 2017 +0900 @@ -102,6 +102,13 @@ GearsCommand( 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 +) + +GearsCommand( + TARGET sort SOURCES examples/sort.cbc
--- a/src/parallel_execution/OneDimIterator.cbc Tue Jul 18 16:13:11 2017 +0900 +++ b/src/parallel_execution/OneDimIterator.cbc Tue Jul 18 16:35:48 2017 +0900 @@ -21,7 +21,7 @@ } struct Context* iterate_task = NEW(struct Context); *iterate_task = *task; - task->iterate = 1; + iterate_task->iterate = 1; iterator->loopCounter->i++; taskManager->taskManager = (union Data*)task->taskManager; taskManager->context = iterate_task;
--- a/src/parallel_execution/TaskManagerImpl.cbc Tue Jul 18 16:13:11 2017 +0900 +++ b/src/parallel_execution/TaskManagerImpl.cbc Tue Jul 18 16:35:48 2017 +0900 @@ -125,6 +125,7 @@ iterator->iterator = (union Data*)task->iterator; iterator->task = task; iterator->next = next; + pthread_mutex_unlock(&taskManager->mutex); goto meta(context, task->iterator->exec); } goto meta(context, C_taskSend);
--- a/src/parallel_execution/examples/bitonicSort.cbc Tue Jul 18 16:13:11 2017 +0900 +++ b/src/parallel_execution/examples/bitonicSort.cbc Tue Jul 18 16:35:48 2017 +0900 @@ -128,6 +128,7 @@ __code createTask2(struct LoopCounter* loopCounter, struct TaskManager* taskManager) { struct Context** tasks = (struct Context**)ALLOC_ARRAY(context, Context, 1); struct Context* task = NEW(struct Context); + initContext(task); task->iterator = createOneDimIterator(context, 10); task->next = C_printIterator; task->idgCount = 0;
--- a/src/parallel_execution/generate_stub.pl Tue Jul 18 16:13:11 2017 +0900 +++ b/src/parallel_execution/generate_stub.pl Tue Jul 18 16:35:48 2017 +0900 @@ -38,59 +38,21 @@ 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+)\s*<(.*)>/) { + if (/^typedef struct (\w+)/) { $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"; @@ -112,29 +74,8 @@ $ttype = $2; } $var{$name}->{$tname} = $ttype; - } 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; - } - } + } elsif (/\_\_code (\w+)\(/) { + $code{$name}->{$1} = 1; } if (/^}/) { $inTypedef = 0; @@ -158,7 +99,6 @@ 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"; @@ -313,31 +253,6 @@ 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
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/parallel_execution/test/oneDimIterator_test.cbc Tue Jul 18 16:35:48 2017 +0900 @@ -0,0 +1,165 @@ +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <unistd.h> + +#include "../../context.h" + +int cpu_num = 1; +int length = 100; +int gpu_num = 0; +int CPU_ANY = -1; +int CPU_CUDA = -1; + +void *start_taskManager(struct Context *context) { + goto initDataGears(context, Gearef(context, LoopCounter), Gearef(context, TaskManager)); + return 0; +} + +#ifdef USE_CUDAWorker +#ifdef USE_CUDA_MAIN_THREAD +extern volatile int cuda_initialized; +#endif +#endif + +__code initDataGears(struct LoopCounter* loopCounter, struct TaskManager* taskManager) { + // loopCounter->tree = createRedBlackTree(context); + loopCounter->i = 0; + taskManager->taskManager = (union Data*)createTaskManagerImpl(context, cpu_num, gpu_num, 0); +#ifdef USE_CUDAWorker +#ifdef USE_CUDA_MAIN_THREAD + while(! cuda_initialized) {}; +#endif +#endif + goto meta(context, C_code1); +} + +__code initDataGears_stub(struct Context* context) { + struct TaskManager* taskManager = Gearef(context, TaskManager); + taskManager->taskManager = 0; +#if (! defined(USE_CUDAWorker) || ! defined(USE_CUDA_MAIN_THREAD)) + struct LoopCounter* loopCounter = Gearef(context, LoopCounter); + goto initDataGears(context, loopCounter, taskManager); +#else + cuda_initialized = 0; + pthread_t thread; + pthread_create(&thread, NULL, (void*)&start_taskManager, context); + while (taskManager->taskManager == 0); + TaskManager *t = (TaskManager*)taskManager->taskManager; + TaskManagerImpl *im = (TaskManagerImpl*)t->taskManager; + struct Queue *q = (Queue *)im->workers[0]; + createCUDAWorker(context,0,q, im); + pthread_join(thread,0); + exit(0); +#endif +} + +__code code1(struct Time* time) { + printf("cpus:\t\t%d\n", cpu_num); + printf("gpus:\t\t%d\n", gpu_num); + printf("length:\t\t%d\n", length); + /* puts("queue"); */ + /* print_queue(context->data[ActiveQueue]->queue.first); */ + /* puts("tree"); */ + /* print_tree(context->data[Tree]->tree.root); */ + /* puts("result"); */ + + time->time = (union Data*)createTimeImpl(context); + time->next = C_createTask1; + 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; + + if (i < length) { + loopCounter->i++; + goto meta(context, C_createTask2); + } + + loopCounter->i = 0; + taskManager->next = C_exit_code; + goto meta(context, taskManager->taskManager->TaskManager.shutdown); +} + +__code createTask2(struct LoopCounter* loopCounter, struct TaskManager* taskManager) { + struct Context** tasks = (struct Context**)ALLOC_ARRAY(context, Context, 1); + struct Context* task = NEW(struct Context); + initContext(task); + task->iterator = createOneDimIterator(context, 10); + task->next = C_printIterator; + task->idgCount = 0; + task->idg = task->dataNum; + task->maxIdg = task->idg; + task->odg = task->maxIdg; + task->maxOdg = task->odg; + tasks[0] = task; + taskManager->contexts = tasks; + taskManager->next1 = C_createTask1; + goto meta(context, taskManager->taskManager->TaskManager.spawnTasks); +} + +void init(int argc, char** argv) { + for (int i = 1; argv[i]; ++i) { + if (strcmp(argv[i], "-cpu") == 0) + cpu_num = (int)atoi(argv[i+1]); + else if (strcmp(argv[i], "-l") == 0) + length = (int)atoi(argv[i+1]); + else if (strcmp(argv[i], "-cuda") == 0) { + gpu_num = 1; + CPU_CUDA = 0; + } + } +} + +int main(int argc, char** argv) { + init(argc, argv); + struct Context* main_context = NEW(struct Context); + initContext(main_context); + main_context->next = C_initDataGears; + + goto start_code(main_context); +}