changeset 447:57132ef16009

Remove ALLOCATE_DATA_GEAR from par goto code gear arguments
author Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
date Thu, 30 Nov 2017 15:42:19 +0900
parents 0c024ea61601
children bb29a1fe43ee
files src/parallel_execution/MultiDimIterator.cbc src/parallel_execution/SynchronizedQueue.cbc src/parallel_execution/TimeImpl.cbc src/parallel_execution/context.h src/parallel_execution/examples/bitonicSort/bitonicSort.cbc src/parallel_execution/examples/calc/calc.cbc src/parallel_execution/examples/twice/main.cbc src/parallel_execution/generate_stub.pl src/parallel_execution/main.cbc
diffstat 9 files changed, 155 insertions(+), 140 deletions(-) [+]
line wrap: on
line diff
--- a/src/parallel_execution/MultiDimIterator.cbc	Sun Nov 26 04:26:44 2017 +0900
+++ b/src/parallel_execution/MultiDimIterator.cbc	Thu Nov 30 15:42:19 2017 +0900
@@ -43,7 +43,6 @@
     multiDim->y = y;
     multiDim->z = z;
     task1->data[task1->maxIdg++] = (union Data*)multiDim;
-
     task1->odg      = task->odg + 1;
     task1->maxOdg   = task->maxOdg + 1;
     for (int i = task1->odg; i < task1->maxOdg; i++) {
--- a/src/parallel_execution/SynchronizedQueue.cbc	Sun Nov 26 04:26:44 2017 +0900
+++ b/src/parallel_execution/SynchronizedQueue.cbc	Thu Nov 30 15:42:19 2017 +0900
@@ -2,7 +2,7 @@
 
 #include <stdio.h>
 
-/* 
+/*
  * Nonnon-blocking queue of Paper: Simple, Fast, and Practical Non-Blocking and Blocking Concurrent Queue Algorithms(https://www.research.ibm.com/people/m/michael/podc-1996.pdf).
  */
 
@@ -81,8 +81,14 @@
 }
 
 __code isEmptySynchronizedQueue(struct SynchronizedQueue* queue, __code next(...), __code whenEmpty(...)) {
-    if (queue->top)
-        goto next(...);
-    else
+    struct Element* top = queue->top;
+    struct Element* last = queue->last;
+    struct Element* nextElement = top->next;
+    if (top != queue->top) {
+        goto meta(context, C_isEmptySynchronizedQueue);
+    }
+    if (top == last && nextElement == NULL) {
         goto whenEmpty(...);
+    }
+    goto next(...);
 }
--- a/src/parallel_execution/TimeImpl.cbc	Sun Nov 26 04:26:44 2017 +0900
+++ b/src/parallel_execution/TimeImpl.cbc	Thu Nov 30 15:42:19 2017 +0900
@@ -4,7 +4,7 @@
 #include "../context.h"
 
 Time* createTimeImpl(struct Context* context) {
-    struct Time* time = &ALLOCATE_DATA_GEAR(context, Time)->Time;
+    struct Time* time = new Time();
     struct TimeImpl* timeImpl = new TimeImpl();
     time->time = (union Data*)timeImpl;
     time->start = C_startTime;
--- a/src/parallel_execution/context.h	Sun Nov 26 04:26:44 2017 +0900
+++ b/src/parallel_execution/context.h	Thu Nov 30 15:42:19 2017 +0900
@@ -389,6 +389,12 @@
     CUdeviceptr CUdeviceptr;
 #endif
     Int Int;
+    struct Memory {
+        union Data* adr;
+        int length;
+        union Data* body;
+        int hash;
+    } Memory;
 }; // union Data end       this is necessary for context generator
 typedef union Data Data;
 
--- a/src/parallel_execution/examples/bitonicSort/bitonicSort.cbc	Sun Nov 26 04:26:44 2017 +0900
+++ b/src/parallel_execution/examples/bitonicSort/bitonicSort.cbc	Thu Nov 30 15:42:19 2017 +0900
@@ -71,7 +71,7 @@
 }
 
 __code createTask1(struct LoopCounter* loopCounter, struct TaskManager* taskManager) {
-    struct SortArray* outputSortArray = &ALLOCATE_DATA_GEAR(context, SortArray)->SortArray;
+    struct SortArray* outputSortArray = new SortArray();
     struct SortArray* inputSortArray = outputSortArray;
     struct Time* time = createTimeImpl(context);
 
@@ -80,7 +80,7 @@
     for (int i=2; i <= length; i=2*i) {
         int first = 1;
         for (int j=i>>1; j > 0; j=j>>1) {
-            outputSortArray = &ALLOCATE_DATA_GEAR(context, SortArray)->SortArray;
+            outputSortArray = new SortArray();
             inputSortArray->prefix = length/2/split;
             inputSortArray->block = j;
             inputSortArray->first = first;
--- a/src/parallel_execution/examples/calc/calc.cbc	Sun Nov 26 04:26:44 2017 +0900
+++ b/src/parallel_execution/examples/calc/calc.cbc	Thu Nov 30 15:42:19 2017 +0900
@@ -89,13 +89,13 @@
 }
 
 __code createTask2(struct LoopCounter* loopCounter, struct TaskManager* taskManager) {
-    Integer* integer1 = &ALLOCATE_DATA_GEAR(context, Integer)->Integer;
-    Integer* integer2 = &ALLOCATE_DATA_GEAR(context, Integer)->Integer;
-    Integer* integer3 = &ALLOCATE_DATA_GEAR(context, Integer)->Integer;
+    Integer* integer1 = new Integer();
+    Integer* integer2 = new Integer();
+    Integer* integer3 = new Integer();
     par goto mult(integer1, integer2, integer3, __exit);
 
-    Integer* integer4 = &ALLOCATE_DATA_GEAR(context, Integer)->Integer;
-    Integer* integer5 = &ALLOCATE_DATA_GEAR(context, Integer)->Integer;
+    Integer* integer4 = new Integer();
+    Integer* integer5 = new Integer();
     par goto add(integer4, integer5, integer1, __exit);
 
     par goto initIntegerDataGears(integer2, integer4, integer5, __exit);
--- a/src/parallel_execution/examples/twice/main.cbc	Sun Nov 26 04:26:44 2017 +0900
+++ b/src/parallel_execution/examples/twice/main.cbc	Thu Nov 30 15:42:19 2017 +0900
@@ -71,8 +71,8 @@
 
 
 __code createTask1(struct LoopCounter* loopCounter, struct TaskManager* taskManager) {
-    Array* array1 = &ALLOCATE_DATA_GEAR(context, Array)->Array;
-    Array* array2 = &ALLOCATE_DATA_GEAR(context, Array)->Array;
+    Array* array1 = new Array();
+    Array* array2 = new Array();
     Time* time = createTimeImpl(context);
 
     par goto createArray(array1, time, __exit);
--- a/src/parallel_execution/generate_stub.pl	Sun Nov 26 04:26:44 2017 +0900
+++ b/src/parallel_execution/generate_stub.pl	Thu Nov 30 15:42:19 2017 +0900
@@ -432,137 +432,141 @@
                 # convert it to the parallel
                 my $prev = $1;
                 my $codeGearName = $2;
+				my $args = $3;
                 my $inputCount = $codeGear{$codeGearName}->{'input'};
                 my $outputCount = $codeGear{$codeGearName}->{'output'};
-                my @dataGears = split(/,\s*/, $3);
-                my $nextCodeGear = pop(@dataGears);
                 my @iterateCounts;
                 # parse examples 'par goto(.., iterate(10), exit);'
-                if ($3 =~ /iterate\((.*)?\)/) {
-                    @iterateCounts = split(/,/,$1);;
-                    $inputCount--;
-                    # pop iterate statement
-                    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 $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
--- a/src/parallel_execution/main.cbc	Sun Nov 26 04:26:44 2017 +0900
+++ b/src/parallel_execution/main.cbc	Thu Nov 30 15:42:19 2017 +0900
@@ -94,7 +94,7 @@
 }
 
 __code createTask1(struct LoopCounter* loopCounter, struct TaskManager* taskManager) {
-    Array* array = &ALLOCATE_DATA_GEAR(context, Array)->Array;
+    Array* array = new Array();
 
     par goto createArray(array, __exit);