Mercurial > hg > Members > kono > Cerium
changeset 800:2708c4a7bade
run16 word count ( not yet worked. )
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 21 May 2010 07:47:25 +0900 |
parents | bf4ee251767e |
children | 974cd68383b3 daab9cd6f91f |
files | TaskManager/Fifo/MainScheduler.cc TaskManager/kernel/ppe/TaskManager.cc TaskManager/kernel/ppe/TaskManagerImpl.cc TaskManager/kernel/ppe/TaskManagerImpl.h TaskManager/kernel/schedule/SchedTask.cc TaskManager/kernel/schedule/SchedTask.h TaskManager/kernel/schedule/SchedTaskArray.cc TaskManager/kernel/schedule/SchedTaskArray.h TaskManager/kernel/schedule/SchedTaskArrayLoad.cc TaskManager/kernel/schedule/SchedTaskBase.h TaskManager/kernel/schedule/Scheduler.cc TaskManager/kernel/schedule/Scheduler.h example/word_count_test/WordCount.h example/word_count_test/main.cc example/word_count_test/ppe/Exec.cc |
diffstat | 15 files changed, 117 insertions(+), 53 deletions(-) [+] |
line wrap: on
line diff
--- a/TaskManager/Fifo/MainScheduler.cc Wed May 19 19:49:49 2010 +0900 +++ b/TaskManager/Fifo/MainScheduler.cc Fri May 21 07:47:25 2010 +0900 @@ -2,6 +2,7 @@ #include <string.h> #include "MainScheduler.h" #include "FifoDmaManager.h" +#include "TaskManagerImpl.h" #include "error.h" void @@ -18,7 +19,7 @@ void MainScheduler::mainMem_alloc(int id, int size) { - mainMemList[id] = (memaddr)allocate(size); + mainMemList[id] = (memaddr)manager->allocate(size); } /* end */
--- a/TaskManager/kernel/ppe/TaskManager.cc Wed May 19 19:49:49 2010 +0900 +++ b/TaskManager/kernel/ppe/TaskManager.cc Fri May 21 07:47:25 2010 +0900 @@ -64,9 +64,7 @@ HTaskPtr TaskManager::create_task_array(int id, int num_task, int num_param, int num_inData, int num_outData) { - HTaskPtr ta = create_task(TaskArray,0,0,0,0); - ta->create_task_array(id, num_task, num_param, num_inData, num_outData) ; - return ta; + return m_impl->create_task_array(id, num_task, num_param, num_inData, num_outData) ; } /**
--- a/TaskManager/kernel/ppe/TaskManagerImpl.cc Wed May 19 19:49:49 2010 +0900 +++ b/TaskManager/kernel/ppe/TaskManagerImpl.cc Fri May 21 07:47:25 2010 +0900 @@ -70,6 +70,14 @@ return new_task; } +HTaskPtr +TaskManagerImpl::create_task_array(int id, int num_task, int num_param, int num_inData, int num_outData) +{ + HTaskPtr ta = create_task(TaskArray,0,0,0,0); + ta->create_task_array(id, num_task, num_param, num_inData, num_outData) ; + return ta; +} + /** * task の依存関係を設定 * master task が終わってから、slave task を実行するように @@ -107,6 +115,7 @@ // systask_finish->wait_for(task); } + /** * Task を実行可能キューに追加する */
--- a/TaskManager/kernel/ppe/TaskManagerImpl.h Wed May 19 19:49:49 2010 +0900 +++ b/TaskManager/kernel/ppe/TaskManagerImpl.h Fri May 21 07:47:25 2010 +0900 @@ -7,7 +7,6 @@ #include "TaskQueueInfo.h" #include "HTaskInfo.h" #include "Scheduler.h" -//class Scheduler; class MemList; @@ -47,6 +46,8 @@ // user virtual HTaskPtr create_task(int cmd); virtual HTaskPtr create_task(int cmd, memaddr rbuf, long r_size, memaddr wbuf, long w_size); + virtual HTaskPtr create_task_array(int id, int num_task, int num_param, int num_inData, int num_outData); + virtual void set_task_depend(HTaskPtr master, HTaskPtr slave); virtual void spawn_task(HTaskPtr); virtual void set_task_cpu(HTaskPtr, CPU_TYPE);
--- a/TaskManager/kernel/schedule/SchedTask.cc Wed May 19 19:49:49 2010 +0900 +++ b/TaskManager/kernel/schedule/SchedTask.cc Fri May 21 07:47:25 2010 +0900 @@ -50,7 +50,8 @@ scheduler = sc; cur_index = index; - scheduler->mainMem_wait(); // これはなんで? + // scheduler->mainMem_wait(); // これはなんで? + manager = sc->manager; } @@ -67,7 +68,7 @@ // 読むデータが一つもなければ無視 if (task->r_size == 0) return; // load Input Data - readbuf = scheduler->allocate(task->r_size); + readbuf = manager->allocate(task->r_size); scheduler->dma_load(readbuf, task->rbuf,task->r_size, DMA_READ); @@ -80,7 +81,7 @@ __debug("[SchedTask:%s]\n", __FUNCTION__); if (task->w_size > 0) { - writebuf = scheduler->allocate(task->w_size); + writebuf = manager->allocate(task->w_size); } scheduler->dma_wait(DMA_READ); task_list[task->command].wait(scheduler,task->command); @@ -251,39 +252,44 @@ HTaskPtr SchedTask::create_task(int cmd) { - return scheduler->create_task(cmd); + return manager->create_task(cmd); } HTaskPtr SchedTask::create_task(int cmd, memaddr r, long rs, memaddr w, long ws) { - return scheduler->create_task(cmd,r,rs,w,ws); + return manager->create_task(cmd,r,rs,w,ws); +} + +HTaskPtr +SchedTask::create_task_array(int id, int num_task, int num_param, int num_inData, int num_outData) { + return manager->create_task_array(id, num_task, num_param, num_inData, num_outData) ; } void SchedTask::set_task_depend(HTaskPtr master, HTaskPtr slave) { - scheduler->set_task_depend(master, slave); + manager->set_task_depend(master, slave); } void SchedTask::spawn_task(HTaskPtr t) { - scheduler->spawn_task(t); + manager->spawn_task(t); } void SchedTask::set_task_cpu(HTaskPtr t, CPU_TYPE cpu) { - scheduler->set_task_cpu(t, cpu); + manager->set_task_cpu(t, cpu); } void* SchedTask::allocate(int size) { - return scheduler->allocate(size) ; + return manager->allocate(size) ; } void* SchedTask::allocate(int size,int align) { - return scheduler->allocate(size,align) ; + return manager->allocate(size,align) ; } Scheduler* SchedTask::get_scheduler()
--- a/TaskManager/kernel/schedule/SchedTask.h Wed May 19 19:49:49 2010 +0900 +++ b/TaskManager/kernel/schedule/SchedTask.h Fri May 21 07:47:25 2010 +0900 @@ -94,6 +94,7 @@ // user HTaskPtr create_task(int cmd); HTaskPtr create_task(int cmd, memaddr r, long rs, memaddr w, long ws); + HTask *create_task_array(int id, int num_task, int num_param, int num_inData, int num_outData); void set_task_depend(HTaskPtr master, HTaskPtr slave); void spawn_task(HTaskPtr);
--- a/TaskManager/kernel/schedule/SchedTaskArray.cc Wed May 19 19:49:49 2010 +0900 +++ b/TaskManager/kernel/schedule/SchedTaskArray.cc Fri May 21 07:47:25 2010 +0900 @@ -1,6 +1,7 @@ #include "SchedTaskArray.h" #include "SchedTaskArrayNop.h" #include "Scheduler.h" +#include "TaskManagerImpl.h" SchedTaskArray::SchedTaskArray(Scheduler *s, SchedTaskBase *savedTask_, Task *curTask_, Task *_array) @@ -84,10 +85,10 @@ inListData.length = atask->inData_count; inListData.size = atask->inData_total_size(); inListData.element = atask->inData(0); - inListData.bound = (int*)scheduler->allocate(inListData.length*sizeof(int)); + inListData.bound = (int*)manager->allocate(inListData.length*sizeof(int)); // load Input Data - readbuf = scheduler->allocate(inListData.size); + readbuf = manager->allocate(inListData.size); // inListData.print(); scheduler->dma_loadList(&inListData, readbuf, DMA_READ); bound(&inListData); @@ -106,10 +107,10 @@ outListData.length = atask->outData_count; outListData.size = atask->outData_total_size(); outListData.element = atask->outData(0); - outListData.bound = (int*)scheduler->allocate(outListData.length*sizeof(int)); + outListData.bound = (int*)manager->allocate(outListData.length*sizeof(int)); bound(&outListData); - writebuf = scheduler->allocate(outListData.size); + writebuf = manager->allocate(outListData.size); } scheduler->dma_wait(DMA_READ); @@ -244,5 +245,12 @@ return *atask->param(index); } +int +SchedTaskArray::read_size() +{ + printf("Don't use read_size() in TaskArray, use get_inputSize(index)\n"); + return 0; +} + /* end */
--- a/TaskManager/kernel/schedule/SchedTaskArray.h Wed May 19 19:49:49 2010 +0900 +++ b/TaskManager/kernel/schedule/SchedTaskArray.h Fri May 21 07:47:25 2010 +0900 @@ -40,6 +40,7 @@ memaddr get_outputAddr(int); int get_outputSize(int); memaddr get_param(int); + int read_size(); };
--- a/TaskManager/kernel/schedule/SchedTaskArrayLoad.cc Wed May 19 19:49:49 2010 +0900 +++ b/TaskManager/kernel/schedule/SchedTaskArrayLoad.cc Fri May 21 07:47:25 2010 +0900 @@ -1,6 +1,7 @@ #include "SchedTaskArrayLoad.h" #include "SchedTaskArray.h" #include "Task.h" +#include "TaskManagerImpl.h" SchedTaskArrayLoad::SchedTaskArrayLoad(Scheduler *s, SchedTaskBase *savedTask_) @@ -17,7 +18,7 @@ { // if (task->r_size == 0) return; cannot happen... // load Task Array Data - readbuf = scheduler->allocate(task->r_size); + readbuf = manager->allocate(task->r_size); scheduler->dma_load(readbuf, task->rbuf,task->r_size, DMA_READ); }
--- a/TaskManager/kernel/schedule/SchedTaskBase.h Wed May 19 19:49:49 2010 +0900 +++ b/TaskManager/kernel/schedule/SchedTaskBase.h Fri May 21 07:47:25 2010 +0900 @@ -2,11 +2,10 @@ #define INCLUDED_SCHED_TASK_BASE #include "base.h" -#include "Scheduler.h" #include <stdio.h> #include <stdlib.h> - +class TaskManagerImpl; class Scheduler; class SchedTaskBase { @@ -31,6 +30,7 @@ virtual void* get_output(void *buff, int index) { return 0; } virtual void* get_input(void *buff, int index) { return 0;} virtual memaddr get_param(int index) { return 0;} + virtual int read_size() { return 0;} /* variables */ @@ -39,6 +39,8 @@ // Task を実行するスケジューラ自身 Scheduler *scheduler; + // Task を作成管理するマネージャー + TaskManagerImpl *manager; SimpleTaskPtr task; TaskPtr atask;
--- a/TaskManager/kernel/schedule/Scheduler.cc Wed May 19 19:49:49 2010 +0900 +++ b/TaskManager/kernel/schedule/Scheduler.cc Fri May 21 07:47:25 2010 +0900 @@ -47,7 +47,7 @@ init_impl(); for (int i = 0; i < 2; i++) { - buff_taskList[i] = (TaskListPtr)allocate(sizeof(TaskList)); + buff_taskList[i] = (TaskListPtr)m->allocate(sizeof(TaskList)); } buffFlag_taskList = 0; @@ -162,7 +162,7 @@ Scheduler::global_alloc(int id, int size) { - globalList[id] = allocate(size); + globalList[id] = manager->allocate(size); return globalList[id]; } @@ -303,7 +303,7 @@ { uint32 head_size = round_up16(sizeof(MemorySegment)); uint32 seg_size = round_up16(head_size+size); - char* mseg = (char*)allocate(seg_size*count); + char* mseg = (char*)manager->allocate(seg_size*count); MemList* mlist = new MemList((MemorySegment*)mseg); if (!hash) { @@ -415,18 +415,6 @@ s->tag = 0; } -HTask * Scheduler::create_task(int cmd) { return manager->create_task(cmd); } -HTaskPtr Scheduler::create_task(int cmd, memaddr r, long rs, memaddr w, long ws) { - return manager->create_task(cmd,r,rs,w,ws); -} - -void Scheduler::set_task_depend(HTask * master, HTask * slave) { - manager->set_task_depend(master, slave) ; -} -void Scheduler::spawn_task(HTask * t) { manager->spawn_task(t); } -void Scheduler::set_task_cpu(HTask * t, CPU_TYPE cpu) { manager->set_task_cpu(t,cpu); } -void* Scheduler::allocate(int size,int align) { return manager->allocate(size,align); } -void* Scheduler::allocate(int size) { return manager->allocate(size,DEFAULT_ALIGNMENT); } long Scheduler::get_random() { #if defined(__SPU__) return 0;
--- a/TaskManager/kernel/schedule/Scheduler.h Wed May 19 19:49:49 2010 +0900 +++ b/TaskManager/kernel/schedule/Scheduler.h Fri May 21 07:47:25 2010 +0900 @@ -126,15 +126,8 @@ void set_manager(TaskManagerImpl *m) { manager = m; }; - // user - HTask * create_task(int cmd); - HTask * create_task(int cmd, memaddr r, long rs, memaddr w, long ws); + /* user */ - void set_task_depend(HTask * master, HTask * slave) ; - void spawn_task(HTask * t) ; - void set_task_cpu(HTask * t, CPU_TYPE cpu) ; - void *allocate(int size); - void* allocate(int size,int align) ; long get_random() ; Scheduler *get_scheduler() { return this; }; int printf(const char *format, ...);
--- a/example/word_count_test/WordCount.h Wed May 19 19:49:49 2010 +0900 +++ b/example/word_count_test/WordCount.h Fri May 21 07:47:25 2010 +0900 @@ -1,3 +1,4 @@ +#include "TaskManager.h" typedef struct wordCount { struct wordCount *self; @@ -15,5 +16,25 @@ int pad; char * file_mmap; HTaskPtr t_print; + int waiting; + int pipeline_count; + HTaskPtr *wait_list; } WordCount; +static inline HTask * +next_wait_task(WordCount *w, HTask *next) +{ + w->waiting = (w->waiting+1)%w->pipeline_count; + HTask *wait = w->wait_list[w->waiting]; + w->wait_list[w->waiting] = next; + return wait; +} + +static inline void +set_pipeline_count(WordCount *w, TaskManager *m, int p) +{ + w->pipeline_count = p; + w->wait_list = (HTaskPtr *)m->allocate(sizeof(HTaskPtr)*p); + bzero(w->wait_list,sizeof(HTaskPtr)*p); +} +
--- a/example/word_count_test/main.cc Wed May 19 19:49:49 2010 +0900 +++ b/example/word_count_test/main.cc Fri May 21 07:47:25 2010 +0900 @@ -11,6 +11,8 @@ #include "Func.h" #include "WordCount.h" +#define TASKARRAY + extern void task_init(); const char *usr_help_str = "Usage: ./word_count [-cpu spe_num] [-file filename]\n"; @@ -68,13 +70,39 @@ } +#ifdef TASKARRAY +static HTask * +run_tasks(SchedTask *manager, WordCount *w, int task_count, HTaskPtr t_next, int size) +{ + HTask *t_exec = manager->create_task_array(TASK_EXEC,task_count,0,1,1); + Task *t = 0; + for (int j = 0; j < task_count && w->size>0; j++) { + int i = w->task_spwaned++; + // printf("div %0x\n", (w->file_mmap + i*w->division_size)); + t = t_exec->next_task_array(TASK_EXEC, t); + t->set_inData(0, (memaddr)(w->file_mmap + i*w->division_size), size); + t->set_outData(0, (memaddr)(w->o_data + i*w->out_size), w->division_out_size); + w->size -= size; + w->task_num--; + } + if (w->size!=0) { + printf("bad align %d\n",w->size); + } + t_exec->spawn_task_array(t->next()); + t_exec->set_cpu(SPE_ANY); + t_next->wait_for(t_exec); + t_exec->spawn(); + return t_exec; +} +#else static void run_tasks(SchedTask *manager, WordCount *w, int task_count, HTaskPtr t_next, int size) { + HTaskPtr t_exec = 0; for (int j = 0; j < task_count && w->size>0; j++) { int i = w->task_spwaned++; // printf("div %0x\n", (w->file_mmap + i*w->division_size)); - HTaskPtr t_exec = manager->create_task(TASK_EXEC, + t_exec = manager->create_task(TASK_EXEC, (memaddr)(w->file_mmap + i*w->division_size), size, (memaddr)(w->o_data + i*w->out_size), w->division_out_size); t_exec->set_cpu(SPE_ANY); @@ -83,7 +111,9 @@ w->size -= size; w->task_num--; } + return t_exec; } +#endif SchedDefineTask1(RUN_TASK_BLOCKS,run16); @@ -102,18 +132,21 @@ HTaskPtr t_next = manager->create_task(RUN_TASK_BLOCKS, (memaddr)&w->self,sizeof(memaddr),0,0); w->t_print->wait_for(t_next); - - run_tasks(manager,w, w->task_blocks, t_next, w->division_size); - + HTask *wait = next_wait_task(w, t_next); + HTask *exec = run_tasks(manager,w, w->task_blocks, w->t_print, w->division_size); + if (wait) { + wait->wait_for(t_next); + wait->wait_for(exec); + } t_next->spawn(); // printf("run16 next %d\n",w->task_num); } return 0; } - static int blocks = 48; static int division = 16; // in Kbyte +static int pipeline = 16; // Pipelined Tasks Blocks static int profile = 0; static void @@ -125,6 +158,7 @@ st_mmap = my_mmap(filename); WordCount *w = (WordCount*)manager->allocate(sizeof(WordCount)); // bzero(w,sizeof(WordCount)); + set_pipeline_count(w,manager,pipeline); w->self = w; w->task_blocks = blocks;
--- a/example/word_count_test/ppe/Exec.cc Wed May 19 19:49:49 2010 +0900 +++ b/example/word_count_test/ppe/Exec.cc Fri May 21 07:47:25 2010 +0900 @@ -9,10 +9,10 @@ static int run(SchedTask *s, void *rbuf, void *wbuf) { - char *i_data = (char *)rbuf; - unsigned long long *o_data = (unsigned long long*)wbuf; + char *i_data = (char *)s->get_input(0); + unsigned long long *o_data = (unsigned long long*)s->get_output(0); unsigned long long *head_tail_flag = o_data +2; - int length = s->read_size(); + int length = s->get_inputSize(0); int word_flag = 0; int word_num = 0;