changeset 364:a0a3301bac4d

Add Time interface
author Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
date Thu, 29 Jun 2017 18:04:33 +0900
parents 3aab69fc4c28
children 51b7e4eb9ade
files src/parallel_execution/CMakeLists.txt src/parallel_execution/Time.cbc src/parallel_execution/TimeImpl.cbc src/parallel_execution/context.h src/parallel_execution/examples/twice.cbc src/parallel_execution/generate_stub.pl src/parallel_execution/time.cbc
diffstat 7 files changed, 56 insertions(+), 130 deletions(-) [+]
line wrap: on
line diff
--- a/src/parallel_execution/CMakeLists.txt	Thu Jun 29 01:14:21 2017 +0900
+++ b/src/parallel_execution/CMakeLists.txt	Thu Jun 29 18:04:33 2017 +0900
@@ -60,7 +60,7 @@
   TARGET
       twice
   SOURCES 
-      examples/twice.cbc CPUWorker.cbc time.cbc twice.cbc TaskManagerImpl.cbc SingleLinkedQueue.cbc SynchronizedQueue.cbc SemaphoreImpl.cbc
+  examples/twice.cbc CPUWorker.cbc twice.cbc TaskManagerImpl.cbc SingleLinkedQueue.cbc SynchronizedQueue.cbc SemaphoreImpl.cbc TimeImpl.cbc
 )
 
 GearsCommand(
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/parallel_execution/Time.cbc	Thu Jun 29 18:04:33 2017 +0900
@@ -0,0 +1,7 @@
+typedef struct Time<Impl>{
+        union Data* time;
+        __code start(Impl* time, __code next(...));
+        __code end(Impl* time, __code next(...));
+        __code next(...);
+} Queue;
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/parallel_execution/TimeImpl.cbc	Thu Jun 29 18:04:33 2017 +0900
@@ -0,0 +1,31 @@
+#include <stdio.h>
+#include <sys/time.h>
+
+#include "../context.h"
+
+Time* createTimeImpl(struct Context* context) {
+    struct Time* time = new Time();
+    struct TimeImpl* timeImpl = new TimeImpl();
+    time->time = (union Data*)timeImpl;
+    time->start = C_startTime;
+    time->end = C_endTime;
+    return time;
+}
+
+__code startTime(struct TimeImpl* time, __code next(...)) {
+    struct timeval tv;
+    gettimeofday(&tv, NULL);
+
+    time->time = tv.tv_sec + (double)tv.tv_usec*1e-6;
+
+    goto next(...);
+}
+
+__code endTime(struct TimeImpl* time, __code next(...)) {
+    struct timeval tv;
+    gettimeofday(&tv, NULL);
+
+    printf("%0.6f\n", (tv.tv_sec+(double)tv.tv_usec*1e-6) - time->time);
+
+    goto next(...);
+}
--- a/src/parallel_execution/context.h	Thu Jun 29 01:14:21 2017 +0900
+++ b/src/parallel_execution/context.h	Thu Jun 29 18:04:33 2017 +0900
@@ -104,9 +104,14 @@
     } meta;
     struct Context Context;
     struct Time {
+        union Data* time;
+        enum Code start;
+        enum Code end;
         enum Code next;
+    } Time;
+    struct TimeImpl {
         double time;
-    } Time;
+    } TimeImpl;
     struct LoopCounter {
         int i;
     } LoopCounter;
--- a/src/parallel_execution/examples/twice.cbc	Thu Jun 29 01:14:21 2017 +0900
+++ b/src/parallel_execution/examples/twice.cbc	Thu Jun 29 18:04:33 2017 +0900
@@ -48,7 +48,7 @@
     while(! cuda_initialized) {};
 #endif
 #endif
-    goto meta(context, C_createTask1);
+    goto meta(context, C_code1);
 }
 
 __code initDataGears_stub(struct Context* context) {
@@ -81,17 +81,14 @@
     /* puts("tree"); */
     /* print_tree(context->data[Tree]->tree.root); */
     /* puts("result"); */
-
-    time->next = C_code2;
-    goto meta(context, C_code2);
+    time->time = (union Data*)createTimeImpl(context);
+    time->next = C_createTask1;
+    goto meta(context, time->time->Time.start);
+    //goto meta(context, C_createTask1);
     //goto meta(context, C_exit_code);
     //goto meta(context, C_start_time);
 }
 
-__code code1_stub(struct Context* context) {
-    goto code1(context, Gearef(context, Time));
-}
-
 __code code2(struct LoopCounter* loopCounter) {
     int i = loopCounter->i;
 
@@ -108,7 +105,7 @@
     goto meta(context, C_exit_code);
 }
 
-__code createTask1(struct LoopCounter* loopCounter, struct TaskManager* taskManager) {
+__code createTask1(struct LoopCounter* loopCounter, struct TaskManager* taskManager, struct Time* time) {
     int i = loopCounter->i;
 
     if ((length/split*i) < length) {
@@ -116,7 +113,8 @@
     }
 
     loopCounter->i = 0;
-    taskManager->next = C_code1;
+    taskManager->next = time->time->Time.end;
+    time->next = C_code2;
 #if ( defined(USE_CUDAWorker) && defined(USE_CUDA_MAIN_THREAD))
 sleep(5);
 #endif
--- a/src/parallel_execution/generate_stub.pl	Thu Jun 29 01:14:21 2017 +0900
+++ b/src/parallel_execution/generate_stub.pl	Thu Jun 29 18:04:33 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
--- a/src/parallel_execution/time.cbc	Thu Jun 29 01:14:21 2017 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,30 +0,0 @@
-#include <stdio.h>
-#include <sys/time.h>
-
-#include "../context.h"
-
-__code start_time(struct Time* time) {
-    struct timeval tv;
-    gettimeofday(&tv, NULL);
-
-    time->time = tv.tv_sec + (double)tv.tv_usec*1e-6;
-
-    goto meta(context, time->next);
-}
-
-__code start_time_stub(struct Context* context) {
-    goto start_time(context, &context->data[D_Time]->Time);
-}
-
-__code end_time(struct Time* time) {
-    struct timeval tv;
-    gettimeofday(&tv, NULL);
-
-    printf("%0.6f\n", (tv.tv_sec+(double)tv.tv_usec*1e-6) - time->time);
-
-    goto meta(context, time->next);
-}
-
-__code end_time_stub(struct Context* context) {
-    goto end_time(context, Gearef(context, Time));
-}