changeset 1510:81f1afd1851f draft

separate TaskObject and GpuTaskObject
author Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
date Mon, 01 Oct 2012 16:51:26 +0900
parents acd86a0ff366
children 34582cd8a7af 18b63e697c61
files TaskManager/Gpu/GpuScheduler.cc TaskManager/kernel/schedule/Scheduler.cc TaskManager/kernel/schedule/Scheduler.h
diffstat 3 files changed, 91 insertions(+), 83 deletions(-) [+]
line wrap: on
line diff
--- a/TaskManager/Gpu/GpuScheduler.cc	Tue Sep 25 16:23:31 2012 +0900
+++ b/TaskManager/Gpu/GpuScheduler.cc	Mon Oct 01 16:51:26 2012 +0900
@@ -81,7 +81,7 @@
 
                 load_kernel(nextTask->command);
 
-                cl_kernel& kernel = *task_list[nextTask->command].kernel;
+                cl_kernel& kernel = *task_list[nextTask->command].gputask->kernel;
                 int err = CL_SUCCESS;
 
                 int param = 0;
@@ -137,7 +137,7 @@
             if(reply[1-cur]) {
                 connector->mail_write(reply[1-cur]);
             }
-            
+
             params_addr = (memaddr)tasklist->next;
             cur = 1 - cur;
         }
@@ -162,7 +162,7 @@
 {
     if (task_list[cmd].run == null_run) return;
 
-    const char *filename = (const char *)task_list[cmd].kernel;
+    const char *filename = (const char *)task_list[cmd].gputask->kernel;
     const char *functionname = task_list[cmd].name;
 
     int fp;
@@ -197,7 +197,7 @@
 
     cl_kernel *kernel = new cl_kernel;
     *kernel = clCreateKernel(program, functionname, &ret);
-    task_list[cmd].kernel = kernel;
+    task_list[cmd].gputask->kernel = kernel;
     task_list[cmd].run = null_run; // kernel is ready
 
 }
@@ -205,11 +205,12 @@
 void
 gpu_register_task(int cmd, const char* filename, const char* functionname)
 {
+    task_list[cmd].gputask->a = 1;
     task_list[cmd].run = not_ready;  // not yet ready
     task_list[cmd].load = null_loader;
     task_list[cmd].wait = null_loader;
     task_list[cmd].name = functionname;
-    task_list[cmd].kernel = (cl_kernel *) filename;
+    task_list[cmd].gputask->kernel = (cl_kernel *) filename;
 }
 
 /* end */
--- a/TaskManager/kernel/schedule/Scheduler.cc	Tue Sep 25 16:23:31 2012 +0900
+++ b/TaskManager/kernel/schedule/Scheduler.cc	Mon Oct 01 16:51:26 2012 +0900
@@ -26,7 +26,7 @@
     delete connector;
 }
 
-int 
+int
 null_run(SchedTask* smanager, void* r, void *w)
 {
     smanager->printf("Calling Undefined Task %d\n", smanager->atask->command);
@@ -48,19 +48,20 @@
     task_count = 0;
 #endif
 
-	/* 
-	 * ;TODO
-	 * Multi-Core Verの場合、各スレッドにMain Schedulerが作られるが、
-	 * その際、globalなlistの初期化を繰り返して無駄な処理を行なっている
-	 */
+        /*
+         * ;TODO
+         * Multi-Core Verの場合、各スレッドにMain Schedulerが作られるが、
+         * その際、globalなlistの初期化を繰り返して無駄な処理を行なっている
+         */
 
     for (int i = 0; i< MAX_TASK_OBJECT; i++) {
-	task_list[i].run = null_run;
-	task_list[i].load = null_loader;
-	task_list[i].wait = null_loader;
+        task_list[i].run = null_run;
+        task_list[i].load = null_loader;
+        task_list[i].wait = null_loader;
+        task_list[i].gputask = new GpuTaskObject();
 
 #ifndef NOT_CHECK
-	entry_cmd[i] = NULL;
+        entry_cmd[i] = NULL;
 #endif
 
     }
@@ -94,18 +95,18 @@
     SchedTaskBase* task3 = new SchedNop();
     // main loop
     do {
-        
+
         task1->read();
         task2->exec();
         task3->write();
-        
-        delete task3; 
-        
+
+        delete task3;
+
         task3 = task2;
         task2 = task1;
         //SchedMailの場合、Mailの待ちが入る
         task1 = task1->next(this, 0);
-    
+
     } while (task1);
 
     delete task3;
@@ -175,7 +176,7 @@
     return mainMemList[id];
 }
 
-/** 
+/**
  *  Task load API
  */
 void
@@ -185,11 +186,11 @@
     code_segment_pool = createMemList(size, count);
     if (table) {
         MemorySegment* here = (MemorySegment*)(
-	     manager->allocate(sizeof(MemorySegment)));
+             manager->allocate(sizeof(MemorySegment)));
         here->data = (void*)(table->vma);
         here->size = size;
-	here->address = (memaddr)here;
-	code_segment_pool->addLast(here);
+        here->address = (memaddr)here;
+        code_segment_pool->addLast(here);
     }
 }
 
@@ -197,20 +198,20 @@
 load_task(Scheduler *m, int task_id)
 {
     MemorySegment *s = m->get_segment(
-	task_list[task_id].location, 
-	m->code_segment_pool, 
-	task_list[task_id].end-task_list[task_id].location);
+        task_list[task_id].location,
+        m->code_segment_pool,
+        task_list[task_id].end-task_list[task_id].location);
     task_list[task_id].segment = s;
     // calcurate call address
-    TaskObjectRun run = 
+    TaskObjectRun run =
         (TaskObjectRun)(
             (char*)task_list[task_id].segment->data +
             task_list[task_id].entry_offset);
     task_list[task_id].run = run;
 #if 0
     m->printf("loadng task id %d at 0x%x entry 0x%x location 0x%x\n",task_id,
-	    (unsigned int)(task_list[task_id].segment->data ),
-	    (unsigned int)(
+            (unsigned int)(task_list[task_id].segment->data ),
+            (unsigned int)(
             (char*)task_list[task_id].segment->data +
             task_list[task_id].entry_offset),
             task_list[task_id].location);
@@ -228,15 +229,15 @@
 #if 0
     MemorySegment *s = task_list[task_id].segment;
     if (s)
-	m->printf("wait load task id %d 0x%x\n",task_id,(int)s->data);
+        m->printf("wait load task id %d 0x%x\n",task_id,(int)s->data);
     else
-	m->printf("wait load task id %d 000000\n",task_id);
+        m->printf("wait load task id %d 000000\n",task_id);
 #endif
     // wait for code segment load
     m->wait_segment(task_list[task_id].segment);
 #if 0
     m->printf("wait load task id %d done. creator = 0x%x entry_offset = 0x%x\n",task_id,
-	(unsigned int)(task_list[task_id].run),
+        (unsigned int)(task_list[task_id].run),
             task_list[task_id].entry_offset);
 #endif
 }
@@ -246,7 +247,7 @@
 {
 }
 
-extern void 
+extern void
 register_task(int cmd, TaskObjectRun run, const char *str)
 {
     task_list[cmd].run = run;
@@ -255,13 +256,13 @@
     task_list[cmd].name = str;
 
 #ifndef NOT_CHECK
-    entry_cmd[task_count++] = cmd;    
+    entry_cmd[task_count++] = cmd;
 #endif
 
 }
 
-extern void 
-register_dynamic_task(int cmd, 
+extern void
+register_dynamic_task(int cmd,
     memaddr start, int size,
     TaskObjectRun run, int entry_offset,
     const char *str)
@@ -276,7 +277,7 @@
     task_list[cmd].name = str;
 
 #ifndef NOT_CHECK
-    entry_cmd[task_count++] = cmd;    
+    entry_cmd[task_count++] = cmd;
 #endif
 
 #if 0
@@ -308,7 +309,7 @@
     MemList* mlist = new MemList((MemorySegment*)mseg);
 
     if (!hash) {
-	hash = new MemHash();
+        hash = new MemHash();
     }
 
     for(int i = 0; i < count; i++) {
@@ -316,7 +317,7 @@
         char* data = (char*)next+head_size;
         next->data = (void*)data;
         next->size = size;
-	next->address = (memaddr)next;
+        next->address = (memaddr)next;
         mlist->addLast(next);
     }
 
@@ -333,8 +334,8 @@
     memory directory にあるべきだが...
 
  */
-MemorySegment * 
-Scheduler::get_segment(memaddr addr, MemList *m) 
+MemorySegment *
+Scheduler::get_segment(memaddr addr, MemList *m)
 {
     if (addr > (memaddr)0x200029f26)
         addr = addr+1;
@@ -342,7 +343,7 @@
 #ifdef USE_CACHE
 
     MemorySegment *s = m->getFirst();
-    return get_segment(addr, m, s->size); 
+    return get_segment(addr, m, s->size);
 
 #else
 
@@ -375,8 +376,8 @@
 
  */
 
-MemorySegment * 
-Scheduler::get_free_segment(memaddr addr, MemList *m) 
+MemorySegment *
+Scheduler::get_free_segment(memaddr addr, MemList *m)
 {
 
 
@@ -403,7 +404,7 @@
  */
 
 void
-Scheduler::overwrite_segment(MemorySegment *s, memaddr addr) 
+Scheduler::overwrite_segment(MemorySegment *s, memaddr addr)
 {
 
     if(addr == NULL) {
@@ -416,8 +417,8 @@
 }
 
 
-MemorySegment * 
-Scheduler::get_segment(memaddr addr, MemList *m, int size) 
+MemorySegment *
+Scheduler::get_segment(memaddr addr, MemList *m, int size)
 {
 
     // memory segment のsizeをoverride する場合がある
@@ -425,14 +426,14 @@
 
     if (s) {
 
-	/* 既に load されている */
+        /* 既に load されている */
 // this->printf("get_segement loaded %llx 0x%x size 0x%d\n",addr,s->data,size);
-	m->moveToFirst(s);
-	return s;
+        m->moveToFirst(s);
+        return s;
     }
 
 
-    /* LRU なので、もっとも使われてない segment を上書きする */ 
+    /* LRU なので、もっとも使われてない segment を上書きする */
     s = m->getLast();
     m->moveToFirst(s);
 
@@ -488,16 +489,16 @@
     s->tag = 0;
 }
 
-long Scheduler::get_random() { 
+long Scheduler::get_random() {
 #if defined(__SPU__)
-    return 0; 
+    return 0;
 #else
-    return random(); 
+    return random();
 #endif
 
 }
 
-int 
+int
 Scheduler::printf(const char * format, ...)
 {
 #if !defined(__SPU__) || 1
@@ -511,7 +512,7 @@
 #endif
 }
 
-int 
+int
 Scheduler::vprintf0(const char * format, va_list ap)
 {
 #if !defined(__SPU__) || 1
--- a/TaskManager/kernel/schedule/Scheduler.h	Tue Sep 25 16:23:31 2012 +0900
+++ b/TaskManager/kernel/schedule/Scheduler.h	Mon Oct 01 16:51:26 2012 +0900
@@ -10,7 +10,7 @@
 #include "SchedTaskBase.h"
 #include "MemList.h"
 #include "MemHash.h"
-#include "types.h" 
+#include "types.h"
 
 #ifdef __CERIUM_GPU__
 #ifdef __APPLE__
@@ -34,6 +34,12 @@
 
 typedef int (*TaskObjectRun)(SchedTask* smanager, void* r, void *w);
 
+typedef struct gpu_task_object {
+#ifdef __CERIUM_GPU__
+    cl_kernel *kernel;
+#endif
+} GpuTaskObject;
+
 // Task Object Table
 //  this is named TaskObjectRun but it is not an object.
 //  It is a pointer to an object creation function
@@ -43,15 +49,15 @@
     CPU_TYPE cpu_type;
     TaskObjectRun run;
     memaddr location;            // location address in a.out
-    memaddr end;            
+    memaddr end;
     uint32 entry_offset;        // offset for create();
     MemorySegment *segment;
     const char *name;
     void (*load)(Scheduler *,int);
     void (*wait)(Scheduler *,int);
-#ifdef __CERIUM_GPU__
-    cl_kernel *kernel;
-#endif
+
+    GpuTaskObject *gputask;
+
 }  __attribute__ ((aligned (DEFAULT_ALIGNMENT))) //sizeはどれくらい?
       TaskObject, *TaskObjectPtr;
 
@@ -133,7 +139,7 @@
 
     /* manager */
 
-    void set_manager(TaskManagerImpl *m) { 
+    void set_manager(TaskManagerImpl *m) {
       manager = m;
     };
 
@@ -147,17 +153,17 @@
 }  ;
 
 extern void register_task(int cmd, TaskObjectRun run, const char *str);
-extern void register_dynamic_task(int cmd, 
+extern void register_dynamic_task(int cmd,
     memaddr start, int size, TaskObjectRun run,
-	int entry_offset,
-	const char *str);
+        int entry_offset,
+        const char *str);
 
-struct tbl { 
-    unsigned int vma; 
-    unsigned int size; 
-    unsigned int file_offset; 
-    unsigned int buf; 
-}; 
+struct tbl {
+    unsigned int vma;
+    unsigned int size;
+    unsigned int file_offset;
+    unsigned int buf;
+};
 
 extern TaskObject task_list[MAX_TASK_OBJECT];
 
@@ -187,13 +193,13 @@
     extern "C" { \
     int runTask_##str(SchedTask *smanager, void *rbuf, void *wbuf) \
     {                                                                   \
-	return run(smanager, rbuf, wbuf); \
+        return run(smanager, rbuf, wbuf); \
     } \
     }
 
 #define SchedExternTask(str)                                            \
     extern "C" { \
-	extern int runTask_##str(SchedTask *manager, void *rbuf, void *wbuf)   ; \
+        extern int runTask_##str(SchedTask *manager, void *rbuf, void *wbuf)   ; \
     }
 
 #define SchedRegisterTask(cmd, str)             \
@@ -208,26 +214,26 @@
 #ifndef NO_OVERLAY
 #define SchedExternDynamicTask(str,segment)                             \
     extern "C" { \
-	extern unsigned long long _EAR_; \
-	extern struct tbl _ovly_table[]; \
-	extern int runTask_##str(SchedTask *manager, void *rbuf, void *wbuf)   ; \
+        extern unsigned long long _EAR_; \
+        extern struct tbl _ovly_table[]; \
+        extern int runTask_##str(SchedTask *manager, void *rbuf, void *wbuf)   ; \
     }
 #else
-#define SchedExternDynamicTask(str,segment) SchedExternTask(str)   
+#define SchedExternDynamicTask(str,segment) SchedExternTask(str)
 #endif
 
 
 #ifndef NO_OVERLAY
 #define SchedRegisterDynamicTask(cmd, str, segment)                    \
     register_dynamic_task(cmd,  (memaddr)(_EAR_+_ovly_table[segment].file_offset), \
-		     _ovly_table[segment].size, \
+                     _ovly_table[segment].size, \
                     runTask_##str, \
-						  runTask_##str##_offset, \
-		#str);
-#define SchedRegisterDynamic(str, segment) SchedRegisterDynamicTask(str, str, segment)                    
+                                                  runTask_##str##_offset, \
+                #str);
+#define SchedRegisterDynamic(str, segment) SchedRegisterDynamicTask(str, str, segment)
 #else
 #define SchedRegisterDynamicTask(cmd, str, segment) SchedRegisterTask(cmd, str)
-#define SchedRegisterDynamic(str, segment) SchedRegisterDynamicTask(str, str, segment)                    
+#define SchedRegisterDynamic(str, segment) SchedRegisterDynamicTask(str, str, segment)
 #endif