# HG changeset patch # User Yuhi TOMARI # Date 1341222931 -32400 # Node ID bde20cca45aed4d3b4075732d0e3360a78c453f7 # Parent d79256b51d7fb8a3a400eb30c57864ef284dd066 remove schedrun diff -r d79256b51d7f -r bde20cca45ae TaskManager/Fifo/FifoDmaManager.cc --- a/TaskManager/Fifo/FifoDmaManager.cc Tue Jun 12 13:18:03 2012 +0900 +++ b/TaskManager/Fifo/FifoDmaManager.cc Mon Jul 02 18:55:31 2012 +0900 @@ -212,7 +212,7 @@ int FifoDmaManager::has_mail_from_host() { - return mail_queue1->count(); + return mail_queue1->count(); } void diff -r d79256b51d7f -r bde20cca45ae TaskManager/Gpu/GpuFunc.h --- a/TaskManager/Gpu/GpuFunc.h Tue Jun 12 13:18:03 2012 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,5 +0,0 @@ -enum { -#include "SysTasks.h" - SchedRun, - RUN_FINISH, -}; diff -r d79256b51d7f -r bde20cca45ae TaskManager/Gpu/GpuScheduler.cc --- a/TaskManager/Gpu/GpuScheduler.cc Tue Jun 12 13:18:03 2012 +0900 +++ b/TaskManager/Gpu/GpuScheduler.cc Mon Jul 02 18:55:31 2012 +0900 @@ -6,7 +6,6 @@ #include "stdio.h" #include #include -SchedDefineTask1(SchedRun,schedrun); void GpuScheduler::init_impl(int useRefDma) @@ -15,55 +14,28 @@ connector = fifoDmaManager; } -static int -schedrun(SchedTask *smanager, void *rbuf, void *wbuf){ - - cl_int ret = gputhreads->ret; - cl_context context = gputhreads->context; - cl_command_queue command_queue = gputhreads->command_queue; - long count = (long)s->get_param(0); - - for(int c = 0; cget_param(c+1); - - cl_mem memobj = clCreateBuffer(context, CL_MEM_READ_WRITE, - sizeof(int)*length, NULL, &ret); - - ret = clEnqueueWriteBuffer(command_queue, memobj, CL_TRUE, 0, - sizeof(int)*length, s->get_input(rbuf, c), 0, NULL, NULL); - - clSetKernelArg(kernel, c, sizeof(cl_mem), (void *)&memobj); - } - - cl_kernel kernel = *(task_list[cmd].kernel); - cl_event ev; - clEnqueueTask(command_queue, kernel, 0, NULL, &ev); - - clReleaseCommandQueue(command_queue); - clReleaseContext(context); - clReleaseKernel(kernel); - return 0 ; -} void GpuScheduler::run() { - 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; - cl_int ret; - - if ((memaddr)params_addr == (memaddr)MY_SPE_COMMAND_EXIT) { - clFinish(command_queue); - } - - TaskListPtr tasklist = (TaskListPtr)connector->dma_load(this, params_addr, - sizeof(TaskList), DMA_READ_TASKLIST); - - for (int cur_index = 0; cur_index < tasklist->length; cur_index++) { + for (;;) { + 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; + cl_int ret; + + if ((memaddr)params_addr == (memaddr)MY_SPE_COMMAND_EXIT) { + clFinish(command_queue); + return ; + } + + TaskListPtr tasklist = (TaskListPtr)connector->dma_load(this, params_addr, + sizeof(TaskList), DMA_READ_TASKLIST); + + for (int cur_index = 0; cur_index < tasklist->length; cur_index++) { SimpleTaskPtr nextTask = &tasklist->tasks[cur_index]; cl_kernel& kernel = *task_list[nextTask->command].kernel; @@ -80,7 +52,18 @@ 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); } + } + + clFlush(command_queue); // waiting for queued task + +#ifdef TASK_LIST_MAILOD + if (!(cur_index < list->length) ) + connector->mail_write(waiter); +#else + connector->mail_write(waiter); +#endif } + // TaskArrayの処理 } diff -r d79256b51d7f -r bde20cca45ae TaskManager/Gpu/GpuTaskManagerImpl.cc --- a/TaskManager/Gpu/GpuTaskManagerImpl.cc Tue Jun 12 13:18:03 2012 +0900 +++ b/TaskManager/Gpu/GpuTaskManagerImpl.cc Mon Jul 02 18:55:31 2012 +0900 @@ -1,14 +1,22 @@ #include "GpuTaskManagerImpl.h" #include "MainScheduler.h" #include "SchedTask.h" +#include "HTask.h" +#include "QueueInfo.h" +#include "ExportTaskLog.h" +#include "SchedTask.h" +#include "MainScheduler.h" +#include "types.h" +#include "SysFunc.h" +static void send_alloc_reply(GpuTaskManagerImpl *tm, int id, + GpuThreads *gpuThreads); GpuTaskManagerImpl::~GpuTaskManagerImpl() { - } void GpuTaskManagerImpl::init(int spuIdle,int useRefDma) { - + gpuTaskList = new QueueInfo; taskListInfo = new QueueInfo; @@ -20,8 +28,9 @@ htaskImpl = activeTaskQueue; mscheduler->set_manager(this); - gpuThreads->init(); - + // GpuThreads* gpuThreads = GpuThreads::getInstance(); + // gpuThreads->init(); + schedTaskManager = new SchedTask(); schedTaskManager->init(0, 0, 0, ppeManager->get_scheduler(), 0); ppeManager->schedTaskManager = schedTaskManager; @@ -79,14 +88,112 @@ gpuThreads->send_mail(0, 0, (memaddr *) &p); } +/** + * メールをチェックする + */ + +static void send_alloc_reply(GpuTaskManagerImpl *tm, int id, + GpuThreads *gpuThreads) { + + /** + * info[0] = alloc_id; (CellScheduler::mainMem_alloc 参照) + * info[1] = alloc_addr; + */ + memaddr alloc_info[2]; + long alloc_size; + long command; + + gpuThreads->get_mail(0, 2, alloc_info); + command = (long) alloc_info[0]; + alloc_size = (long) alloc_info[1]; + + alloc_info[1] = (memaddr) tm->allocate(alloc_size); + //__debug_ppe("[PPE] MALLOCED 0x%lx from [SPE %d]\n", alloc_info[1],id); + // 今のところ何もしてない。どうも、この allocate を free + // するのは、SPE task が返した値を見て行うらしい。それは、 + // 忘れやすいのではないか? + gpuThreads->add_output_tasklist(command, alloc_info[1], alloc_size); + + gpuThreads->send_mail(0, 2, alloc_info); +} + +void GpuTaskManagerImpl::mail_check() { + GpuThreads* gpuThreads = GpuThreads::getInstance(); + memaddr data; + + // SPE Scheduler からの mail check + while (gpuThreads->has_mail(0, 0, &data)) { + + if (data == (memaddr) MY_SPE_STATUS_READY) { + // MY_SPE_STATUS_READY: SPE が持ってた Task 全て終了 + // freeAll する前に循環リストに戻す + gpuTaskList->getLast()->next = gpuTaskList; + gpuTaskList->freeAll(); + // printf("SPE %d status ready, %d running\n",id, spe_running); + } else if (data == (memaddr) MY_SPE_COMMAND_MALLOC) { + + + // MY_SPE_COMMAND_MALLOC SPE からのmain memory request + send_alloc_reply(this, 0, gpuThreads); + } else if (data > (memaddr) MY_SPE_NOP) { + +#ifdef TASK_LIST_MAIL + TaskListPtr list = (TaskListPtr)data; + check_task_list_finish(schedTaskManager, list, waitTaskQueue); +#else + // 終了したタスク(PPEにあるのでアドレス) + HTaskPtr task = (HTaskPtr) data; +#if 0 + if (task->cpu_type != CPU_SPE) { + const char *name = get_task_name(task); + if (name != NULL) { + printf("[SPE] "); + printf("Task id : %d, ", task->command); + printf("Task name : %s\n", name); + } + } +#endif +#ifndef NOT_CHECK + + if (task != NULL) { + //SPE で処理された Task が返ってくるはず。それがもし、type PPE なら・・・ + if (task->cpu_type == CPU_PPE) { + printf("attention : PPE task run on SPE\n"); + printf("Task id : %d\n", task->command); + const char *name = get_task_name(task); + if (name != NULL) { + printf("Task name : %s\n", name); + } + } + } + +#endif + + task->post_func(schedTaskManager, task->post_arg1, task->post_arg2); + check_task_finish(task, waitTaskQueue); +#endif + + } + + + } +} + + + + +/* void GpuTaskManagerImpl::mail_check() { memaddr data; while (gpuThreads->has_mail(0, 0, &data)) { //どのメールが必要かよく考える - + //check_task_finish } -} + }*/ + + + #ifdef __CERIUM_GPU__ TaskManagerImpl* diff -r d79256b51d7f -r bde20cca45ae TaskManager/Gpu/GpuTaskManagerImpl.h --- a/TaskManager/Gpu/GpuTaskManagerImpl.h Tue Jun 12 13:18:03 2012 +0900 +++ b/TaskManager/Gpu/GpuTaskManagerImpl.h Mon Jul 02 18:55:31 2012 +0900 @@ -7,11 +7,11 @@ #include "QueueInfo.h" class GpuTaskManagerImpl : public TaskManagerImpl { -public: + public: GpuTaskManagerImpl(){}; - GpuTaskManagerImpl(int num, Threads *gpus) : TaskManagerImpl(num) {gpuThreads = gpus;} + GpuTaskManagerImpl(int num, GpuThreads *gpus) : TaskManagerImpl(num) {/*gpuThreads = gpus;*/} ~GpuTaskManagerImpl(); - + void init(int spuIdle,int useRefDma); void run(); void poll(); @@ -31,8 +31,7 @@ FifoTaskManagerImpl *ppeManager; - Threads *gpuThreads; - + GpuThreads *gpuThreads; }; #endif diff -r d79256b51d7f -r bde20cca45ae TaskManager/Gpu/task_init.cc --- a/TaskManager/Gpu/task_init.cc Tue Jun 12 13:18:03 2012 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,17 +0,0 @@ -#include "GpuFunc.h" -#include "Scheduler.h" - -/* 必ずこの位置に書いて */ -SchedExternTask(SchedRun); - -/** - * この関数は ../spe/spe-main と違って - * 自分で呼び出せばいい関数なので - * 好きな関数名でおk (SchedRegisterTask は必須) - */ - -void -task_init() -{ - SchedRegister(SchedRun); -} diff -r d79256b51d7f -r bde20cca45ae TaskManager/test/GpuRunTest/Makefile --- a/TaskManager/test/GpuRunTest/Makefile Tue Jun 12 13:18:03 2012 +0900 +++ b/TaskManager/test/GpuRunTest/Makefile Mon Jul 02 18:55:31 2012 +0900 @@ -1,11 +1,11 @@ include ./Makefile.def SRCS_TMP = $(wildcard *.cc) -SRCS_EXCLUDE = GpuTaskManagerImpl.cc # 除外するファイルを書く +SRCS_EXCLUDE = # 除外するファイルを書く SRCS = $(filter-out $(SRCS_EXCLUDE),$(SRCS_TMP)) OBJS = $(SRCS:.cc=.o) -LIBS += ../../libGpuManager.a `sdl-config --cflags` -framework opencl +LIBS += -lGpuManager -framework opencl `sdl-config --libs`#cflags` .SUFFIXES: .cc .o @@ -26,4 +26,3 @@ clean: rm -f $(TARGET) $(OBJS) rm -f *~ \#* - diff -r d79256b51d7f -r bde20cca45ae TaskManager/test/GpuRunTest/Makefile.def --- a/TaskManager/test/GpuRunTest/Makefile.def Tue Jun 12 13:18:03 2012 +0900 +++ b/TaskManager/test/GpuRunTest/Makefile.def Mon Jul 02 18:55:31 2012 +0900 @@ -1,4 +1,3 @@ -include ../../Makefile.def TARGET = GpuRunTest CERIUM = ../../../../Cerium @@ -6,5 +5,5 @@ CC = g++ CFLAGS = -g -Wall -INCLUDE = -I${CERIUM}/include/TaskManager -I. -I.. +INCLUDE = -I${CERIUM}/include/TaskManager -I. -I../.. LIBS = -L${CERIUM}/TaskManager