changeset 1436:42057124fb44 draft

change to Singleton Pattern
author Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
date Fri, 06 Apr 2012 18:30:09 +0900
parents 9f6ba00ca15c
children fa6723e7d329
files TaskManager/Gpu/GpuScheduler.cc TaskManager/Gpu/GpuScheduler.h TaskManager/Gpu/GpuTaskManagerImpl.cc TaskManager/Gpu/GpuTaskManagerImpl.h TaskManager/Gpu/GpuThreads.cc TaskManager/Gpu/GpuThreads.h TaskManager/kernel/ppe/TaskManagerImpl.h
diffstat 7 files changed, 47 insertions(+), 41 deletions(-) [+]
line wrap: on
line diff
--- a/TaskManager/Gpu/GpuScheduler.cc	Fri Apr 06 07:57:27 2012 +0900
+++ b/TaskManager/Gpu/GpuScheduler.cc	Fri Apr 06 18:30:09 2012 +0900
@@ -1,5 +1,6 @@
 #include "GpuScheduler.h"
 #include "GpuDmaManager.h"
+#include "GpuThreads.h"
 #include "stdio.h"
 
 void
@@ -18,6 +19,9 @@
 void
 gpu_register_task(int cmd, char* filename, char* functionname)
 {
+    GpuThreads gputhreads = GpuThreads::getInstance();
+    context = &gputhreads.context 
+
     FILE *fp;
     char *souce_str;
     size_t source_size;
--- a/TaskManager/Gpu/GpuScheduler.h	Fri Apr 06 07:57:27 2012 +0900
+++ b/TaskManager/Gpu/GpuScheduler.h	Fri Apr 06 18:30:09 2012 +0900
@@ -12,13 +12,9 @@
 class GpuScheduler : public Scheduler {
 public:
     void init_impl(int useRefDma);
-    void set_command_queue(cl_command_queue* _command_queue) {
-        command_queue = _command_queue;
-    }
-
 
 private:
-    cl_command_queue *command_queue;
+    cl_context* context;
 
 };
 
--- a/TaskManager/Gpu/GpuTaskManagerImpl.cc	Fri Apr 06 07:57:27 2012 +0900
+++ b/TaskManager/Gpu/GpuTaskManagerImpl.cc	Fri Apr 06 18:30:09 2012 +0900
@@ -20,19 +20,17 @@
     htaskImpl = activeTaskQueue;
     mscheduler->set_manager(this);
 
-    clGetPlatformIDs(1, &platfrom_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);
-
-    gpuThreads->init(&command_queue);
+    gpuThreads->init();
 
     schedTaskManager = new SchedTask();
     schedTaskManager->init(0, 0, 0, ppeManager->get_scheduler(), 0);
     ppeManager->schedTaskManager = schedTaskManager;
 }
 
+#ifdef __CERIUM_GPU__
+TaskManagerImpl*
+create_impl(int num, int useRefDma)
+{
+    Threads *gpus = GpuThreads::getInstance();
+    return new CellTaskManagerImpl(num, cpus);
+}
--- a/TaskManager/Gpu/GpuTaskManagerImpl.h	Fri Apr 06 07:57:27 2012 +0900
+++ b/TaskManager/Gpu/GpuTaskManagerImpl.h	Fri Apr 06 18:30:09 2012 +0900
@@ -1,13 +1,6 @@
 #ifndef INCLUDED_GPU_TASK_MANAGER_IMPL
 #define INCLUDED_GPU_TASK_MANAGER_IMPL
 
-#ifdef __APPLE__
-#include <OpenCL/opencl.h>
-#else
-#include <CL/cl.h>
-#endif
-
-
 #include "TaskManagerImpl.h"
 #include "FifoTaskManagerImpl.h"
 #include "GpuThreads.h"
@@ -30,14 +23,6 @@
     Threads *gpuThreads;
     FifoTaskManagerImpl *ppeManager;
 
-    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;
-
-
 };
 
 #endif
--- a/TaskManager/Gpu/GpuThreads.cc	Fri Apr 06 07:57:27 2012 +0900
+++ b/TaskManager/Gpu/GpuThreads.cc	Fri Apr 06 18:30:09 2012 +0900
@@ -2,11 +2,10 @@
 #include "GpuScheduler.h"
 #include "TaskManagerImpl.h"
 
-GpuThreads::GpuThreads(int num, int useRefDma, int start_id) : use_refdma(useRefDma)
+GpuThreads::GpuThreads()
 {
     threads = new pthread_t;
     args = new gpu_arg;
-
 }
 
 GpuThreads::~GpuThreads()
@@ -16,11 +15,20 @@
 }
 
 void
-GpuThreads::init(cl_command_queue* _command_queue)
+GpuThreads::init()
 {
+    clGetPlatformIDs(1, &platfrom_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.useRefDma = use_refdma;
-    args.command_queue = _command_queue;
+    args.command_queue = command_queue;
 
     pthread_create(&threads, NULL, &cpu_thread_run, (void*)&args);
 
@@ -31,6 +39,7 @@
 {
     gpu_arg *argt = (gpu_arg *) args;
     Scheduler *g_scheduler = argt->scheduler;
+    // command_queueがThreadセーフじゃない。
     cl_command_queue *command_queue = argt->command_queue;
 
     TaskManagerImpl *manager = new GpuTaskManagerImpl();
--- a/TaskManager/Gpu/GpuThreads.h	Fri Apr 06 07:57:27 2012 +0900
+++ b/TaskManager/Gpu/GpuThreads.h	Fri Apr 06 18:30:09 2012 +0900
@@ -10,6 +10,7 @@
 #include <CL/cl.h>
 #endif
 
+// Singleton Pattern
 struct gpu_arg {
     GpuScheduler *scheduler;
     cl_command_queue *command_queue;
@@ -18,13 +19,26 @@
 
 class GpuThreads : public Threads {
 public:
-    GpuThreads(int num, int useRefDma, int start_id);
+    static GpuThreads* getInstance() {
+        static GpuThreads* singleton;
+        return singleton;
+    }
     ~GpuThreads();
 
     void init(cl_device_id device_id;);
     void *gpu_thread_run(void *args);
 
+public:
+    cl_platform_id platform_id;
+    cl_device_id device_id;
+    cl_uint ret_num_platforms;
+    cl_uint ret_num_devices;
+    cl_device_id* device_id;
+    cl_context context;
+    cl_command_queue command_queue;
+
 private:
+    GpuThreads();
 
     gpu_arg *args;
     pthread_t *threads;
--- a/TaskManager/kernel/ppe/TaskManagerImpl.h	Fri Apr 06 07:57:27 2012 +0900
+++ b/TaskManager/kernel/ppe/TaskManagerImpl.h	Fri Apr 06 18:30:09 2012 +0900
@@ -59,12 +59,12 @@
     virtual HTaskPtr create_task(int cmd, memaddr rbuf, long r_size, memaddr wbuf, long w_size,void *from);
     virtual HTaskPtr create_task_array(int id, int num_task, int num_param, int num_inData, int num_outData,void *from);
     virtual TaskListPtr createTaskList();
-	const char *get_task_name(int cmd);
-	const char *get_task_name(TaskPtr task);
-	const char *get_task_name(SimpleTaskPtr simpletask);
-	const char *get_task_name(SchedTaskBase *schedtask);
-	const char *get_task_name(HTaskPtr htask);
-	const char *get_task_name(HTaskPtr htask, int index);
+    const char *get_task_name(int cmd);
+    const char *get_task_name(TaskPtr task);
+    const char *get_task_name(SimpleTaskPtr simpletask);
+    const char *get_task_name(SchedTaskBase *schedtask);
+    const char *get_task_name(HTaskPtr htask);
+    const char *get_task_name(HTaskPtr htask, int index);
     virtual void set_task_depend(HTaskPtr master, HTaskPtr slave);
     virtual void spawn_task(HTaskPtr);
     virtual void set_task_cpu(HTaskPtr, CPU_TYPE);