changeset 1482:85a848d7f181 draft

fix CpuThreads
author Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
date Wed, 01 Aug 2012 21:37:29 +0900
parents a9da5c6bea91
children f402f6444237
files TaskManager/Cell/CellTaskManagerImpl.cc TaskManager/Gpu/GpuScheduler.cc TaskManager/Gpu/GpuScheduler.h TaskManager/Gpu/GpuThreads.cc TaskManager/Gpu/GpuThreads.h TaskManager/kernel/ppe/CpuThreads.cc TaskManager/kernel/ppe/CpuThreads.h TaskManager/kernel/ppe/TaskManagerImpl.cc TaskManager/test/GpuRunTest/GpuRunTest.cc TaskManager/test/GpuRunTest/twice.cl example/OpenCL/twice.cl
diffstat 11 files changed, 63 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/TaskManager/Cell/CellTaskManagerImpl.cc	Tue Jul 31 19:12:41 2012 +0900
+++ b/TaskManager/Cell/CellTaskManagerImpl.cc	Wed Aug 01 21:37:29 2012 +0900
@@ -371,7 +371,7 @@
 #ifdef __CERIUM_CELL__
     Threads *cpus = new SpeThreads(num);
 #elif __CERIUM_GPU__    
-    Threads *cpus = new GpuThreads(num, useRefDma);
+    Threads *cpus = new CpuThreads(num, useRefDma);
 #else    
     Threads *cpus = new CpuThreads(num, useRefDma);
 #endif
--- a/TaskManager/Gpu/GpuScheduler.cc	Tue Jul 31 19:12:41 2012 +0900
+++ b/TaskManager/Gpu/GpuScheduler.cc	Wed Aug 01 21:37:29 2012 +0900
@@ -1,5 +1,6 @@
 #include "GpuScheduler.h"
 #include "ReferencedDmaManager.h"
+#include "PreRefDmaManager.h"
 #include "SchedTask.h"
 #include "stdio.h"
 #include <fcntl.h>
@@ -14,7 +15,13 @@
 void
 GpuScheduler::init_impl(int useRefDma)
 {
-    fifoDmaManager = new ReferencedDmaManager();
+    if (useRefDma & 0x10) {
+        fifoDmaManager = new PreRefDmaManager();
+    } else if (useRefDma & 0x01) {
+        fifoDmaManager = new FifoDmaManager();
+    } else {
+        fifoDmaManager = new ReferencedDmaManager();
+    }
     connector = fifoDmaManager;
 }
 
@@ -54,6 +61,7 @@
                                                                     sizeof(TaskList), DMA_READ_TASKLIST);
 
 
+
             for (TaskPtr nextTask = tasklist->tasks; nextTask < tasklist->last(); nextTask = nextTask->next()) {
                 cl_kernel& kernel = *task_list[nextTask->command].kernel;
                 int err = CL_SUCCESS;
--- a/TaskManager/Gpu/GpuScheduler.h	Tue Jul 31 19:12:41 2012 +0900
+++ b/TaskManager/Gpu/GpuScheduler.h	Wed Aug 01 21:37:29 2012 +0900
@@ -22,7 +22,7 @@
     void regist_task(int cmd,const char* filename,const char* functionname);
     
     void mail_write_from_host(memaddr data) {
-	fifoDmaManager->mail_write_from_host(data);
+        fifoDmaManager->mail_write_from_host(data);
     }
 
     memaddr mail_read_from_host() {
--- a/TaskManager/Gpu/GpuThreads.cc	Tue Jul 31 19:12:41 2012 +0900
+++ b/TaskManager/Gpu/GpuThreads.cc	Wed Aug 01 21:37:29 2012 +0900
@@ -3,10 +3,11 @@
 #include "TaskManagerImpl.h"
 #include "SpeTaskManagerImpl.h"
 
-GpuThreads::GpuThreads()
+
+GpuThreads::GpuThreads(int useRefDma) : use_refdma(useRefDma)
 {
     threads = new pthread_t;
-    args = new gpu_arg;
+    args = new gpu_thread_arg_t;
 }
 
 GpuThreads::~GpuThreads()
@@ -17,28 +18,35 @@
 }
 
 void
+GpuThreads::set_wait(SemPtr wait)
+{
+    args->wait=wait;
+}
+
+void
 GpuThreads::init()
 {
-
     args->scheduler = new GpuScheduler();    
     args->useRefDma = use_refdma;
 
     pthread_create(threads, NULL, &gpu_thread_run, args);
-
+    
+    
 }
 
 void *
 GpuThreads::gpu_thread_run(void *args)
 {
-    gpu_arg *argt = (gpu_arg *) args;
+    gpu_thread_arg_t *argt = (gpu_thread_arg_t *) args;
     Scheduler *g_scheduler = argt->scheduler;
     
     TaskManagerImpl *manager = new SpeTaskManagerImpl();
     g_scheduler->init(manager, argt->useRefDma);
     
-    
     manager->set_scheduler(g_scheduler);
 
+    argt->wait->sem_v();
+
     g_scheduler->run();
     g_scheduler->finish();
 
--- a/TaskManager/Gpu/GpuThreads.h	Tue Jul 31 19:12:41 2012 +0900
+++ b/TaskManager/Gpu/GpuThreads.h	Wed Aug 01 21:37:29 2012 +0900
@@ -4,6 +4,7 @@
 #include <pthread.h>
 #include "Threads.h"
 #include "GpuScheduler.h"
+#include "Sem.h"
 
 #ifdef __APPLE__
 #include <OpenCL/opencl.h>
@@ -13,10 +14,14 @@
 
 class GpuScheduler;
 
-struct gpu_arg {
+typedef struct gpu_arg {
+    int cpuid;
+    // should be syncrhonized
     GpuScheduler *scheduler;
-    int useRefDma;
-};
+    TaskManagerImpl *manager;
+    SemPtr wait;
+	int useRefDma;
+} gpu_thread_arg_t;
 
 class GpuThreads : public Threads {
  public:
@@ -25,7 +30,7 @@
       static GpuThreads singleton;
       return &singleton;
       }*/
-    GpuThreads();
+    GpuThreads(int useRefDma);
     ~GpuThreads();
     
     void init();
@@ -35,13 +40,14 @@
     int has_mail(int speid, int count, memaddr *ret);
     void send_mail(int speid, int num, memaddr *data);
     void add_output_tasklist(int command, memaddr buff, int alloc_size);
-    
+    void set_wait(SemPtr);
+
  public:
     
     
 
 private:
-    gpu_arg *args;
+    gpu_thread_arg_t *args;
     pthread_t *threads;
     int use_refdma;
 };
--- a/TaskManager/kernel/ppe/CpuThreads.cc	Tue Jul 31 19:12:41 2012 +0900
+++ b/TaskManager/kernel/ppe/CpuThreads.cc	Wed Aug 01 21:37:29 2012 +0900
@@ -1,12 +1,17 @@
 #include <stdlib.h>
 #include "types.h"
 #include "CpuThreads.h"
+#ifdef __CERIUM_GPU__
+#include "GpuThreads.h"
+#endif
+#include "GpuThreads.h"
 #include "MainScheduler.h"
 #include "SysFunc.h"
 #include "SchedNop.h"
 #include "SpeTaskManagerImpl.h"
 #include "CellScheduler.h"
 
+
 SchedExternTask(ShowTime);
 SchedExternTask(StartProfile);
 
@@ -14,7 +19,7 @@
 CpuThreads::CpuThreads(int num, int useRefDma, int start_id) : cpu_num(num), use_refdma(useRefDma), id_offset(start_id) {
 
 #ifdef __CERIUM_GPU__
-    gpu = new GpuThreads();
+    gpu = new GpuThreads(useRefDma);
 #endif
     threads = new pthread_t[cpu_num];
     args    = new cpu_thread_arg_t[cpu_num];
@@ -72,6 +77,12 @@
 //CpuThreads::init()
 CpuThreads::init()
 {
+#ifdef __CERIUM_GPU__
+    gpu->set_wait(wait);
+    gpu->init();
+    wait->sem_p();
+#endif
+
 	for (int i = 0; i < cpu_num; i++) {
 		args[i].cpuid = i + id_offset;
 		args[i].scheduler = new MainScheduler();
--- a/TaskManager/kernel/ppe/CpuThreads.h	Tue Jul 31 19:12:41 2012 +0900
+++ b/TaskManager/kernel/ppe/CpuThreads.h	Wed Aug 01 21:37:29 2012 +0900
@@ -6,9 +6,7 @@
 #include "TaskManagerImpl.h"
 #include "MainScheduler.h"
 #include "Sem.h"
-#ifdef __CERIUM_GPU__
-#include "GpuThreads.h"
-#endif
+
 typedef struct cpu_arg {
     int cpuid;
     // should be syncrhonized
@@ -18,6 +16,8 @@
 	int useRefDma;
 } cpu_thread_arg_t;
 
+class GpuThreads;
+
 class CpuThreads : public Threads {
  public:
     /* constructor */
--- a/TaskManager/kernel/ppe/TaskManagerImpl.cc	Tue Jul 31 19:12:41 2012 +0900
+++ b/TaskManager/kernel/ppe/TaskManagerImpl.cc	Wed Aug 01 21:37:29 2012 +0900
@@ -372,7 +372,7 @@
 {
     if (_export_task_log)
         htask->tasklog->execute_time = rdtsc();
-
+    
     TaskListPtr tl = (TaskList*)htask->rbuf;
     while(tl->prev) tl=tl->prev;
     while(tl) {
--- a/TaskManager/test/GpuRunTest/GpuRunTest.cc	Tue Jul 31 19:12:41 2012 +0900
+++ b/TaskManager/test/GpuRunTest/GpuRunTest.cc	Wed Aug 01 21:37:29 2012 +0900
@@ -52,13 +52,12 @@
     
     HTaskPtr schedtask = manager->create_task(SchedRun);
 
+    schedtask->set_param(0, length);
     schedtask->set_inData(0, indata, sizeof (int)*length);
-    schedtask->set_outData(1, outdata, sizeof (int)*length);
-    schedtask->set_inData(2, &count, sizeof (int));
+    schedtask->set_outData(0, outdata, sizeof (int)*length);
     schedtask->set_cpu(GPU_0);
     schedtask->spawn();
     
-    gpu->run();
 }
 
 void
--- a/TaskManager/test/GpuRunTest/twice.cl	Tue Jul 31 19:12:41 2012 +0900
+++ b/TaskManager/test/GpuRunTest/twice.cl	Wed Aug 01 21:37:29 2012 +0900
@@ -1,9 +1,9 @@
 __kernel void
-twice(__global int *input_data,
-      __global int *output_data,
-      __global int *data_count)
+twice(__global int *data_count,
+      __global int *input_data,
+      __global int *output_data)
 {
-    int count = *data_count;
+    long count = (long)data_count;
 	for (int i = 0; i<count; i++) {
 	    output_data[i] = input_data[i] * 2;
 	}
--- a/example/OpenCL/twice.cl	Tue Jul 31 19:12:41 2012 +0900
+++ b/example/OpenCL/twice.cl	Wed Aug 01 21:37:29 2012 +0900
@@ -1,9 +1,9 @@
 __kernel void
-twice(__global int *data_count,
-      __global int *input_data,
-      __global int *output_data)
+twice(__global int *input_data,
+      __global int *output_data,
+      __global int *data_count,)
 {
-    long count = (long)data_count;
+    int count = *data_count;
 	for (int i = 0; i<count; i++) {
 	    output_data[i] = input_data[i] * 2;
 	}