changeset 1738:893353c014f5 draft

run sort by ANY_ANY
author Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
date Sun, 03 Nov 2013 19:00:45 +0900
parents 6bd9a57eb44d
children dfeeb2f681db
files example/fft/gpu/spinFact.cl example/fft/output.pgm example/many_task/Makefile.def example/many_task/Makefile.gpu example/many_task/Makefile.macosx example/many_task/gpu/QuickSort.cc example/many_task/gpu/QuickSort.h example/many_task/gpu/task_init.cc example/many_task/main.cc example/many_task/ppe/task_init.cc example/many_task/task_init.cc
diffstat 11 files changed, 162 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/example/fft/gpu/spinFact.cl	Sat Nov 02 17:34:40 2013 +0900
+++ b/example/fft/gpu/spinFact.cl	Sun Nov 03 19:00:45 2013 +0900
@@ -10,7 +10,6 @@
     float2 angle;
     angle.x = (float)(2*i*PI/(float)n);
     angle.y = (float)((2*i*PI/(float)n) + PI_2);
-
     w[i].x = cos(angle.x);
     w[i].y = cos(angle.y);
 }
Binary file example/fft/output.pgm has changed
--- a/example/many_task/Makefile.def	Sat Nov 02 17:34:40 2013 +0900
+++ b/example/many_task/Makefile.def	Sun Nov 03 19:00:45 2013 +0900
@@ -14,7 +14,7 @@
 CFLAGS  =  -Wall  $(OPT) -DUSE_SIMPLE_TASK
 CXXFLAGS  = ${CFLAGS}
 
-INCLUDE = -I${CERIUM}/include/TaskManager -I. -I..
+INCLUDE =  -I. -I.. -I${CERIUM}/include/TaskManager
 LIBS = -L${CERIUM}/TaskManager
 
 ABIBIT = 64
--- a/example/many_task/Makefile.gpu	Sat Nov 02 17:34:40 2013 +0900
+++ b/example/many_task/Makefile.gpu	Sun Nov 03 19:00:45 2013 +0900
@@ -14,7 +14,6 @@
 CC += $(ABI)
 CFLAGS  += -D__CERIUM_GPU__
 
-INCLUDE = -I${CERIUM}/include/TaskManager -I. -I..
 LIBS = -L${CERIUM}/TaskManager -DUSE_SIMPLE_TASK -lGpuManager -framework opencl `sdl-config --libs`
 
 .SUFFIXES: .cc .o
--- a/example/many_task/Makefile.macosx	Sat Nov 02 17:34:40 2013 +0900
+++ b/example/many_task/Makefile.macosx	Sun Nov 03 19:00:45 2013 +0900
@@ -16,7 +16,7 @@
 CC += $(ABI)
 # CFLAGS  = -g -Wall# -O9 #-DDEBUG
 
-INCLUDE = -I${CERIUM}/include/TaskManager -I. -I..
+INCLUDE =  -I. -I.. -I${CERIUM}/include/TaskManager
 LIBS = -L${CERIUM}/TaskManager -lFifoManager `sdl-config --libs`
 
 .SUFFIXES: .cc .o
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/many_task/gpu/QuickSort.cc	Sun Nov 03 19:00:45 2013 +0900
@@ -0,0 +1,103 @@
+#include "QuickSort.h"
+#include <stdio.h>
+#include <string.h>
+
+SchedDefineTask(QuickSort);
+
+static void quick_sort( Data *data, int begin, int end ) ;
+
+static void
+swap( Data *data, int left, int right )
+{
+    Data tmp    = data[left];
+    data[left]  = data[right];
+    data[right] = tmp;
+}
+
+//#define USE_MEMCPY
+
+void
+bubble_sort(Data *data, int begin, int end)
+{
+    for (int count=0;count<end;count++) {
+        for (int c=end;c>count;c--) {
+            if (data[c].index<data[c-1].index)swap(data,c-1,c);
+        }
+    }
+}
+static int
+run(SchedTask *s, void* rbuff, void* wbuff) {
+    // copy value
+    int begin  = 0;
+#if USE_SIMPLE_TASK
+    int end = s->read_size()/sizeof(Data);
+    Data *r_data = (Data*)rbuff;
+#ifdef USE_MEMCPY
+    Data *w_data = (Data*)wbuff;
+#endif
+#else
+    int end = s->get_inputSize(0)/sizeof(Data);
+    DataPtr r_data = (DataPtr)s->get_input(0);
+#ifdef USE_MEMCPY
+    DataPtr w_data = (DataPtr)s->get_output(0);
+#endif
+#endif
+
+    // printf("[PPE] Quick: length:%d addr->%x \n",end, (int)rbuff);
+    // printf("[PPE] Quick: data[0]: %ld addr->%lx\n",sizeof(r_data),(long)r_data);
+
+    quick_sort(r_data, begin, end);
+
+#ifdef USE_MEMCPY
+    memcpy(w_data, r_data, sizeof(Data)*end);
+#else
+    s->swap();
+#endif
+
+    return 0;
+}
+
+void
+qsort_test(Data *data, int begin, int end ) {
+    quick_sort(data, begin, end-1);
+}
+
+static void
+quick_sort( Data *data, int begin, int end ) {
+    int stack[1024];
+    int sp = 0;
+    int p;
+
+    while (1) {
+        while (begin < end) {
+
+            if (end-begin <= 50) {
+                //bubble_sort(data, begin, end);
+                //break;
+            }
+
+            int where = (begin + end) / 2;
+            int pivot = data[where].index;
+            data[where].index = data[begin].index;
+            int i;
+            p = begin;
+            for (i=begin+1; i<=end; i++) {
+                if (data[i].index < pivot) {
+                    p++;
+                    swap(data, p, i);
+                }
+            }
+            data[begin].index = data[p].index;
+            data[p].index = pivot;
+
+            stack[sp++] = p + 1;
+            stack[sp++] = end;
+            end = p - 1;
+        }
+        if (sp == 0) return;
+        end = stack[--sp];
+        begin = stack[--sp];
+        begin = p + 1;
+        }
+}
+/* end */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/many_task/gpu/QuickSort.h	Sun Nov 03 19:00:45 2013 +0900
@@ -0,0 +1,10 @@
+#ifndef INCLUDED_TASK_QUICKSORT
+#define INCLUDED_TASK_QUICKSORT
+
+#ifndef INCLUDED_SCHED_TASK
+#  include "SchedTask.h"
+#endif
+
+#include "sort.h"
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/many_task/gpu/task_init.cc	Sun Nov 03 19:00:45 2013 +0900
@@ -0,0 +1,21 @@
+#include "Func.h"
+#include "Scheduler.h"
+#include "GpuScheduler.h"
+
+SchedExternTask(QuickSort);
+SchedExternTask(SortSimple);
+SchedExternTask(SortCompat);
+
+void
+task_init(void)
+{
+    SchedRegister(SortSimple);
+    SchedRegisterTask(QUICK_SORT, QuickSort);
+    //    SchedRegister(SortCompat);
+}
+
+void
+gpu_task_init(void)
+{
+    GpuSchedRegister(QUICK_SORT,"gpu/QuickSort.cl","quick_sort");
+}
--- a/example/many_task/main.cc	Sat Nov 02 17:34:40 2013 +0900
+++ b/example/many_task/main.cc	Sun Nov 03 19:00:45 2013 +0900
@@ -9,6 +9,7 @@
 #include "sort.h"
 
 extern void task_init();
+extern void gpu_task_init();
 extern int get_split_num(int len, int num);
 
 
@@ -67,6 +68,9 @@
             use_task_array = 1;
             
         }
+        if (strcmp(argv[i], "-any") == 0 ) {
+            spe_cpu = ANY_ANY;
+        }
     }
 
     return 0;
@@ -146,6 +150,7 @@
     }
 
     task_init();
+    gpu_task_init();
 
     int cpu  = manager->get_cpuNum();
     // in case of -cpu 0
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/many_task/ppe/task_init.cc	Sun Nov 03 19:00:45 2013 +0900
@@ -0,0 +1,21 @@
+#include "Func.h"
+#include "Scheduler.h"
+#include "GpuScheduler.h"
+
+SchedExternTask(QuickSort);
+SchedExternTask(SortSimple);
+SchedExternTask(SortCompat);
+
+void
+task_init(void)
+{
+    SchedRegisterTask(QUICK_SORT, QuickSort);
+    SchedRegister(SortSimple);
+    //    SchedRegister(SortCompat);
+}
+
+void
+gpu_task_init(void)
+{
+
+}
--- a/example/many_task/task_init.cc	Sat Nov 02 17:34:40 2013 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,23 +0,0 @@
-#include "Func.h"
-#include "Scheduler.h"
-#include "GpuScheduler.h"
-
-#ifndef __CERIUM_GPU__
-SchedExternTask(QuickSort);
-#endif // __CERIUM_GPU__
-SchedExternTask(SortSimple);
-SchedExternTask(SortCompat);
-
-void
-task_init(void)
-{
-#ifdef __CERIUM_GPU__
-    GpuSchedRegister(QUICK_SORT, "gpu/QuickSort.cl", "quick_sort");
-#else
-    SchedRegisterTask(QUICK_SORT, QuickSort);
-#endif
-
-
-    SchedRegister(SortSimple);
-    //    SchedRegister(SortCompat);
-}