changeset 1443:dff9b3f388e2 draft

debug GpuScheduler.cc
author Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
date Mon, 23 Apr 2012 21:38:42 +0900
parents db8a954fcfb3
children 9de96bded518 ef6933a92fff
files TaskManager/Gpu/GpuScheduler.cc TaskManager/Gpu/GpuThreads.cc TaskManager/Gpu/GpuThreads.h
diffstat 3 files changed, 40 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/TaskManager/Gpu/GpuScheduler.cc	Mon Apr 23 19:07:41 2012 +0900
+++ b/TaskManager/Gpu/GpuScheduler.cc	Mon Apr 23 21:38:42 2012 +0900
@@ -3,6 +3,7 @@
 #include "GpuThreads.h"
 #include "stdio.h"
 #include <fcntl.h>
+#include <sys/stat.h>
 
 void
 GpuScheduler::init_impl(int useRefDma)
@@ -16,9 +17,9 @@
     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;
+    GpuThreads* gputhreads = GpuThreads::getInstance();
+    cl_context& context = gputhreads->context;
+    cl_command_queue& command_queue = gputhreads->command_queue;
     cl_int ret;
 
     if ((memaddr)params_addr == (memaddr)MY_SPE_COMMAND_EXIT) {
@@ -26,27 +27,24 @@
         return 0;
     }
 
-    TaskListPtr *tasklist = (TaskListPtr)connector->dma_load(tasklist, params_addr, 
+    TaskListPtr tasklist = (TaskListPtr)connector->dma_load(this, params_addr, 
                                          sizeof(TaskList), DMA_READ_TASKLIST);
 
-    GpuThreads gputhreads = GpuThreads::getInstance();
-    cl_command_queue& command_queue = gputhreads.cl_command_queue;
-
     for (int cur_index = 0; cur_index < tasklist->length; cur_index++) {
-        TaskPtr task = tasklist.tasks[cur_index];
-        cl_kernel& kernel = task_list[task->command].kernel;
+        SimpleTaskPtr nextTask = &tasklist->tasks[cur_index];
+        cl_kernel& kernel = *task_list[nextTask->command].kernel;
 
-        if ( task.r_size != 0 ) {
-            cl_mem memobj = clCreateBuffer(context, CL_MEM_READ_WRITE, r_size, NULL, &ret);
-            clEnqueueWriteBuffer(command_queue, memobj, CL_TRUE, 0, r_size, rbuf, 0, NULL, NULL);
+        if ( nextTask->r_size != 0 ) {
+            cl_mem memobj = clCreateBuffer(context, CL_MEM_READ_WRITE, nextTask->r_size, NULL, &ret);
+            clEnqueueWriteBuffer(command_queue, memobj, CL_TRUE, 0, nextTask->r_size, nextTask->rbuf, 0, NULL, NULL);
         }
         // カーネル引数の設定
 
         clEnqueueTask(command_queue, kernel, 0, NULL, NULL);
 
-        if ( task.w_size != 0 ) {
-            cl_mem memobj = clCreateBuffer(context, CL_MEM_READ_WRITE, w_size, NULL, &ret);
-            clEnqueueWriteBuffer(command_queue, memobj, CL_TRUE, 0, w_size, wbuf, 0, NULL, NULL);
+        if ( nextTask->w_size != 0 ) {
+            cl_mem memobj = clCreateBuffer(context, CL_MEM_READ_WRITE, nextTask->w_size, NULL, &ret);
+            clEnqueueWriteBuffer(command_queue, memobj, CL_TRUE, 0, nextTask->w_size, nextTask->wbuf, 0, NULL, NULL);
         }
     }
     // TaskArrayの処理
@@ -57,12 +55,12 @@
 void
 gpu_register_task(int cmd, char* filename, char* functionname)
 {
-    GpuThreads gputhreads = GpuThreads::getInstance();
-    cl_context& context = &gputhreads.context;
-    cl_device_id& device_id = &gputhreads.device_id;
+    GpuThreads* gputhreads = GpuThreads::getInstance();
+    cl_context& context = gputhreads->context;
+    cl_device_id& device_id = gputhreads->device_id;
 
-    int *fp;
-    char *souce_str;
+    int fp;
+    char *source_str;
     size_t source_size;
     
     fp = open(filename, O_RDONLY);
@@ -73,8 +71,8 @@
     }
     
     struct stat stats;
-    fstat(fileno(fp),&stats);
-    off_t size = stas.st_size;
+    fstat(fp,&stats);
+    off_t size = stats.st_size;
     
     if (!size) {
         fprintf(stderr, "Failed to load kernel.\n");
@@ -82,7 +80,7 @@
     
     source_str = (char*)malloc(size);
 
-    source_size = read(source_str, size, fp);
+    source_size = read(fp, source_str, size);
     close(fp);
 
     cl_program program = NULL;
@@ -95,10 +93,10 @@
     cl_kernel *kernel = new cl_kernel; 
     *kernel = clCreateKernel(program, functionname, &ret);
     
-    task_list[cmd].run = run;
-    task_list[cmd].load = null_loader;
-    task_list[cmd].wait = null_waiter;
-    task_list[cmd].name = str;
+    task_list[cmd].run = NULL;
+    task_list[cmd].load = NULL;
+    task_list[cmd].wait = NULL;
+    task_list[cmd].name = functionname;
     task_list[cmd].kernel = kernel;
 
 }
--- a/TaskManager/Gpu/GpuThreads.cc	Mon Apr 23 19:07:41 2012 +0900
+++ b/TaskManager/Gpu/GpuThreads.cc	Mon Apr 23 21:38:42 2012 +0900
@@ -54,24 +54,29 @@
 }
 
 int
-GpuThreads::get_mail(memaddr *ret)
+GpuThreads::get_mail(int speid, int count, memaddr *ret)
 {
     *ret = args.scheduler->mail_read_from_host();
     return 1;
 }
 
 int
-GpuThreads::has_mail(memaddr *ret)
+GpuThreads::has_mail(int speid, int count, memaddr *ret)
 {
     if (args.scheduler->has_mail_from_host() != 0) {
-        return get_mail(ret);
+        return get_mail(0, 0, ret);
     } else {
         return 0;
     }
 }
 
 void
-CpuThreads::send_mail(int cpuid, int num, memaddr *data)
+CpuThreads::send_mail(int speid, int num, memaddr *data)
 {
     args.scheduler->mail_write_from_host(*data);
 }
+
+void
+GpuThreads::add_output_tasklist(int command, memaddr buff, int alloc_size)
+{
+}
--- a/TaskManager/Gpu/GpuThreads.h	Mon Apr 23 19:07:41 2012 +0900
+++ b/TaskManager/Gpu/GpuThreads.h	Mon Apr 23 21:38:42 2012 +0900
@@ -14,7 +14,7 @@
 struct gpu_arg {
     GpuScheduler *scheduler;
     int useRefDma;
-}
+};
 
 class GpuThreads : public Threads {
 public:
@@ -24,19 +24,19 @@
     }
     ~GpuThreads();
 
-    void init(cl_device_id device_id;);
+    void init();
     void *gpu_thread_run(void *args);
 
-    int get_mail();
-    int has_mail();
-    void send_mail();
+    int get_mail(int speid, int count, memaddr *ret);
+    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:
     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;