changeset 1580:806b4658ced6 draft

add multi dimension
author Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
date Fri, 29 Mar 2013 19:32:58 +0900
parents 7418c7aef534
children 8ee897303cd0
files TaskManager/Cell/CellTaskManagerImpl.cc TaskManager/Cell/SpeThreads.cc TaskManager/Gpu/GpuThreads.cc TaskManager/kernel/ppe/CpuThreads.cc TaskManager/kernel/ppe/HTask.cc TaskManager/kernel/ppe/HTask.h TaskManager/kernel/ppe/TaskList.h TaskManager/kernel/schedule/SchedTask.cc example/multiply/main.cc example/multiply/ppe/Multi.cc
diffstat 10 files changed, 107 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/TaskManager/Cell/CellTaskManagerImpl.cc	Mon Mar 25 23:27:04 2013 +0900
+++ b/TaskManager/Cell/CellTaskManagerImpl.cc	Fri Mar 29 19:32:58 2013 +0900
@@ -237,8 +237,10 @@
             send_alloc_reply(this, id, speThreads);
         } else if (data > (memaddr) MY_SPE_NOP) {
 #ifdef TASK_LIST_MAIL
+  	    // multi dimensionだったらカウントする 
             TaskListPtr list = (TaskListPtr)data;
-            check_task_list_finish(schedTaskManager, list, waitTaskQueue);
+	    if (list->tasks[0].self->flag.dim_count-- == 0)
+	        check_task_list_finish(schedTaskManager, list, waitTaskQueue);
 #else
             // 終了したタスク(PPEにあるのでアドレス)
             HTaskPtr task = (HTaskPtr) data;
@@ -330,7 +332,7 @@
     tmp->getLast()->next = 0;
     TaskListPtr p = tmp->getFirst();
     // printf("SPE %d task list sending\n",id);
-    speThreads->send_mail(id, 1, (memaddr *) &p);
+    speThreads->spawn_task(id, p);
     // printf("SPE %d task list sent\n",id);
 }
 
--- a/TaskManager/Cell/SpeThreads.cc	Mon Mar 25 23:27:04 2013 +0900
+++ b/TaskManager/Cell/SpeThreads.cc	Fri Mar 29 19:32:58 2013 +0900
@@ -103,6 +103,19 @@
     }
 }
 
+void
+SpeThreads::spawn_task(int cpu_num, TaskListPtr p) {
+    if (p->dim>0) {
+      int dim_count = (x+1)*(y+1)*(z+1);
+      if (cpu_num > dim_count)
+        p->tasks[0].self->dim_count = cpu_num;
+        for (int i = 0; i < cpu_num; i++) {
+	  send_mail(i+1,1,(memaddr)&p);
+	}
+    } else {
+        send_mail(cpu_num,1,(memaddr)&p);
+    }
+}
 
 /**
  * SPE からのメールを受信する。
@@ -149,7 +162,6 @@
  */
 void
 SpeThreads::send_mail(int speid, int num, memaddr *data)
-
 {
     spe_in_mbox_write(spe_ctx[speid], (unsigned int *)data, num*(sizeof(memaddr)/sizeof(int)), SPE_MBOX_ALL_BLOCKING);
 }
--- a/TaskManager/Gpu/GpuThreads.cc	Mon Mar 25 23:27:04 2013 +0900
+++ b/TaskManager/Gpu/GpuThreads.cc	Fri Mar 29 19:32:58 2013 +0900
@@ -61,6 +61,11 @@
     return NULL;
 }
 
+void
+GpuThreads::spawn_task(int id, TaskListPtr p) {
+    send_mail(id, 1, (memaddr)&p);
+}
+
 int
 GpuThreads::get_mail(int speid, int count, memaddr *ret)
 {
--- a/TaskManager/kernel/ppe/CpuThreads.cc	Mon Mar 25 23:27:04 2013 +0900
+++ b/TaskManager/kernel/ppe/CpuThreads.cc	Fri Mar 29 19:32:58 2013 +0900
@@ -101,6 +101,20 @@
     gpu->set_NDRange(ndr);
 }
 
+void
+CpuThreads::spawn_task(int cpu_num, TaskListPtr p) {
+    if (p->dim>0) {
+      int dim_count = (x+1)*(y+1)*(z+1);
+      if (cpu_num > dim_count)
+        p->tasks[0].self->dim_count = cpu_num;
+        for (int i = 0; i < cpu_num; i++) {
+	  send_mail(i+1,1,(memaddr)&p);
+	}
+    } else {
+        send_mail(cpu_num,1,(memaddr)&p);
+    }
+}
+
 /**
  * このCPU からのメールを受信する。
  *
--- a/TaskManager/kernel/ppe/HTask.cc	Mon Mar 25 23:27:04 2013 +0900
+++ b/TaskManager/kernel/ppe/HTask.cc	Fri Mar 29 19:32:58 2013 +0900
@@ -3,7 +3,7 @@
 #include "TaskManagerImpl.h"
 #include "strings.h"
 #include "rdtsc.h"
-
+#include "Dim.h"
 
 /*!
   manager->set_task_depend(task1, task2); // task2 は task1 の終了を待つ
@@ -28,6 +28,30 @@
     mimpl->spawn_task(this);
 }
 
+void
+HTask::iterate(long x) {
+    TaskList *tl = (TaskList*)rbuf;
+    tl->dim=1;
+    tl->x=x;
+}
+
+void
+HTask::iterate(long x, long y) {
+    TaskList *tl = (TaskList*)rbuf;
+    tl->dim=2;
+    tl->x=x;
+    tl->y=y;
+}
+
+void
+HTask::iterate(long x, long y, long z) {
+    TaskList *tl = (TaskList*)rbuf;
+    tl->dim=3;
+    tl->x=x;
+    tl->y=y;
+    tl->z=z;
+}
+
 /*!
   @brief この Task が待ち合わせする Task を指定する
   @param[in] master この Task が終了待ち合わせをする相手の Task
@@ -134,6 +158,13 @@
         last = task->next();
         return task;
     }
+    Task *next=get_nextTaskArea(t,tl);
+    last = next->next();
+    next->init(id, param_count, inData_count, outData_count);
+    return next;
+}
+
+Task *get_nextTaskArea(Task *t, TaskList *tl) {
     Task *next = t->next();
     if (next >= tl->last()) {
         tl->set_last(t);
@@ -145,11 +176,9 @@
         tl->self = 0;
         rbuf = (memaddr)tl;
     } 
-    next->init(id, param_count, inData_count, outData_count);
-    last = next->next();
+
     return next;
 }
-
 /*!
   @brief Task Array の中のすべてのTaskが書き込まれたかどうかをチェックする
          TaskArray 自体の spawn() は別に必要
--- a/TaskManager/kernel/ppe/HTask.h	Mon Mar 25 23:27:04 2013 +0900
+++ b/TaskManager/kernel/ppe/HTask.h	Fri Mar 29 19:32:58 2013 +0900
@@ -54,9 +54,11 @@
         unsigned no_auto_free:1;        //      bit 0    auto free flag (0 .. auto, 1 manual)
         unsigned flip:1;                //      use read write buffers for all
         unsigned nd_range:1;            //      openCL nd_range
+        unsigned dim_count:8; // count finished cpu on multi dim execution
     } flag;
 
     void spawn();
+    void iterate(long x); // spawn x tasks with paramtor0 as index
     void wait_for(HTask *);
     void set_cpu(CPU_TYPE type);
     void set_post(PostFunction func, void *read, void *write);
--- a/TaskManager/kernel/ppe/TaskList.h	Mon Mar 25 23:27:04 2013 +0900
+++ b/TaskManager/kernel/ppe/TaskList.h	Fri Mar 29 19:32:58 2013 +0900
@@ -17,7 +17,7 @@
     TaskList *prev; // 4 byte
     TaskList *waiter; // 4 byte
     HTask *self; // 4 byte
-    long dummy[3]; // 16 byte
+    int dim,x,y,z; // 16 byte
     Task tasks[TASK_MAX_SIZE]; // 32*TASK_MAX_SIZE
     
 
--- a/TaskManager/kernel/schedule/SchedTask.cc	Mon Mar 25 23:27:04 2013 +0900
+++ b/TaskManager/kernel/schedule/SchedTask.cc	Fri Mar 29 19:32:58 2013 +0900
@@ -113,7 +113,12 @@
     }
     connector->dma_wait((DMA_READ + this->tag));
     void *read = get_input(readbuf, 0); void *write =  get_output(writebuf, 0);
-    run(this, read,write);
+    // set param (if exit dim )
+    if (list->dim) {
+        multi_dimension(list, read, write);
+    } else {
+        run(this, read,write);
+    }
     connector->free_(readbuf);
     // User 側で作る方法が必要...
     // 書き込む領域がなければ無視
@@ -124,6 +129,29 @@
 }
 
 void
+SchedTask::multi_dimension(TaskListPtr list, void* read, void* write,run) {
+    // 自分のidはSchedulerがわかる
+    int x=0,y=0,z=0;
+    for (;;) {
+      if (cpu==scheduler->cpu) {
+	if (list->dim>0) set_param(0,(memaddr)x);
+	if (list->dim>1) set_param(1,(memaddr)y);
+	if (list->dim>2) set_param(2,(memaddr)z);
+	  run(this, read,write);
+      }
+      if (++x>list->x) {
+	  x=0;
+  	  if (++y>list->y) {
+	    y=0;
+	      if (++z>list->z) {
+		break;		
+	      }
+	  }
+	  cpu++;
+    }
+}
+
+void
 SchedTask::write()
 {
     __debug("[SchedTask:%s]\n", __FUNCTION__);
@@ -150,7 +178,7 @@
         nextSched->init(list, &list->tasks[0], scheduler, this->tag^1);
         return nextSched;
     }
-    TaskPtr nextTask = cur_index->next();
+    TaskPtr nextTask = cur_index->next(); // ここで一個一個のtaskを取ってきてる
     if (nextTask < list->last()) {
         // Task List が残っているので、次を準備
 
--- a/example/multiply/main.cc	Mon Mar 25 23:27:04 2013 +0900
+++ b/example/multiply/main.cc	Fri Mar 29 19:32:58 2013 +0900
@@ -81,12 +81,12 @@
     //    manager->set_NDRange(ndr);
 
     multiply = manager->create_task(MULTIPLY_TASK);
-    multiply->nd_range();
     multiply->set_cpu(spe_cpu);
 
     /**
      * Set of Input Data
      *   add_inData(address of input data, size of input data);
+     * 単一のtaskを渡してscheduler側でiterをまわした方がよい
      */
     multiply->set_inData(0,(memaddr)A, sizeof(float)*length);
     multiply->set_inData(1,(memaddr)B, sizeof(float)*length);
@@ -97,14 +97,9 @@
      */
     multiply->set_outData(0,(memaddr)C, sizeof(float)*length);
 
-    /**
-     * Set 32bits parameter
-     *   add_param(32bit parameter);
-     */
-    multiply->set_param(0, (memaddr)length);
+    // param 0に0~length-1をsetしたtaskをlength個spawnする
+    multiply->iterate(length); 
     
-    // add Active Queue
-    multiply->spawn();
 }
 
 
--- a/example/multiply/ppe/Multi.cc	Mon Mar 25 23:27:04 2013 +0900
+++ b/example/multiply/ppe/Multi.cc	Fri Mar 29 19:32:58 2013 +0900
@@ -16,10 +16,8 @@
     B = (float*)s->get_input(rbuf, 1);
     C = (float*)s->get_output(wbuf, 0);
 
-    long length = (long)s->get_param(0);
-    for (int i=0; i<length; i++) {
-        C[i]=A[i]*B[i];
-    }
+    long i = (long)s->get_param(0);
+    C[i]=A[i]*B[i];
     
     return 0;
 }