changeset 570:1233236c244d

autogen DetaGears
author anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Sun, 24 Nov 2019 22:54:35 +0900
parents 077158ea026c
children d9c3bccaa13c
files src/parallel_execution/plautogen/impl/AtomicReference.h src/parallel_execution/plautogen/impl/CUDAExecutor.h src/parallel_execution/plautogen/impl/CUDAWorker.h src/parallel_execution/plautogen/impl/LockImpl.h src/parallel_execution/plautogen/impl/MultiDimIterator.h src/parallel_execution/plautogen/impl/RedBlackTree.h src/parallel_execution/plautogen/impl/SemaphoreImpl.h src/parallel_execution/plautogen/impl/SingleLinkedQueue.h src/parallel_execution/plautogen/impl/SpinLock.h src/parallel_execution/plautogen/impl/SynchronizedQueue.h src/parallel_execution/plautogen/impl/TaskManagerImpl.h src/parallel_execution/plautogen/impl/TimerImpl.h src/parallel_execution/plautogen/interface/Allocate.h src/parallel_execution/plautogen/interface/Array.h src/parallel_execution/plautogen/interface/ArrayStack.h src/parallel_execution/plautogen/interface/BoundedBuffer.h src/parallel_execution/plautogen/interface/CPUWorker.h src/parallel_execution/plautogen/interface/CUDABuffer.h src/parallel_execution/plautogen/interface/Element.h src/parallel_execution/plautogen/interface/Integer.h src/parallel_execution/plautogen/interface/LoopCounter.h src/parallel_execution/plautogen/interface/Main.h src/parallel_execution/plautogen/interface/Memory.h src/parallel_execution/plautogen/interface/Meta.h src/parallel_execution/plautogen/interface/MultiDim.h src/parallel_execution/plautogen/interface/Node.h src/parallel_execution/plautogen/interface/RotateTree.h src/parallel_execution/tmp_tool/parse_cerate_each_context.pl
diffstat 28 files changed, 288 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/parallel_execution/plautogen/impl/AtomicReference.h	Sun Nov 24 22:54:35 2019 +0900
@@ -0,0 +1,3 @@
+typedef struct AtomicReference <Type, Isa> impl Atomic {
+  ;
+} AtomicReference;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/parallel_execution/plautogen/impl/CUDAExecutor.h	Sun Nov 24 22:54:35 2019 +0900
@@ -0,0 +1,9 @@
+typedef struct CUDAExecutor <Type, Isa> impl Executor {
+  CUdeviceptr** kernelParams;
+  struct CUDABuffer* buffer;
+  int maxThreadPerBlock;
+  int maxThreadPerBlockX;
+  int maxThreadPerBlockY;
+  int maxThreadPerBlockZ;
+  struct Timer* timer;
+} CUDAExecutor;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/parallel_execution/plautogen/impl/CUDAWorker.h	Sun Nov 24 22:54:35 2019 +0900
@@ -0,0 +1,14 @@
+typedef struct CUDAWorker <Type, Isa> impl Worker {
+  CUdevice device;
+  CUcontext cuCtx;
+  struct Context* context;
+  int id;
+  int loopCounter;
+  int deviceNum;
+  struct Queue* tasks;
+  int runFlag;
+  __code next(...)
+  int numStream;
+  struct Executor* executor;
+  CUstream *stream;
+} CUDAWorker;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/parallel_execution/plautogen/impl/LockImpl.h	Sun Nov 24 22:54:35 2019 +0900
@@ -0,0 +1,6 @@
+typedef struct LockImpl <Type, Isa> impl Lock {
+  Int* lock;
+  struct Queue* waitThreadQueue;
+  struct Atomic* atomic;
+  struct Context* lockContext;
+} LockImpl;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/parallel_execution/plautogen/impl/MultiDimIterator.h	Sun Nov 24 22:54:35 2019 +0900
@@ -0,0 +1,9 @@
+typedef struct MultiDimIterator <Type, Isa> impl Iterator {
+  int x;
+  int y;
+  int z;
+  int count;
+  int counterX;
+  int counterY;
+  int counterZ;
+} MultiDimIterator;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/parallel_execution/plautogen/impl/RedBlackTree.h	Sun Nov 24 22:54:35 2019 +0900
@@ -0,0 +1,11 @@
+typedef struct RedBlackTree <Type, Isa> impl Tree {
+  struct Node* root;
+  struct Node* current // reading node of original tree;
+  struct Node* previous // parent of reading node of original tree;
+  struct Node* newNode // writing node of new tree;
+  struct Node* parent;
+  struct Node* grandparent;
+  struct Stack* nodeStack;
+  __code findNodeNext(...)
+  int result;
+} RedBlackTree;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/parallel_execution/plautogen/impl/SemaphoreImpl.h	Sun Nov 24 22:54:35 2019 +0900
@@ -0,0 +1,5 @@
+typedef struct SemaphoreImpl <Type, Isa> impl Semaphore {
+  int value;
+  struct Lock* lock;
+  struct Queue* waitThreadQueue;
+} SemaphoreImpl;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/parallel_execution/plautogen/impl/SingleLinkedQueue.h	Sun Nov 24 22:54:35 2019 +0900
@@ -0,0 +1,4 @@
+typedef struct SingleLinkedQueue <Type, Isa> impl Queue {
+  struct Element* top;
+  struct Element* last;
+} SingleLinkedQueue;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/parallel_execution/plautogen/impl/SpinLock.h	Sun Nov 24 22:54:35 2019 +0900
@@ -0,0 +1,5 @@
+typedef struct SpinLock <Type, Isa> impl Lock {
+  volatile Int* lock;
+  struct Atomic* atomic;
+  struct Context* lockContext;
+} SpinLock;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/parallel_execution/plautogen/impl/SynchronizedQueue.h	Sun Nov 24 22:54:35 2019 +0900
@@ -0,0 +1,5 @@
+typedef struct SynchronizedQueue <Type, Isa> impl Queue {
+  struct Element* top;
+  struct Element* last;
+  struct Atomic* atomic;
+} SynchronizedQueue;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/parallel_execution/plautogen/impl/TaskManagerImpl.h	Sun Nov 24 22:54:35 2019 +0900
@@ -0,0 +1,16 @@
+typedef struct TaskManagerImpl <Type, Isa> impl TaskManager {
+  __code next(...)
+  int numWorker;
+  int sendCPUWorkerIndex;
+  int sendGPUWorkerIndex;
+  int taskCount;
+  pthread_mutex_t mutex;
+  struct Queue* activeQueue;
+  struct Worker** workers;
+  struct Element* taskList;
+  int loopCounter;
+  int cpu;
+  int gpu;
+  int io;
+  int maxCPU;
+} TaskManagerImpl;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/parallel_execution/plautogen/impl/TimerImpl.h	Sun Nov 24 22:54:35 2019 +0900
@@ -0,0 +1,3 @@
+typedef struct TimerImpl <Type, Isa> impl Timer {
+  double time;
+} TimerImpl;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/parallel_execution/plautogen/interface/Allocate.h	Sun Nov 24 22:54:35 2019 +0900
@@ -0,0 +1,4 @@
+typedef struct Allocate <Type, Impl> {
+  __code next(...)
+  long size;
+} Allocate;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/parallel_execution/plautogen/interface/Array.h	Sun Nov 24 22:54:35 2019 +0900
@@ -0,0 +1,4 @@
+typedef struct Array <Type, Impl> {
+  int prefix;
+  Int* array;
+} Array;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/parallel_execution/plautogen/interface/ArrayStack.h	Sun Nov 24 22:54:35 2019 +0900
@@ -0,0 +1,5 @@
+typedef struct ArrayStack <Type, Impl> {
+  int size;
+  int limit;
+  struct Element* array;
+} ArrayStack;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/parallel_execution/plautogen/interface/BoundedBuffer.h	Sun Nov 24 22:54:35 2019 +0900
@@ -0,0 +1,7 @@
+typedef struct BoundedBuffer <Type, Impl> {
+  struct Element* top;
+  struct Element* last;
+  struct Semaphore* fullCount;
+  struct Semaphore* emptyCount;
+  struct Semaphore* lock;
+} BoundedBuffer;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/parallel_execution/plautogen/interface/CPUWorker.h	Sun Nov 24 22:54:35 2019 +0900
@@ -0,0 +1,7 @@
+typedef struct CPUWorker <Type, Impl> {
+  pthread_mutex_t mutex;
+  pthread_cond_t cond;
+  struct Context* context;
+  int id;
+  int loopCounter;
+} CPUWorker;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/parallel_execution/plautogen/interface/CUDABuffer.h	Sun Nov 24 22:54:35 2019 +0900
@@ -0,0 +1,6 @@
+typedef struct CUDABuffer <Type, Impl> {
+  int inputLen;
+  int outputLen;
+  union Data** inputData;
+  union Data** outputData;
+} CUDABuffer;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/parallel_execution/plautogen/interface/Element.h	Sun Nov 24 22:54:35 2019 +0900
@@ -0,0 +1,4 @@
+typedef struct Element <Type, Impl> {
+  union Data* data;
+  struct Element* next;
+} Element;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/parallel_execution/plautogen/interface/Integer.h	Sun Nov 24 22:54:35 2019 +0900
@@ -0,0 +1,3 @@
+typedef struct Integer <Type, Impl> {
+  int value;
+} Integer;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/parallel_execution/plautogen/interface/LoopCounter.h	Sun Nov 24 22:54:35 2019 +0900
@@ -0,0 +1,3 @@
+typedef struct LoopCounter <Type, Impl> {
+  int i;
+} LoopCounter;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/parallel_execution/plautogen/interface/Main.h	Sun Nov 24 22:54:35 2019 +0900
@@ -0,0 +1,5 @@
+typedef struct Main <Type, Impl> {
+  __code code(...)
+  __code next(...)
+  struct Queue* args;
+} Main;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/parallel_execution/plautogen/interface/Memory.h	Sun Nov 24 22:54:35 2019 +0900
@@ -0,0 +1,6 @@
+typedef struct Memory <Type, Impl> {
+  union Data* adr;
+  int length;
+  union Data* body;
+  int hash;
+} Memory;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/parallel_execution/plautogen/interface/Meta.h	Sun Nov 24 22:54:35 2019 +0900
@@ -0,0 +1,6 @@
+typedef struct Meta <Type, Impl> {
+  enum DataType type;
+  long size;
+  long len;
+  struct Queue* wait // tasks waiting this dataGear;
+} Meta;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/parallel_execution/plautogen/interface/MultiDim.h	Sun Nov 24 22:54:35 2019 +0900
@@ -0,0 +1,5 @@
+typedef struct MultiDim <Type, Impl> {
+  int x;
+  int y;
+  int z;
+} MultiDim;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/parallel_execution/plautogen/interface/Node.h	Sun Nov 24 22:54:35 2019 +0900
@@ -0,0 +1,12 @@
+typedef struct Node <Type, Impl> {
+  int key // comparable data segment;
+  union Data* value;
+  struct Node* left;
+  struct Node* right;
+          // need to balancing;
+          enum Color {;
+              Red,;
+              Black,;
+              // Red eq 0,Black eq 1. enum name convert intager.;
+          }color;
+} Node;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/parallel_execution/plautogen/interface/RotateTree.h	Sun Nov 24 22:54:35 2019 +0900
@@ -0,0 +1,5 @@
+typedef struct RotateTree <Type, Impl> {
+  __code next(...)
+  struct RedBlackTree* traverse;
+  struct Tree* tree;
+} RotateTree;
--- a/src/parallel_execution/tmp_tool/parse_cerate_each_context.pl	Sat Nov 23 19:39:11 2019 +0900
+++ b/src/parallel_execution/tmp_tool/parse_cerate_each_context.pl	Sun Nov 24 22:54:35 2019 +0900
@@ -3,6 +3,27 @@
 use warnings;
 use DDP {deparse => 1};
 
+my @already_defined = qw/
+Atomic
+Buffer
+CodeGear
+Executor
+Iterator
+Lock
+Queue
+Semaphore
+Stack
+TaskManager
+Timer
+Tree
+Worker
+SingleLinkedStack
+SortArray
+/;
+
+my %already_defined_hash;
+map { $already_defined_hash{$_}++ } @already_defined;
+
 my $context = shift // "context.h";
 
 open my $fh, '<', $context;
@@ -20,14 +41,107 @@
 while (my $line = shift @context_cg_str) {
   if ($line =~ /\s*struct\s*(\w+)\s*\{/) {
     my $struct = $1;
+    if (exists $already_defined_hash{$struct}) {
+      next;
+    }
     $line = shift @context_cg_str;
     while ($line !~  /\}\s*$struct/) {
         $line =~ s/\s+([\*\w ]+);/$1/;
         push (@{$res->{$struct}},$line);
         $line = shift @context_cg_str ;
     }
+    unless (defined $res->{$struct}) {
+        push (@{$res->{$struct}},"");
+    }
   }
 }
-use Data::Dumper;
+
+map { print "$_\n" } keys %$res;
+my %impl2inter = (
+  SpinLock          => "Lock",
+  CUDAWorker        => "Worker",
+  RedBlackTree      => "Tree",
+  AtomicReference   => "Atomic",
+  CPUWoker          => "Woker",
+  MultiDimIterator  => "Iterator",
+  CUDAExecutor      => "Executor",
+  SingleLinkedStack => "Stack",
+  SingleLinkedQueue => "Queue",
+  SynchronizedQueue => "Queue",
+);
+
+for my $dg_name (keys %$res) {
+  if ($dg_name =~ /(\w+)Impl/) {
+      create_impl_file($dg_name,$res->{$dg_name},$1);
+      next;
+  }
+
+  if (exists $impl2inter{$dg_name}) {
+      create_impl_file($dg_name,$res->{$dg_name},$impl2inter{$dg_name});
+      next;
+  }
+  create_inter_file($dg_name,$res->{$dg_name});
+}
+
+sub create_impl_file {
+  my ($name, $contents,$interface) = @_;
+  my $str = "typedef struct $name <Type, Isa> impl $interface {\n";
+  create_file("impl/$name.h",$contents,$str,$name);
+}
+
+sub create_inter_file {
+  my ($name, $contents) = @_;
+  my $str = "typedef struct $name <Type, Impl> {\n";
+  create_file("interface/$name.h",$contents,$str,$name);
+}
 
-print Dumper  $res;
+sub create_file {
+  my ($file_name, $contents, $str, $name) = @_;
+  my $space = "  ";
+  for my $co (@$contents) {
+    if ($co =~ /enum\s*Code\s*(\w+)/) {
+      $str .= "${space}__code $1(...)\n";
+      next;
+    }
+    chomp $co;
+    $str .= "${space}$co;\n";
+  }
+  open my $fh, '>', "$ENV{PWD}/plautogen/$file_name" or die "oops! $file_name\n";
+  print $fh $str;
+  print $fh "} $name;\n";
+  close $fh;
+}
+
+sub print_impl {
+  my ($out, $name, $cg_info) = @_;
+  print $out "typedef strcut $name<Impl, Bot> {\n";
+}
+
+__DATA__
+SpinLock
+Main
+CUDAExecutor
+TaskManagerImpl
+LockImpl
+MultiDim
+SynchronizedQueue
+ArrayStack
+LoopCounter
+TimerImpl
+Node
+CUDAWorker
+Memory
+SemaphoreImpl
+BoundedBuffer
+RotateTree
+CUDABuffer
+Array
+Allocate
+Meta
+SingleLinkedQueue
+CPUWorker
+Integer
+MultiDimIterator
+Element
+RedBlackTree
+