changeset 1437:fa6723e7d329 draft

fix GpuTaskManagerImpl
author Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
date Sat, 07 Apr 2012 09:29:09 +0900
parents 42057124fb44
children 3c787a21ff10
files TaskManager/Cell/CellTaskManagerImpl.cc TaskManager/Gpu/GpuScheduler.cc TaskManager/Gpu/GpuTaskManagerImpl.cc TaskManager/Gpu/GpuTaskManagerImpl.h TaskManager/Gpu/GpuThreads.cc TaskManager/Gpu/GpuThreads.h
diffstat 6 files changed, 133 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/TaskManager/Cell/CellTaskManagerImpl.cc	Fri Apr 06 18:30:09 2012 +0900
+++ b/TaskManager/Cell/CellTaskManagerImpl.cc	Sat Apr 07 09:29:09 2012 +0900
@@ -147,30 +147,28 @@
 }
 
 void CellTaskManagerImpl::run() {
-	int spu_limit = spuIdle;
-	if (machineNum == 0) {
-		ppeManager->run();
-		return;
-	}
-
-	do {
+    int spu_limit = spuIdle;
+    if (machineNum == 0) {
+        ppeManager->run();
+        return;
+    }
 
-		// PPE side
-		ppeManager->poll();
-		// SPE side
-		do {
-			poll();
-		} while (ppeManager->activeTaskQueue->empty() && spe_running > 0);
+    do {
+        // PPE side
+        ppeManager->poll();
+        // SPE side
+        do {
+            poll();
+        } while (ppeManager->activeTaskQueue->empty() && spe_running > 0);
 
-		if (spe_running < spu_limit) {
-			debug_check_spe_idle(ppeManager->activeTaskQueue, spe_running);
-		}
+        if (spe_running < spu_limit) {
+            debug_check_spe_idle(ppeManager->activeTaskQueue, spe_running);
+        }
 
-	} while (!ppeManager->activeTaskQueue->empty() || !activeTaskQueue->empty()
-			|| spe_running > 0);
-	if (!waitTaskQueue->empty()) {
-		show_dead_lock_info();
-	}
+    } while (!ppeManager->activeTaskQueue->empty() || !activeTaskQueue->empty() || spe_running > 0);
+    if (!waitTaskQueue->empty()) {
+        show_dead_lock_info();
+    }
 
 }
 
--- a/TaskManager/Gpu/GpuScheduler.cc	Fri Apr 06 18:30:09 2012 +0900
+++ b/TaskManager/Gpu/GpuScheduler.cc	Sat Apr 07 09:29:09 2012 +0900
@@ -9,13 +9,29 @@
     connector = new GpuDmamanager;
 }
 
-void
+int
 GpuScheduler::run()
 {
     // command_queueにここで、enqueueする?
+    memaddr params_addr = connector->task_list_mail_read();
+
+    if ((memaddr)params_addr == (memaddr)MY_SPE_COMMAND_EXIT) {
+        // 終了確認
+        return 0;
+    }
+
+    TaskListPtr *tasklist = (TaskListPtr)connector->dma_load(tasklist, params_addr, 
+                                         sizeof(TaskList), DMA_READ_TASKLIST);
+    for (int cur_index = 0; cur_index < tasklist->length; cur_index++) {
+
+    }
+
+
 
 }
 
+
+
 void
 gpu_register_task(int cmd, char* filename, char* functionname)
 {
--- a/TaskManager/Gpu/GpuTaskManagerImpl.cc	Fri Apr 06 18:30:09 2012 +0900
+++ b/TaskManager/Gpu/GpuTaskManagerImpl.cc	Sat Apr 07 09:29:09 2012 +0900
@@ -7,7 +7,7 @@
 
 }
 
-void GpuTaskManagerImpl::init(int spuIdle_, int useRefDma) {
+void GpuTaskManagerImpl::init() {
 
     gpuTaskList = new QueueInfo<TaskList>
     TaskListInfo = new QueueInfo<TaskList>
@@ -27,10 +27,71 @@
     ppeManager->schedTaskManager = schedTaskManager;
 }
 
+void GpuTaskManagerImpl::run() {
+    do {
+        ppeManager->poll();
+        do {
+            poll();
+        } while (ppeManager->activeTaskQueue->empty());
+        // ちゃんと最後のタスクまで実行される?
+    } while (!ppeManager->activeTaskQueue->empty() || !activeTaskQueue->empty());
+}
+
+void GpuTaskManagerImpl::poll() {
+    set_runTaskList();
+    sendTaskList();
+}
+
+void GpuTaskManagerImpl::set_runTaskList() {
+    HtaskPtr htask = activeTaskQueue->getFirst();
+    while (htask != NULL) {
+        if (htask->cpu_type == CPU_PPE) {
+            htask = activeTaskQueue->getNext(htask);
+        } else {
+            set_taskList(htask, taskListInfo);
+
+            HtaskPtr next = activeTaskQueue->getNext(htask);
+            activeTaskQueue->remove(htask);
+            htask = next;
+        }
+    }
+}
+
+void GpuTaskManagerImpl::sendTaskList() {
+    mail_check();
+    if (!gpuTaskList->empty()) {
+        continue;
+    }
+    if (!taskListInfo->empty()) {
+        send_taskList();
+    }
+}
+
+void GpuTaskManagerImpl::send_taskList() {
+    // swap gpuTaskList for taskListInfo
+    QueueInfo<TaskList> *tmp = taskListInfo;
+    taskListInfo = gpuTaskList;
+    gpuTaskList = tmp;
+
+    gpuTaskList->getLast()->next = 0;
+    TaskListPtr p = gpuTaskList->getFirst();
+
+    // send taskList
+    gpuThreads->send_mail((memaddr *) &p);
+}
+
+void GpuTaskManagerImpl::mail_check() {
+    memaddr data;
+    while (speThreads->has_mail(&data)) {
+        //どのメールが必要かよく考える
+    }
+}
+
 #ifdef __CERIUM_GPU__
 TaskManagerImpl*
 create_impl(int num, int useRefDma)
 {
-    Threads *gpus = GpuThreads::getInstance();
-    return new CellTaskManagerImpl(num, cpus);
+    GpuThreads *gpus = GpuThreads::getInstance();
+    return new GpuTaskManagerImpl(num, gpus);
 }
+#endif
--- a/TaskManager/Gpu/GpuTaskManagerImpl.h	Fri Apr 06 18:30:09 2012 +0900
+++ b/TaskManager/Gpu/GpuTaskManagerImpl.h	Sat Apr 07 09:29:09 2012 +0900
@@ -13,6 +13,11 @@
 
     void init(int spuIdle,int useRefDma);
     void run();
+    void poll();
+    void set_runTaskList();
+    void sendTaskList();
+    void send_taskList();
+    void mail_check();
 
 public:
     QueueInfo<TaskList> *gpuTaskList;
@@ -20,7 +25,7 @@
 
     FifoTaskManagerImpl *ppeManager;
 
-    Threads *gpuThreads;
+    GpuThreads *gpuThreads;
     FifoTaskManagerImpl *ppeManager;
 
 };
--- a/TaskManager/Gpu/GpuThreads.cc	Fri Apr 06 18:30:09 2012 +0900
+++ b/TaskManager/Gpu/GpuThreads.cc	Sat Apr 07 09:29:09 2012 +0900
@@ -53,3 +53,26 @@
 
     return NULL
 }
+
+int
+GpuThreads::get_mail(memaddr *ret)
+{
+    *ret = args.scheduler->mail_read_from_host();
+    return 1;
+}
+
+int
+GpuThreads::has_mail(memaddr *ret)
+{
+    if (args.scheduler->has_mail_from_host() != 0) {
+        return get_mail(ret);
+    } else {
+        return 0;
+    }
+}
+
+void
+CpuThreads::send_mail(int cpuid, int num, memaddr *data)
+{
+    args.scheduler->mail_write_from_host(*data);
+}
--- a/TaskManager/Gpu/GpuThreads.h	Fri Apr 06 18:30:09 2012 +0900
+++ b/TaskManager/Gpu/GpuThreads.h	Sat Apr 07 09:29:09 2012 +0900
@@ -28,6 +28,10 @@
     void init(cl_device_id device_id;);
     void *gpu_thread_run(void *args);
 
+    int get_mail();
+    int has_mail();
+    void send_mail();
+
 public:
     cl_platform_id platform_id;
     cl_device_id device_id;
@@ -43,7 +47,6 @@
     gpu_arg *args;
     pthread_t *threads;
     int use_refdma;
-    cl_int ret;
 };
 
 #endif