changeset 1480:f2512fb94223 draft

GpuTaskManager no compile error
author Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
date Wed, 25 Jul 2012 19:41:04 +0900
parents 163220e54cc0
children a9da5c6bea91
files TaskManager/Cell/CellTaskManagerImpl.cc TaskManager/Cell/spe/SpeTaskManagerImpl.cc TaskManager/Cell/spe/SpeTaskManagerImpl.h TaskManager/Gpu/GpuScheduler.cc TaskManager/Gpu/GpuScheduler.h TaskManager/Gpu/GpuThreads.cc TaskManager/Gpu/GpuThreads.h TaskManager/Makefile.gpu TaskManager/kernel/ppe/CpuThreads.cc TaskManager/kernel/ppe/CpuThreads.h TaskManager/kernel/ppe/Task.h TaskManager/kernel/schedule/Scheduler.cc TaskManager/test/GpuRegistTaskTest/GpuRegistTaskTest.cc TaskManager/test/GpuRunTest/GpuRunTest.cc
diffstat 14 files changed, 141 insertions(+), 94 deletions(-) [+]
line wrap: on
line diff
--- a/TaskManager/Cell/CellTaskManagerImpl.cc	Tue Jul 24 17:15:15 2012 +0900
+++ b/TaskManager/Cell/CellTaskManagerImpl.cc	Wed Jul 25 19:41:04 2012 +0900
@@ -360,17 +360,21 @@
 
 TaskListPtr CellTaskManagerImpl::createTaskList()
 {
-        TaskListPtr tl = taskListInfo[0]->create();
-        bzero(tl->tasks,sizeof(Task)*TASK_MAX_SIZE);
+    TaskListPtr tl = taskListInfo[0]->create();
+    bzero(tl->tasks,sizeof(Task)*TASK_MAX_SIZE);
 	return tl;
 }
 
-
+#if defined (__CERIUM_CELL__)||(__CERIUM_GPU__)
+TaskManagerImpl *create_impl(int num, int useRefDma)
+{
 #ifdef __CERIUM_CELL__
-TaskManagerImpl*
-create_impl(int num, int useRefDma)
-{
-	Threads *cpus = new SpeThreads(num);
-	return new CellTaskManagerImpl(num,cpus);
+    Threads *cpus = new SpeThreads(num);
+#elif __CERIUM_GPU__
+    Threads *cpus = new CpuThreads(num, useRefDma);
+#endif
+	return new CellTaskManagerImpl(num, cpus);
 }
 #endif // __CERIUM_CELL
+
+
--- a/TaskManager/Cell/spe/SpeTaskManagerImpl.cc	Tue Jul 24 17:15:15 2012 +0900
+++ b/TaskManager/Cell/spe/SpeTaskManagerImpl.cc	Wed Jul 25 19:41:04 2012 +0900
@@ -23,16 +23,13 @@
 // Odd
 #ifndef __CERIUM_FIFO__
 
-TaskManagerImpl::TaskManagerImpl(int i) {}
-void TaskManagerImpl::append_activeTask(HTask* p) {}
-void TaskManagerImpl::append_waitTask(HTask* p) {}
+SpeTaskManagerImpl::SpeTaskManagerImpl(int i) {}
+void SpeTaskManagerImpl::append_activeTask(HTask* p) {}
+void SpeTaskManagerImpl::append_waitTask(HTask* p) {}
 
 
-HTaskPtr TaskManagerImpl::create_task(int cmd,void *from) {return 0;}
-HTaskPtr TaskManagerImpl::create_task(int cmd, memaddr rbuf, long rs, memaddr wbuf, long ws,void *from) { return 0; }
-HTask * TaskManagerImpl::create_task_array(int id, int num_task, int num_param, int num_inData, int num_outData,void *from) {return 0;}
-void TaskManagerImpl::set_task_depend(HTaskPtr master, HTaskPtr slave) {}
-void TaskManagerImpl::spawn_task(HTaskPtr) {}
-void TaskManagerImpl::set_task_cpu(HTaskPtr, CPU_TYPE) {}
+HTaskPtr SpeTaskManagerImpl::create_task(int cmd,void *from) {return 0;}
+HTaskPtr SpeTaskManagerImpl::create_task(int cmd, memaddr rbuf, long rs, memaddr wbuf, long ws,void *from) { return 0; }
+HTask * SpeTaskManagerImpl::create_task_array(int id, int num_task, int num_param, int num_inData, int num_outData,void *from) {return 0;}
 
 #endif
--- a/TaskManager/Cell/spe/SpeTaskManagerImpl.h	Tue Jul 24 17:15:15 2012 +0900
+++ b/TaskManager/Cell/spe/SpeTaskManagerImpl.h	Wed Jul 25 19:41:04 2012 +0900
@@ -32,6 +32,17 @@
     void free_htask(HTaskPtr htask) {}
     void print_arch();
 
+#ifdef __CERIUM_GPU__
+    
+    SpeTaskManagerImpl(int i);
+    void append_activeTask(HTask* p);
+    void append_waitTask(HTask* p);
+    
+    
+    HTaskPtr create_task(int cmd,void *from);
+    HTaskPtr create_task(int cmd, memaddr rbuf, long rs, memaddr wbuf, long ws,void *from);
+    HTask * create_task_array(int id, int num_task, int num_param, int num_inData, int num_outData,void *from);
+#endif
 }  ;
 
 
--- a/TaskManager/Gpu/GpuScheduler.cc	Tue Jul 24 17:15:15 2012 +0900
+++ b/TaskManager/Gpu/GpuScheduler.cc	Wed Jul 25 19:41:04 2012 +0900
@@ -1,7 +1,6 @@
 #include "GpuScheduler.h"
 #include "ReferencedDmaManager.h"
 #include "SchedTask.h"
-#include "GpuThreads.h"
 #include "stdio.h"
 #include <fcntl.h>
 #include <sys/stat.h>
@@ -9,6 +8,7 @@
 GpuScheduler::GpuScheduler()
 {
     init_impl(0);
+    init_gpu();
 }
 
 void
@@ -18,6 +18,21 @@
     connector = fifoDmaManager;
 }
 
+void
+GpuScheduler::init_gpu()
+{
+    clGetPlatformIDs(1, &platform_id, &ret_num_platforms); 
+    clGetDeviceIDs(platform_id, CL_DEVICE_TYPE_GPU, 1, &device_id, &ret_num_devices);
+    // unavailable GPU
+    if(ret_num_devices == 0) {
+        exit(EXIT_FAILURE);
+    }
+    
+    context = clCreateContext(NULL, 1, &device_id, NULL, NULL, &ret);
+    command_queue = clCreateCommandQueue(context, device_id, 0, &ret);
+
+}
+
 
 void
 GpuScheduler::run()
@@ -26,15 +41,12 @@
         memaddr params_addr = connector->task_list_mail_read();
         
         // Get OpenCL infomation
-        GpuThreads* gputhreads = GpuThreads::getInstance();
-        cl_context context = gputhreads->context;
-        cl_command_queue command_queue = gputhreads->command_queue;
         
         if ((memaddr)params_addr == (memaddr)MY_SPE_COMMAND_EXIT) {
             clFinish(command_queue);
             return ;
         }
-
+        
         TaskListPtr tasklist ;
 
         while (params_addr) {
@@ -53,7 +65,7 @@
                     cl_mem memobj = clCreateBuffer(context, CL_MEM_READ_WRITE, nextTask->inData(i)->size, NULL, NULL);
                     err |= clEnqueueWriteBuffer(command_queue, memobj, CL_TRUE, 0, 
                                                 nextTask->inData(i)->size, nextTask->inData(i)->addr, 0, NULL, NULL);
-                    //clSetKernleArg(kernel, cur_index,);
+                    
                 }
                 // カーネル引数の設定
             
@@ -78,11 +90,8 @@
 }
 
 void
-gpu_register_task(GpuThreads *gputhreads,int cmd, const char* filename, const char* functionname)
+GpuScheduler::regist_task(int cmd, const char* filename, const char* functionname)
 {
-    cl_context context = gputhreads->context;
-    cl_device_id device_id = gputhreads->device_id;
-    
     int fp;
     char *source_str;
     size_t source_size;
@@ -108,7 +117,7 @@
     close(fp);
 
     cl_program program = NULL;
-    cl_int ret = gputhreads->ret;
+
     program = clCreateProgramWithSource(context, 1, (const char **)&source_str,
                                                (const size_t *)&source_size, &ret);
     clBuildProgram(program, 1, &device_id, NULL, NULL, NULL);
--- a/TaskManager/Gpu/GpuScheduler.h	Tue Jul 24 17:15:15 2012 +0900
+++ b/TaskManager/Gpu/GpuScheduler.h	Wed Jul 25 19:41:04 2012 +0900
@@ -3,6 +3,7 @@
 
 #include "Scheduler.h"
 #include "FifoDmaManager.h"
+#include "GpuThreads.h"
 
 #ifdef __APPLE__
 #include <OpenCL/opencl.h>
@@ -10,13 +11,16 @@
 #include <CL/cl.h>
 #endif
 
+
 class GpuScheduler : public Scheduler {
 public:
     GpuScheduler();
 
     void init_impl(int useRefDma);
+    void init_gpu();
     void run();
-
+    void regist_task(int cmd,const char* filename,const char* functionname);
+    
     void mail_write_from_host(memaddr data) {
 	fifoDmaManager->mail_write_from_host(data);
     }
@@ -29,11 +33,18 @@
 	return fifoDmaManager->has_mail_from_host();
     }
 
+    cl_platform_id platform_id;
+    cl_device_id device_id;
+    cl_uint ret_num_platforms;
+    cl_uint ret_num_devices;
+    cl_context context;
+    cl_command_queue command_queue;
+    cl_int ret;
 private:
     FifoDmaManager *fifoDmaManager;
+
 };
 
 #endif
 
-#define GpuSchedRegister(gputhreads, str, filename, functionname)    \
-    gpu_register_task(gputhreads, str, filename, functionname);
+
--- a/TaskManager/Gpu/GpuThreads.cc	Tue Jul 24 17:15:15 2012 +0900
+++ b/TaskManager/Gpu/GpuThreads.cc	Wed Jul 25 19:41:04 2012 +0900
@@ -14,26 +14,16 @@
     delete threads;
     delete args;
 
-    clReleaseCommandQueue(command_queue);
-    clReleaseContext(context);
 }
 
 void
 GpuThreads::init()
 {
-    clGetPlatformIDs(1, &platform_id, &ret_num_platforms); 
-    clGetDeviceIDs(platform_id, CL_DEVICE_TYPE_GPU, 1, &device_id, &ret_num_devices);
-    // unavailable GPU
-    if( ret_num_devices == 0) {
-        exit(EXIT_FAILURE);
-    }
-    context = clCreateContext(NULL, 1, &device_id, NULL, NULL, &ret);
-    command_queue = clCreateCommandQueue(context, device_id, 0, &ret);
 
-    args->scheduler = new GpuScheduler();
+    args->scheduler = new GpuScheduler();    
     args->useRefDma = use_refdma;
 
-    // pthread_create(threads, NULL, &gpu_thread_run, args);
+    //pthread_create(threads, NULL, &gpu_thread_run, args);
 
 }
 
@@ -42,10 +32,11 @@
 {
     gpu_arg *argt = (gpu_arg *) args;
     Scheduler *g_scheduler = argt->scheduler;
-
+    
     TaskManagerImpl *manager = new SpeTaskManagerImpl();
     g_scheduler->init(manager, argt->useRefDma);
-
+    
+    
     manager->set_scheduler(g_scheduler);
 
     g_scheduler->run();
--- a/TaskManager/Gpu/GpuThreads.h	Tue Jul 24 17:15:15 2012 +0900
+++ b/TaskManager/Gpu/GpuThreads.h	Wed Jul 25 19:41:04 2012 +0900
@@ -11,20 +11,23 @@
 #include <CL/cl.h>
 #endif
 
-// Singleton Pattern
+class GpuScheduler;
+
 struct gpu_arg {
     GpuScheduler *scheduler;
     int useRefDma;
 };
 
 class GpuThreads : public Threads {
-public:
-    static GpuThreads* getInstance() {
+ public:
+    /*
+      static GpuThreads* getInstance() {
       static GpuThreads singleton;
       return &singleton;
-    }
+      }*/
+    GpuThreads();
     ~GpuThreads();
-
+    
     void init();
     static void *gpu_thread_run(void *args);
 
@@ -32,16 +35,10 @@
     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);
-
-public:
-    GpuThreads();
-    cl_platform_id platform_id;
-    cl_device_id device_id;
-    cl_uint ret_num_platforms;
-    cl_uint ret_num_devices;
-    cl_context context ;
-    cl_command_queue command_queue;
-    cl_int ret;
+    
+ public:
+    
+    
 
 private:
     gpu_arg *args;
--- a/TaskManager/Makefile.gpu	Tue Jul 24 17:15:15 2012 +0900
+++ b/TaskManager/Makefile.gpu	Wed Jul 25 19:41:04 2012 +0900
@@ -20,7 +20,7 @@
 ALL_OBJS = $(KERN_MAIN_OBJS) $(KERN_PPE_OBJS) $(KERN_SCHED_OBJS) \
 	$(KERN_SYSTASK_OBJS) $(IMPL_FIFO_OBJS) $(KERN_MEM_OBJS) \
 	$(IMPL_GPU_OBJS) \
-	Cell/spe/SpeTaskManagerImpl.o Cell/CellTaskManagerImpl.o
+    Cell/spe/SpeTaskManagerImpl.o Cell/CellTaskManagerImpl.o
 
 Makefile.dep: 
 	make -f Makefile.gpu depend
--- a/TaskManager/kernel/ppe/CpuThreads.cc	Tue Jul 24 17:15:15 2012 +0900
+++ b/TaskManager/kernel/ppe/CpuThreads.cc	Wed Jul 25 19:41:04 2012 +0900
@@ -12,6 +12,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();
 #endif
@@ -99,21 +100,27 @@
 int
 CpuThreads::get_mail(int cpuid, int count, memaddr *ret)
 {  
-    
-    *ret = args[cpuid-id_offset].scheduler->mail_read_from_host();
-    return 1;
+    if (is_gpu(cpuid)) {
+        return 0;//gpu->get_mail(cpuid, count, ret);
+    } else {
+        *ret = args[cpuid-id_offset].scheduler->mail_read_from_host();
+        return 1;
+    }
 }
 
 int
 CpuThreads::has_mail(int cpuid, int count, memaddr *ret)
 {
-	if (args[cpuid-id_offset].scheduler->has_mail_from_host() != 0) {
-		return get_mail(cpuid,count,ret);
-	} else {
-		return 0; //mailがないとき0を返す
-	}
+    if (is_gpu(cpuid)) {
+        return gpu->has_mail(cpuid, count, ret);
+    } else {
+        if (args[cpuid-id_offset].scheduler->has_mail_from_host() != 0) {
+            return get_mail(cpuid,count,ret);
+        } else {
+            return 0; //mailがないとき0を返す
+        }
+    }
 }
-
 /**
  * Inbound Mailbox
  * メール送信 Front End -> CPU
@@ -131,7 +138,11 @@
 void
 CpuThreads::send_mail(int cpuid, int num, memaddr *data)
 {
-    args[cpuid-id_offset].scheduler->mail_write_from_host(*data);
+    if (is_gpu(cpuid)) {
+        //gpu->send_mail(cpuid, num, data);
+    } else {
+        args[cpuid-id_offset].scheduler->mail_write_from_host(*data);
+    }
 }
 
 void
@@ -146,4 +157,17 @@
 
 }
 
+
+int
+CpuThreads::is_gpu(int cpuid)
+{
+    if ( (cpuid < GPU_0)||(cpuid > GPU_3) ) {
+        return 0;
+        // cpuidがGPU以外なら0を返す
+    } else {
+        return 1;
+        //GPUなら1を返す
+    }
+}
+
 /* end */
--- a/TaskManager/kernel/ppe/CpuThreads.h	Tue Jul 24 17:15:15 2012 +0900
+++ b/TaskManager/kernel/ppe/CpuThreads.h	Wed Jul 25 19:41:04 2012 +0900
@@ -19,18 +19,19 @@
 } cpu_thread_arg_t;
 
 class CpuThreads : public Threads {
-public:
+ public:
     /* constructor */
     CpuThreads(int num = 1, int useRefDma = 0, int start_id = 0);
     ~CpuThreads();
     static void *cpu_thread_run(void *args);
-
+    
     /* functions */
     virtual void init();
     virtual int get_mail(int speid, int count, memaddr *ret); // BLOCKING
     virtual int has_mail(int speid, int count, memaddr *ret); // NONBLOCK
     virtual void send_mail(int speid, int num, memaddr *data); // BLOCKING
     virtual void add_output_tasklist(int command, memaddr buff, int alloc_size);
+    virtual int is_gpu(int sepid);
 
 private:
     /* variables */
--- a/TaskManager/kernel/ppe/Task.h	Tue Jul 24 17:15:15 2012 +0900
+++ b/TaskManager/kernel/ppe/Task.h	Wed Jul 25 19:41:04 2012 +0900
@@ -96,6 +96,7 @@
         char *p = (char *)addr; int b = *p;
         p = (char *)(addr+size-1); b += *p;
 #endif
+
 #ifdef __CERIUM_CELL__
 	list->addr = (uint32)addr;
 #else
--- a/TaskManager/kernel/schedule/Scheduler.cc	Tue Jul 24 17:15:15 2012 +0900
+++ b/TaskManager/kernel/schedule/Scheduler.cc	Wed Jul 25 19:41:04 2012 +0900
@@ -336,7 +336,7 @@
 MemorySegment * 
 Scheduler::get_segment(memaddr addr, MemList *m) 
 {
-    if (addr>(memaddr)0x200029f26)
+    if (addr > (memaddr)0x200029f26)
         addr = addr+1;
 
 #ifdef USE_CACHE
--- a/TaskManager/test/GpuRegistTaskTest/GpuRegistTaskTest.cc	Tue Jul 24 17:15:15 2012 +0900
+++ b/TaskManager/test/GpuRegistTaskTest/GpuRegistTaskTest.cc	Wed Jul 25 19:41:04 2012 +0900
@@ -37,8 +37,7 @@
 test(int task_array_num)
 {
     
-    GpuThreads* gpuThreads = new GpuThreads();
-    gpuThreads->init(); 
+    GpuScheduler* g_scheduler = new GpuScheduler();
 
     int *indata,*outdata;
     int count;
@@ -51,17 +50,17 @@
         indata[count] = count;
     }
     
-    GpuSchedRegister(gpuThreads, 1,"./twice.cl","twice");
+    g_scheduler->regist_task(1,"./twice.cl","twice");
 
 
     cl_int ret;
-    cl_context context = gpuThreads->context;
+    cl_context context = (cl_context)g_scheduler->command_queue;
 
     cl_mem memobj_in  = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(int)*count, NULL, &ret);
     cl_mem memobj_out = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(int)*count, NULL, &ret);
     cl_mem data_count = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(int)*count, NULL, &ret);
     
-    cl_command_queue command_queue = gpuThreads->command_queue;
+    cl_command_queue command_queue = g_scheduler->command_queue;
     ret = clEnqueueWriteBuffer(command_queue, memobj_in, CL_TRUE, 0,
                                sizeof(int)*count, indata, 0, NULL, NULL);
     ret = clEnqueueWriteBuffer(command_queue, data_count, CL_TRUE, 0,
@@ -87,7 +86,7 @@
 
     delete [] indata;
     delete [] outdata;
-    delete gpuThreads;
+    delete [] g_scheduler;
     clReleaseCommandQueue(command_queue);
     clReleaseContext(context);
     
--- a/TaskManager/test/GpuRunTest/GpuRunTest.cc	Tue Jul 24 17:15:15 2012 +0900
+++ b/TaskManager/test/GpuRunTest/GpuRunTest.cc	Wed Jul 25 19:41:04 2012 +0900
@@ -5,13 +5,14 @@
 #include "GpuScheduler.h"
 #include "GpuThreads.h"
 #include "GpuFunc.h"
+
 #define DEFAULT 5
 
 char usr_help_str[] = "GpuRun [length]\n";
 
-extern void gpu_register_task(int, const char*, const char*);
 extern void task_init(void);
 
+
 void
 print_data(int *data, int size, const char *title)
 {
@@ -34,26 +35,23 @@
             check++;
         }
     }
-    
+   
     printf("Computed '%d/%d' correct values\n",check,num);
     
 }
 
 void
-task_init()
+task_init(GpuScheduler *g_scheduler)
 {
     int cmd = SchedRun;
-
-    GpuThreads* gputhreads = GpuThreads::getInstance();
-    gputhreads->init();
-
-    GpuSchedRegister(cmd, "twice.cl", "twice");
+    g_scheduler->regist_task(cmd, "twice.cl", "twice");
+    
 }
 
 void
-test(TaskManager *manager, long int length) {
+test(TaskManager *manager, long int length, GpuScheduler *g_scheduler) {
     
-    int *indata  = (int *)manager->allocate(sizeof(int)*length);//new int[length];
+    int *indata  = new int[length];
     int *outdata = new int[length];
     int count;
     for (count=0; count < length ;count++) {
@@ -62,12 +60,15 @@
     print_data(indata, count, "before");
     
     HTaskPtr schedtask = manager->create_task(SchedRun);
+
     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_cpu(SPE_ANY);   // これでは、GPU しか使えないではないか。
+    schedtask->set_cpu(GPU_0);
     schedtask->spawn();
     
+    g_scheduler->run();
+    
 }
     
 int
@@ -80,10 +81,11 @@
             length = atoi(argv[1]);
         }
     }
-    task_init();
+    GpuScheduler *g_scheduler = new GpuScheduler();
+    task_init(g_scheduler);
 
-    test(manager, length);
-
+    test(manager, length, g_scheduler);
+    
     return 0;
 }