changeset 1530:c7f0e6eb1d50 draft

add comment
author Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
date Thu, 06 Dec 2012 16:49:41 +0900
parents 504a76847b85
children 4443d59a8210
files TaskManager/Gpu/GpuScheduler.cc TaskManager/Gpu/GpuScheduler.h example/many_task/main.cc
diffstat 3 files changed, 35 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/TaskManager/Gpu/GpuScheduler.cc	Sun Nov 25 21:10:50 2012 +0900
+++ b/TaskManager/Gpu/GpuScheduler.cc	Thu Dec 06 16:49:41 2012 +0900
@@ -28,6 +28,12 @@
     connector = fifoDmaManager;
 }
 
+
+/*
+ * Prepare OpenCL:
+ * get OpenCL information
+ * create command queue
+ */
 void
 GpuScheduler::init_gpu()
 {
@@ -50,6 +56,14 @@
     clReleaseContext(context);
 }
 
+
+/*
+ * run GPU task
+ * Get input and output data from tasklist.
+ * Enqueue OpenCL command and clflush.
+ * Enqueue and clflush are pipelined structure.
+ */
+
 void
 GpuScheduler::run()
 {
@@ -61,7 +75,7 @@
 
     for (;;) {
         memaddr params_addr = connector->task_list_mail_read();
-        // Get OpenCL infomation
+        // read task list mail from DmaManager
 
         if ((memaddr)params_addr == (memaddr)MY_SPE_COMMAND_EXIT) {
             clFinish(command_queue[0]);
@@ -70,11 +84,15 @@
         }
 
         while (params_addr) {
-            // since we are on the same memory space, we don't hae to use dma_load here
+            // since we are on the same memory space, we don't has to use dma_load here
             TaskListPtr tasklist = (TaskListPtr)connector->dma_load(this, params_addr,
                                                         sizeof(TaskList), DMA_READ_TASKLIST);
 
             if (tasklist->self) {
+                /*
+                 * get flip flag
+                 * flip : When cluculate on input data, to treat this as a output data
+                 */
                 flag = tasklist->self->flag;
             }
 
@@ -87,6 +105,7 @@
 
                 int param = 0;
 
+                // set arg count
                 cl_mem memparam = clCreateBuffer(context, CL_MEM_READ_ONLY,
                                                  sizeof(memaddr)*nextTask->param_count, NULL, NULL);
                 ret = clEnqueueWriteBuffer(command_queue[cur], memparam, CL_TRUE, 0,
@@ -97,7 +116,7 @@
 
                 cl_mem_flags mem_flag = CL_MEM_READ_ONLY;
                 cl_mem *memin = new cl_mem[nextTask->inData_count];
-                if (!flag.flip) {
+                if (!flag.flip) { // set input data when not flip
                     for(int i=0;i<nextTask->inData_count;i++) {
                         memin[i] = clCreateBuffer(context, mem_flag, nextTask->inData(i)->size, NULL, NULL);
                         ListElement *input_buf = nextTask->inData(i);
@@ -113,7 +132,7 @@
                 cl_mem_flags out_mem_flag = flag.flip? CL_MEM_READ_WRITE : CL_MEM_WRITE_ONLY;
 
 
-                for(int i=0;i<nextTask->outData_count;i++) {
+                for(int i=0;i<nextTask->outData_count;i++) { // set output data
                     ListElement *output_buf = nextTask->outData(i);
                     memout[i] = clCreateBuffer(context, out_mem_flag, output_buf->size, NULL, &ret);
 
@@ -130,10 +149,12 @@
 
                 cl_event ev = NULL;
                 ret = clEnqueueTask(command_queue[cur], kernel, 0, NULL, &ev);
+
                 // ndrange flagが0ならdim,global_work_size[0],local_work_size[0] = 1で固定に
                 // clEnqueueNDRange
                 // (command_queue[cur], kernel, dim, NULL,global_work_size[0],local_work_size[0],NULL&ev);
-                for(int i=0;i<nextTask->outData_count;i++) {
+
+                for(int i=0;i<nextTask->outData_count;i++) { // read output data
                     ListElement *output_buf = nextTask->outData(i);
                     ret = clEnqueueReadBuffer(command_queue[cur], memout[i], CL_TRUE, 0,
                                               output_buf->size, output_buf->addr, 1, &ev, NULL);
@@ -143,7 +164,6 @@
 
             reply[cur] = (memaddr)tasklist->waiter;
             clFlush(command_queue[1-cur]); // waiting for queued task
-            //clFinish(command_queue[cur]); // waiting for queued task
             // pipeline    : 1-cur
             // no pipeline : cur
 
@@ -159,7 +179,7 @@
           connector->mail_write(reply[1-cur]);
 
 
-        connector->mail_write((memaddr)MY_SPE_STATUS_READY);
+          connector->mail_write((memaddr)MY_SPE_STATUS_READY);
     }
     // TaskArrayの処理
 }
@@ -171,6 +191,9 @@
     return 0;
 }
 
+/*
+ * kernel file open and build program
+ */
 void
 GpuScheduler::load_kernel(int cmd)
 {
@@ -216,6 +239,9 @@
 
 }
 
+
+
+// regist kernel file name
 void
 gpu_register_task(int cmd, const char* filename, const char* functionname)
 {
@@ -226,12 +252,4 @@
     task_list[cmd].gputask->kernel = (cl_kernel *) filename;
 }
 
-void
-gpu_register_ndrange(int cmd, int dim, size_t* l_work_size)
-{
-    task_list[cmd].gputask->dim = dim;
-    task_list[cmd].gputask->l_work_size = l_work_size;
-
-}
-
 /* end */
--- a/TaskManager/Gpu/GpuScheduler.h	Sun Nov 25 21:10:50 2012 +0900
+++ b/TaskManager/Gpu/GpuScheduler.h	Thu Dec 06 16:49:41 2012 +0900
@@ -47,12 +47,7 @@
 
 #define GpuSchedRegister(str, filename, functionname)   \
     gpu_register_task(str, filename, functionname);
-
-#define GpuNDRangeRegister(str, dimension, g_worksizePtr)   \
-    gpu_register_ndrange(str, dimension, g_worksizePtr);
-
 #endif
 
 extern void gpu_register_task(int cmd,const char* filename,const char* functionname);
-extern void gpu_register_ndrange(int, int, size_t*);
 
--- a/example/many_task/main.cc	Sun Nov 25 21:10:50 2012 +0900
+++ b/example/many_task/main.cc	Thu Dec 06 16:49:41 2012 +0900
@@ -74,11 +74,13 @@
 static void
 show_data(void)
 {
+    /*
     puts("-----------------------------------------------");
     for(int i = 0; i < sorter.data_length; i++) {
         printf("data[%02d].index = %d\n", i, sorter.data[i].index);
     }
     puts("-----------------------------------------------");
+    */
 }
 
 static void