changeset 1799:d9122ca02431 draft

Exec wordcount by Data Parallel
author Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
date Fri, 06 Dec 2013 05:30:43 +0900
parents 3babb36ac459
children 9a1ba9cb9557
files example/regex_mas/main.cc example/word_count/Func.h example/word_count/WordCount.h example/word_count/main.cc example/word_count/task_init.cc
diffstat 5 files changed, 54 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/example/regex_mas/main.cc	Thu Dec 05 16:41:38 2013 +0900
+++ b/example/regex_mas/main.cc	Fri Dec 06 05:30:43 2013 +0900
@@ -260,7 +260,7 @@
 
     /* out用のdivision_size. statusが2つなので、あわせて16byteになるように、long long(4byte)を使用 */
 
-    w->division_out_size = sizeof(unsigned long long)*1;
+    w->division_out_size = sizeof(unsigned long long)*2;
     int out_size = w->division_out_size*out_task_num;
     w->o_data = (unsigned long long *)manager->allocate(out_size);
     w->out_size = 1;
@@ -271,14 +271,15 @@
                                    (memaddr)&w->self,sizeof(memaddr),0,0);
     w->t_print = t_print;
 
-    for(int i = 0;i<2;i++) {
+    //    for(int i = 0;i<2;i++) {
         /* Task を task_blocks ずつ起動する Task */
         /* serialize されていると仮定する... */
         HTaskPtr t_exec = manager->create_task(RUN_TASK_BLOCKS,
                                                (memaddr)&w->self,sizeof(memaddr),0,0);
         t_print->wait_for(t_exec);
-        t_exec->spawn();
-    }
+        t_exec->iterate(2);
+        //        t_exec->spawn();
+        //    }
 
     t_print->spawn();
 }
--- a/example/word_count/Func.h	Thu Dec 05 16:41:38 2013 +0900
+++ b/example/word_count/Func.h	Fri Dec 06 05:30:43 2013 +0900
@@ -1,6 +1,7 @@
 enum {
 #include "SysTasks.h"
     TASK_EXEC,
+    TASK_EXEC_DATA_PARALLEL,
     RUN_TASK_BLOCKS,
     TASK_PRINT,
 };
--- a/example/word_count/WordCount.h	Thu Dec 05 16:41:38 2013 +0900
+++ b/example/word_count/WordCount.h	Fri Dec 06 05:30:43 2013 +0900
@@ -5,6 +5,7 @@
     int division_size;    // for each word count task
     int division_out_size;    
     int out_size;    
+    int out_size_;
     int task_num;         // remaining task count
     int task_blocks;      // spawn task one at a time
     int status_num; 
--- a/example/word_count/main.cc	Thu Dec 05 16:41:38 2013 +0900
+++ b/example/word_count/main.cc	Fri Dec 06 05:30:43 2013 +0900
@@ -24,6 +24,7 @@
 int use_task_array = 1;
 int use_task_creater = 0;
 int use_compat = 0;
+int use_iterate = 0;
 int array_task_num = 8;
 int spe_num = 1;
 CPU_TYPE spe_cpu = SPE_ANY;
@@ -95,9 +96,8 @@
         array_task_num = task_count;
         if (task_count<=0) return;
     }
-  
+    
     for (int i = 0; i < task_count; i += array_task_num) {
-        
         HTask *task_array;
         if (use_task_array) {
             int task_num = (w->size+size-1)/size;
@@ -124,11 +124,46 @@
                 h_exec = manager->create_task(TASK_EXEC);
                 h_exec->set_inData(0,w->file_mmap + i*w->division_size, size);
                 h_exec->set_outData(0,w->o_data + i*w->out_size, w->division_out_size);
-
+                
                 t_next->wait_for(h_exec);
 
                 h_exec->set_cpu(spe_cpu);
                 h_exec->spawn();
+            } else if (use_iterate) {
+                w->size -= size*array_task_num;
+                if(w->size < 0) array_task_num -= 1;
+                h_exec = manager->create_task(TASK_EXEC_DATA_PARALLEL);
+                h_exec->set_inData(0,w->file_mmap,w->file_size);
+                h_exec->set_outData(0,w->o_data,w->out_size_);
+                h_exec->set_param(0,(long)i);
+                h_exec->set_param(1,(long)w->division_size);
+                h_exec->set_param(2,(long)size);
+                h_exec->set_param(3,(long)w->out_size);
+
+                t_next->wait_for(h_exec);
+                h_exec->set_cpu(spe_cpu);
+                h_exec->iterate(array_task_num);
+                
+                w->task_num -= array_task_num;
+                w->task_spwaned += array_task_num-1;
+                
+                if(w->size < 0) {
+                    h_exec = manager->create_task(TASK_EXEC_DATA_PARALLEL);
+                    h_exec->set_inData(0,w->file_mmap,w->file_size);
+                    h_exec->set_outData(0,w->o_data,w->out_size_);
+                    h_exec->set_param(0,(long)w->task_spwaned);
+                    h_exec->set_param(1,(long)w->division_size);
+                    h_exec->set_param(2,(long)(size+w->size));
+                    h_exec->set_param(3,(long)w->out_size);
+                    
+                    t_next->wait_for(h_exec);
+                    h_exec->set_cpu(spe_cpu);
+                    h_exec->iterate(1);
+                    w->task_num -= 1;
+                    w->task_spwaned += 1;
+                    array_task_num += 1;
+                }
+                break;
             } else {
                 h_exec = manager->create_task(TASK_EXEC,
                                               (memaddr)(w->file_mmap + i*w->division_size), size,
@@ -174,7 +209,7 @@
         HTaskPtr t_next = manager->create_task(RUN_TASK_BLOCKS,
                                                (memaddr)&w->self,sizeof(memaddr),0,0);
         w->t_print->wait_for(t_next);
-
+        
         run_tasks(manager,w, w->task_blocks, t_next, w->division_size);
 
         t_next->spawn();
@@ -238,6 +273,7 @@
     w->division_out_size = sizeof(unsigned long long)*4;
     int out_size = w->division_out_size*out_task_num;
     w->o_data = (unsigned long long *)manager->allocate(out_size);
+    w->out_size_ = out_size;
     w->out_size = 4;
     printf("out size %d\n",out_size);
 
@@ -251,9 +287,9 @@
         /* Task を task_blocks ずつ起動する Task */
         /* serialize されていると仮定する... */
         HTaskPtr t_exec = manager->create_task(RUN_TASK_BLOCKS,
-                                           (memaddr)&w->self,sizeof(memaddr),0,0);
+                                               (memaddr)&w->self,sizeof(memaddr),0,0);
         t_print->wait_for(t_exec);
-        //t_exec->iterate(4);
+        //    t_exec->iterate(4);
         t_exec->spawn();
     }
     t_print->spawn();
@@ -292,6 +328,9 @@
             i++;
         } else if (strcmp(argv[i], "-g") == 0 ) {
             spe_cpu = GPU_0;
+        } else if (strcmp(argv[i], "-i") == 0) {
+            use_iterate = 1;
+            use_task_array = 0;
         }/* else if (strcmp(argv[i], "-cpu") == 0) {
             spe_num = atoi(argv[i+1]);
             i++;
--- a/example/word_count/task_init.cc	Thu Dec 05 16:41:38 2013 +0900
+++ b/example/word_count/task_init.cc	Fri Dec 06 05:30:43 2013 +0900
@@ -4,6 +4,7 @@
 
 /* 必ずこの位置に書いて */
 SchedExternTask(Exec);
+SchedExternTask(Exec_Data_Prallel);
 SchedExternTask(Print);
 SchedExternTask(RUN_TASK_BLOCKS);
 
@@ -19,6 +20,7 @@
     GpuSchedRegister(TASK_EXEC, "gpu/Exec.cl", "wordcount");
 #endif
     SchedRegisterTask(TASK_EXEC, Exec);
+    SchedRegisterTask(TASK_EXEC_DATA_PARALLEL, Exec_Data_Prallel);
 
     SchedRegisterTask(TASK_PRINT, Print);
     SchedRegister(RUN_TASK_BLOCKS);