Mercurial > hg > Game > Cerium
changeset 1468:840dee241530 draft
merge
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 15 Jul 2012 17:42:10 +0900 |
parents | d585a7614cd5 (current diff) bde20cca45ae (diff) |
children | 9088e6f2c2e0 |
files | TaskManager/Cell/CellTaskManagerImpl.cc TaskManager/Cell/spe/SpeTaskManagerImpl.h TaskManager/Fifo/FifoTaskManagerImpl.cc TaskManager/Makefile.def TaskManager/kernel/ppe/HTask.cc TaskManager/kernel/ppe/TaskLog.h TaskManager/kernel/ppe/TaskManagerImpl.cc TaskManager/kernel/ppe/TaskManagerImpl.h TaskManager/kernel/schedule/Scheduler.cc example/OpenCL/twice.cc scripts/view_log.sh |
diffstat | 43 files changed, 1391 insertions(+), 71 deletions(-) [+] |
line wrap: on
line diff
--- a/TaskManager/Cell/CellTaskManagerImpl.cc Sun Jul 15 17:33:50 2012 +0900 +++ b/TaskManager/Cell/CellTaskManagerImpl.cc Sun Jul 15 17:42:10 2012 +0900 @@ -6,6 +6,7 @@ #include "CellTaskManagerImpl.h" #include "HTask.h" #include "QueueInfo.h" +#include "ExportTaskLog.h" #include "SchedTask.h" #include "MainScheduler.h" #include "types.h" @@ -146,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(); + } } @@ -348,6 +347,11 @@ } } +void CellTaskManagerImpl::export_task_log() { + ExportTaskLog _export(taskLogQueue); + _export.printOut(); +} + void CellTaskManagerImpl::print_arch() { printf("CellTaskManager\n"); }
--- a/TaskManager/Cell/CellTaskManagerImpl.h Sun Jul 15 17:33:50 2012 +0900 +++ b/TaskManager/Cell/CellTaskManagerImpl.h Sun Jul 15 17:42:10 2012 +0900 @@ -39,6 +39,7 @@ void append_activeTask(HTaskPtr); void show_profile() ; void start_profile() ; + void export_task_log() ; void polling(); void debug_check_spe_idle(QueueInfo<HTask> * activeTaskQueue, int spe_running_); void print_arch();
--- a/TaskManager/Cell/spe/SpeTaskManagerImpl.cc Sun Jul 15 17:33:50 2012 +0900 +++ b/TaskManager/Cell/spe/SpeTaskManagerImpl.cc Sun Jul 15 17:42:10 2012 +0900 @@ -16,6 +16,7 @@ void SpeTaskManagerImpl::show_profile() {} void SpeTaskManagerImpl::start_profile() {} +void SpeTaskManagerImpl::export_task_log() {} void SpeTaskManagerImpl::print_arch() { printf("SpeTaskManagerImpl\n"); }
--- a/TaskManager/Cell/spe/SpeTaskManagerImpl.h Sun Jul 15 17:33:50 2012 +0900 +++ b/TaskManager/Cell/spe/SpeTaskManagerImpl.h Sun Jul 15 17:42:10 2012 +0900 @@ -20,6 +20,7 @@ void run(); void start_profile(); void show_profile(); + void export_task_log(); HTaskPtr create_task(int cmd); HTaskPtr create_task(int cmd, memaddr rbuf, long r_size, memaddr wbuf, long w_size); HTaskPtr create_task_array(int cmd, memaddr rbuf, long rs, memaddr wbuf, long ws);
--- a/TaskManager/Fifo/FifoDmaManager.cc Sun Jul 15 17:33:50 2012 +0900 +++ b/TaskManager/Fifo/FifoDmaManager.cc Sun Jul 15 17:42:10 2012 +0900 @@ -212,7 +212,7 @@ int FifoDmaManager::has_mail_from_host() { - return mail_queue1->count(); + return mail_queue1->count(); } void
--- a/TaskManager/Fifo/FifoTaskManagerImpl.cc Sun Jul 15 17:33:50 2012 +0900 +++ b/TaskManager/Fifo/FifoTaskManagerImpl.cc Sun Jul 15 17:42:10 2012 +0900 @@ -314,6 +314,9 @@ } } +void FifoTaskManagerImpl::export_task_log() { +} + void FifoTaskManagerImpl::print_arch() {
--- a/TaskManager/Fifo/FifoTaskManagerImpl.h Sun Jul 15 17:33:50 2012 +0900 +++ b/TaskManager/Fifo/FifoTaskManagerImpl.h Sun Jul 15 17:42:10 2012 +0900 @@ -29,6 +29,7 @@ void run(); void show_profile(); void start_profile(); + void export_task_log(); void polling(); TaskListPtr createTaskList();
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Gpu/GpuScheduler.cc Sun Jul 15 17:42:10 2012 +0900 @@ -0,0 +1,119 @@ +#include "GpuScheduler.h" +#include "ReferencedDmaManager.h" +#include "SchedTask.h" +#include "GpuFunc.h" +#include "GpuThreads.h" +#include "stdio.h" +#include <fcntl.h> +#include <sys/stat.h> + +void +GpuScheduler::init_impl(int useRefDma) +{ + fifoDmaManager = new ReferencedDmaManager(); + connector = fifoDmaManager; +} + + +void +GpuScheduler::run() +{ + 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; + + 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); + //clSetKernleArg(kernel, cur_index,); + } + // カーネル引数の設定 + + clEnqueueTask(command_queue, kernel, 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); + } + } + + 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の処理 +} + + + +void +gpu_register_task(int cmd, const char* filename, const char* functionname) +{ + GpuThreads* gputhreads = GpuThreads::getInstance(); + //gputhreads->init(); + cl_context context = gputhreads->context; + cl_device_id device_id = gputhreads->device_id; + + int fp; + char *source_str; + size_t source_size; + + fp = open(filename, O_RDONLY); + + if (!fp) { + fprintf(stderr, "Failed to load kernel.\n"); + exit(1); + } + + struct stat stats; + fstat(fp,&stats); + off_t size = stats.st_size; + + if (!size) { + fprintf(stderr, "Failed to load kernel.\n"); + exit(1); + } + + source_str = (char*)malloc(size); + source_size = read(fp, source_str, size); + close(fp); + + cl_program program = NULL; + cl_int ret = gputhreads->ret; + program = clCreateProgramWithSource(context, 1, (const char **)&source_str, + (const size_t *)&source_size, &ret); + clBuildProgram(program, 1, &device_id, NULL, NULL, NULL); + + cl_kernel *kernel = new cl_kernel; + *kernel = clCreateKernel(program, functionname, &ret); + + 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; + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Gpu/GpuScheduler.h Sun Jul 15 17:42:10 2012 +0900 @@ -0,0 +1,37 @@ +#ifndef INCLUDED_GPU_SCHEDULER +#define INCLUDED_GPU_SCHEDULER + +#include "Scheduler.h" +#include "FifoDmaManager.h" + +#ifdef __APPLE__ +#include <OpenCL/opencl.h> +#else +#include <CL/cl.h> +#endif + +class GpuScheduler : public Scheduler { +public: + void init_impl(int useRefDma); + void run(); + + void mail_write_from_host(memaddr data) { + fifoDmaManager->mail_write_from_host(data); + } + + memaddr mail_read_from_host() { + return fifoDmaManager->mail_read_from_host(); + } + + int has_mail_from_host() { + return fifoDmaManager->has_mail_from_host(); + } + +private: + FifoDmaManager *fifoDmaManager; +}; + +#endif + +#define GpuSchedRegister(str, filename, functionname) \ + gpu_register_task(str, filename, functionname);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Gpu/GpuTaskManagerImpl.cc Sun Jul 15 17:42:10 2012 +0900 @@ -0,0 +1,205 @@ +#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<TaskList>; + taskListInfo = new QueueInfo<TaskList>; + + ppeManager = new FifoTaskManagerImpl(machineNum); + MainScheduler *mscheduler = new MainScheduler; + set_scheduler(mscheduler); + ppeManager->init(mscheduler, this, useRefDma); + + htaskImpl = activeTaskQueue; + mscheduler->set_manager(this); + + // GpuThreads* gpuThreads = GpuThreads::getInstance(); + // gpuThreads->init(); + + schedTaskManager = new SchedTask(); + schedTaskManager->init(0, 0, 0, ppeManager->get_scheduler(), 0); + 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()) { + } + 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(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* +create_impl(int num, int useRefDma) +{ + GpuThreads *gpus = GpuThreads::getInstance(); + return new GpuTaskManagerImpl(num, gpus); +} +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Gpu/GpuTaskManagerImpl.h Sun Jul 15 17:42:10 2012 +0900 @@ -0,0 +1,38 @@ +#ifndef INCLUDED_GPU_TASK_MANAGER_IMPL +#define INCLUDED_GPU_TASK_MANAGER_IMPL + +#include "TaskManagerImpl.h" +#include "FifoTaskManagerImpl.h" +#include "GpuThreads.h" +#include "QueueInfo.h" + +class GpuTaskManagerImpl : public TaskManagerImpl { + public: + GpuTaskManagerImpl(){}; + GpuTaskManagerImpl(int num, GpuThreads *gpus) : TaskManagerImpl(num) {/*gpuThreads = gpus;*/} + ~GpuTaskManagerImpl(); + + void init(int spuIdle,int useRefDma); + void run(); + void poll(); + void set_runTaskList(); + void sendTaskList(); + void send_taskList(); + void mail_check(); + + void start_profile(){} + void show_profile(){} + void polling(){} + void print_arch(){} + +public: + QueueInfo<TaskList> *gpuTaskList; + QueueInfo<TaskList> *taskListInfo; + + FifoTaskManagerImpl *ppeManager; + + GpuThreads *gpuThreads; +}; + +#endif +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Gpu/GpuThreads.cc Sun Jul 15 17:42:10 2012 +0900 @@ -0,0 +1,83 @@ +#include "GpuThreads.h" +#include "GpuScheduler.h" +#include "TaskManagerImpl.h" +#include "GpuTaskManagerImpl.h" + +GpuThreads::GpuThreads() +{ + threads = new pthread_t; + args = new gpu_arg; +} + +GpuThreads::~GpuThreads() +{ + delete threads; + delete args; + + clReleaseCommandQueue(command_queue); + clReleaseContext(context); +} + +void +GpuThreads::init() +{ + clGetPlatformIDs(1, &platform_id, &ret_num_platforms); + clGetDeviceIDs(platform_id, CL_DEVICE_TYPE_GPU, 1, &device_id, &ret_num_devices); + // unavailable GPU + if( ret_num_devices == 0) { + exit(EXIT_FAILURE); + } + context = clCreateContext(NULL, 1, &device_id, NULL, NULL, &ret); + command_queue = clCreateCommandQueue(context, device_id, 0, &ret); + + args->scheduler = new GpuScheduler(); + args->useRefDma = use_refdma; + + // pthread_create(threads, NULL, &gpu_thread_run, args); + +} + +void * +GpuThreads::gpu_thread_run(void *args) +{ + gpu_arg *argt = (gpu_arg *) args; + Scheduler *g_scheduler = argt->scheduler; + + TaskManagerImpl *manager = new GpuTaskManagerImpl(); + g_scheduler->init(manager, argt->useRefDma); + + manager->set_scheduler(g_scheduler); + + g_scheduler->run(); + g_scheduler->finish(); + + return NULL; +} + +int +GpuThreads::get_mail(int speid, int count, memaddr *ret) +{ + *ret = args->scheduler->mail_read_from_host(); + return 1; +} + +int +GpuThreads::has_mail(int speid, int count, memaddr *ret) +{ + if (args->scheduler->has_mail_from_host() != 0) { + return get_mail(0, 0, ret); + } else { + return 0; + } +} + +void +GpuThreads::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) +{ +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Gpu/GpuThreads.h Sun Jul 15 17:42:10 2012 +0900 @@ -0,0 +1,53 @@ +#ifndef INCLUDED_GPU_THREADS +#define INCLUDED_GPU_THREADS + +#include <pthread.h> +#include "Threads.h" +#include "GpuScheduler.h" + +#ifdef __APPLE__ +#include <OpenCL/opencl.h> +#else +#include <CL/cl.h> +#endif + +// Singleton Pattern +struct gpu_arg { + GpuScheduler *scheduler; + int useRefDma; +}; + +class GpuThreads : public Threads { +public: + static GpuThreads* getInstance() { + static GpuThreads singleton; + return &singleton; + } + ~GpuThreads(); + + void init(); + static void *gpu_thread_run(void *args); + + 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_context context ; + cl_command_queue command_queue; + cl_int ret; + +private: + GpuThreads(); + + gpu_arg *args; + pthread_t *threads; + int use_refdma; +}; + +#endif
--- a/TaskManager/Makefile Sun Jul 15 17:33:50 2012 +0900 +++ b/TaskManager/Makefile Sun Jul 15 17:42:10 2012 +0900 @@ -21,6 +21,9 @@ parallel: FORCE @$(MAKE) -f Makefile.parallel +gpu: FORCE + @$(MAKE) -f Makefile.gpu + FORCE: -mkdir -p ../include/TaskManager rsync `find . -name Test -prune -or -name '*.h' -print` ../include/TaskManager
--- a/TaskManager/Makefile.def Sun Jul 15 17:33:50 2012 +0900 +++ b/TaskManager/Makefile.def Sun Jul 15 17:42:10 2012 +0900 @@ -27,6 +27,10 @@ IMPL_CELL_SRCS = $(IMPL_FIFO_SRCS) $(wildcard $(IMPL_CELL_DIR)/*.cc) IMPL_CELL_OBJS = $(IMPL_CELL_SRCS:.cc=.o) +IMPL_GPU_DIR = Gpu +IMPL_GPU_SRCS = $(wildcard $(IMPL_GPU_DIR)/*.cc) +IMPL_GPU_OBJS = $(IMPL_GPU_SRCS:.cc=.o) + ABIBIT = 64 OPT = -g -DMAIL_QUEUE -DNOT_CHECK -DTASK_LIST_MAIL #-DEARLY_TOUCH -DUSE_CACHE
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Makefile.gpu Sun Jul 15 17:42:10 2012 +0900 @@ -0,0 +1,37 @@ +include ./Makefile.def +TARGET = libGpuManager.a +CFLAGS += -DHAS_POSIX_MEMALIGN + +ifdef LINUX +CFLAGS += -lrt +endif + +.SUFFIXES: .cc .o + +EXTRA_CFLAGS = -D__CERIUM_GPU__ + +.cc.o: + $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(INCLUDE) -c $< -o $@ + + +all: default +default: $(TARGET) + +ALL_OBJS = $(KERN_MAIN_OBJS) $(KERN_PPE_OBJS) $(KERN_SCHED_OBJS) \ + $(KERN_SYSTASK_OBJS) $(IMPL_FIFO_OBJS) $(KERN_MEM_OBJS) \ + $(IMPL_GPU_OBJS) \ + Cell/spe/SpeTaskManagerImpl.o Cell/CellTaskManagerImpl.o + +Makefile.dep: + make -f Makefile.gpu depend + +depend: + $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(INCLUDE) $(ALL_OBJS:.o=.cc) -MM > Makefile.dep + +$(TARGET): $(ALL_OBJS) + ar crus $@ $(ALL_OBJS) + +gpudistclean: gpuclean + rm -f $(TARGET) + +gpuclean:
--- a/TaskManager/kernel/main.cc Sun Jul 15 17:33:50 2012 +0900 +++ b/TaskManager/kernel/main.cc Sun Jul 15 17:42:10 2012 +0900 @@ -11,6 +11,7 @@ extern int TMmain(TaskManager* manager, int argc, char *argv[]); static int profile = 0; +static int export_task_log = 0; /* Default TMend function */ static void @@ -42,6 +43,8 @@ machineNum = atoi(argv[++i]); } else if (strcmp(argv[i], "-p") == 0) { profile = 1; + } else if (strcmp(argv[i], "-export") == 0) { + export_task_log = 1; } else if (strcmp(argv[i], "-speidle") == 0) { // これなんだよ? speIdle = atoi(argv[++i]); } else if (strcmp(argv[i], "-copy") == 0) { // force copy DMA in FifoManager @@ -77,6 +80,9 @@ (manager->tm_end)(manager); if (profile) manager->show_profile(); + if (export_task_log) + manager->export_task_log(); + manager->run(); // tm_end/show_profile may create a Task.. FINISH:
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/kernel/ppe/ExportTaskLog.cc Sun Jul 15 17:42:10 2012 +0900 @@ -0,0 +1,51 @@ +#include "ExportTaskLog.h" +const char* const ExportTaskLog::FILENAME="logfile.yml"; + +ExportTaskLog::ExportTaskLog(QueueInfo<TaskLog> *_tasklog) +{ + tasklog = _tasklog; + + open(); +} + +ExportTaskLog::~ExportTaskLog() +{ + close(); +} + +void +ExportTaskLog::open() +{ + if ((fp = fopen(FILENAME, "w")) == NULL) { + printf("file open error!\n"); + exit(EXIT_FAILURE); + }; +} + +void +ExportTaskLog::printOut() +{ + while(!tasklog->empty()){ + TaskLog *log = tasklog->poll(); + fprintf(fp, "--- \n"); + fprintf(fp, "task_id: %d\n", log->mtask_id); + fprintf(fp, "cmd: %d\n", log->cmd); + fprintf(fp, "create_time: %llu\n", log->create_time); + fprintf(fp, "execute_time: %llu\n", log->execute_time); + fprintf(fp, "finish_time: %llu\n", log->finish_time); + fprintf(fp, "wait_for:\n"); + while(!log->wait_for_list.empty()){ + waitTask *task = log->wait_for_list.poll(); + fprintf(fp, " - \n"); + fprintf(fp, " task_id: %d\n", task->task_id); + fprintf(fp, " cmd: %d\n", task->cmd); + } + } +} + +void +ExportTaskLog::close() +{ + fclose(fp); +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/kernel/ppe/ExportTaskLog.h Sun Jul 15 17:42:10 2012 +0900 @@ -0,0 +1,28 @@ +#ifndef included_exporttasklog +#define included_exporttasklog + +#include <stdio.h> +#include "TaskLog.h" +#include "QueueInfo.h" + +class ExportTaskLog { +public: + ExportTaskLog(QueueInfo<TaskLog> *_tasklog); + virtual ~ExportTaskLog(); + +public: + void open(); + void printOut(); + void close(); + +private: + QueueInfo<TaskLog> *tasklog; + FILE *fp; + + static const char* const FILENAME; + +}; + + + +#endif
--- a/TaskManager/kernel/ppe/HTask.cc Sun Jul 15 17:33:50 2012 +0900 +++ b/TaskManager/kernel/ppe/HTask.cc Sun Jul 15 17:42:10 2012 +0900 @@ -39,7 +39,7 @@ { waitTask *wait_task = new waitTask; wait_task->task_id = master->tasklog->mtask_id; - wait_task->cmd = master->command; + wait_task->cmd = master->tasklog->cmd; tasklog->wait_for_list.addLast(wait_task); mimpl->set_task_depend(master, this); @@ -80,7 +80,8 @@ @param num_inData 一つのTaskが読み込む Data の数、set_inData の数 @param num_outData 一つのTaskが書き出す Data の数、set_outData の数 @return Task Array へのポインタ - */ + */ + Task * HTask::create_task_array(int id, int num_task, int num_param, int num_inData, int num_outData) { @@ -95,6 +96,7 @@ return task; // first task } + /*! @brief Task Array の次のTask @param t 今のTaskのポインタ @@ -124,7 +126,7 @@ TaskList *tl = (TaskList*)rbuf; if (t==0) { tl->tasks->init(id, param_count, inData_count, outData_count); - return tl->tasks; + return tl->tasks; } Task *next = t->next(); if (next >= tl->last()) { @@ -141,7 +143,6 @@ return next; } - /*! @brief Task Array の中のすべてのTaskが書き込まれたかどうかをチェックする TaskArray 自体の spawn() は別に必要
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/kernel/ppe/TaskLog.cc Sun Jul 15 17:42:10 2012 +0900 @@ -0,0 +1,4 @@ +#include "TaskLog.h" + +// initialize +int TaskLog::task_id = 0;
--- a/TaskManager/kernel/ppe/TaskLog.h Sun Jul 15 17:33:50 2012 +0900 +++ b/TaskManager/kernel/ppe/TaskLog.h Sun Jul 15 17:42:10 2012 +0900 @@ -1,7 +1,6 @@ #ifndef INCLUDED_TASKLOG #define INCLUDED_TASKLOG -#include "HTask.h" #include "QueueInfo.h" struct waitTask { @@ -34,8 +33,16 @@ TaskLog() { mtask_id = task_id; task_id++; + create_time = 0; + execute_time = 0; + finish_time = 0; } + void set_cmd(int _cmd) { + cmd = _cmd; + } + + private: // Unique id
--- a/TaskManager/kernel/ppe/TaskManager.h Sun Jul 15 17:33:50 2012 +0900 +++ b/TaskManager/kernel/ppe/TaskManager.h Sun Jul 15 17:42:10 2012 +0900 @@ -33,6 +33,7 @@ void start_profile() { m_impl->start_profile(); } void show_profile() { m_impl->show_profile(); } + void export_task_log() { m_impl->export_task_log(); } SchedTask *get_schedTask() { return m_impl->schedTaskManager;
--- a/TaskManager/kernel/ppe/TaskManagerImpl.cc Sun Jul 15 17:33:50 2012 +0900 +++ b/TaskManager/kernel/ppe/TaskManagerImpl.cc Sun Jul 15 17:42:10 2012 +0900 @@ -13,6 +13,7 @@ QueueInfo<TaskQueue> *taskQueuePool = new QueueInfo<TaskQueue>() ; QueueInfo<HTask> *htaskPool = new QueueInfo<HTask>() ; QueueInfo<TaskList> *taskListPool = new QueueInfo<TaskList>() ; +QueueInfo<TaskLog> *taskLogQueue = new QueueInfo<TaskLog>(); static HTaskPtr systask_start; static HTaskPtr systask_finish; @@ -67,7 +68,8 @@ new_task->from = (memaddr)from; TaskLog *tasklog = new TaskLog(); - taskLogQueue.addLast(tasklog); + tasklog->set_cmd(cmd); + taskLogQueue->addLast(tasklog); new_task->tasklog = tasklog; #ifdef EARLY_TOUCH @@ -107,6 +109,11 @@ new_task->command = TaskArray1; new_task->from = (memaddr)from; + TaskLog *tasklog = new TaskLog(); + tasklog->set_cmd(cmd); + taskLogQueue->addLast(tasklog); + new_task->tasklog = tasklog; + return new_task; } @@ -121,6 +128,12 @@ return ta; } +TaskListPtr +TaskManagerImpl::createTaskList() +{ + return NULL; +} + /* call get_task_name from ppu only */ const char * TaskManagerImpl::get_task_name(int cmd) {
--- a/TaskManager/kernel/ppe/TaskManagerImpl.h Sun Jul 15 17:33:50 2012 +0900 +++ b/TaskManager/kernel/ppe/TaskManagerImpl.h Sun Jul 15 17:42:10 2012 +0900 @@ -12,7 +12,8 @@ extern QueueInfo<TaskQueue> *taskQueuePool ; extern QueueInfo<HTask> *htaskPool ; -extern QueueInfo<TaskList> *taskListPool; +extern QueueInfo<TaskList> *taskListPool; +extern QueueInfo<TaskLog> *taskLogQueue; @@ -27,8 +28,6 @@ QueueInfo<TaskQueue> *taskQueueImpl; QueueInfo<HTask> *htaskImpl; - QueueInfo<TaskLog> taskLogQueue; - SchedTask *schedTaskManager; Scheduler *scheduler; TaskManagerImpl *others; @@ -44,6 +43,7 @@ virtual void run() = 0; virtual void start_profile() = 0; virtual void show_profile() = 0; + virtual void export_task_log(){} virtual void append_activeTask(HTaskPtr); virtual void append_waitTask(HTaskPtr); virtual void polling() = 0; @@ -59,12 +59,12 @@ virtual HTaskPtr create_task(int cmd, memaddr rbuf, long r_size, memaddr wbuf, long w_size,void *from); virtual HTaskPtr create_task_array(int id, int num_task, int num_param, int num_inData, int num_outData,void *from); virtual TaskListPtr createTaskList() = 0; - const char *get_task_name(int cmd); - const char *get_task_name(TaskPtr task); - const char *get_task_name(SimpleTaskPtr simpletask); - const char *get_task_name(SchedTaskBase *schedtask); - const char *get_task_name(HTaskPtr htask); - const char *get_task_name(HTaskPtr htask, int index); + const char *get_task_name(int cmd); + const char *get_task_name(TaskPtr task); + const char *get_task_name(SimpleTaskPtr simpletask); + const char *get_task_name(SchedTaskBase *schedtask); + const char *get_task_name(HTaskPtr htask); + const char *get_task_name(HTaskPtr htask, int index); 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/Scheduler.cc Sun Jul 15 17:33:50 2012 +0900 +++ b/TaskManager/kernel/schedule/Scheduler.cc Sun Jul 15 17:42:10 2012 +0900 @@ -94,18 +94,18 @@ SchedTaskBase* task3 = new SchedNop(); // main loop do { - - task1->read(); - task2->exec(); - task3->write(); - - delete task3; - + + task1->read(); + task2->exec(); + task3->write(); + + delete task3; + task3 = task2; task2 = task1; - //SchedMailの場合、Mailの待ちが入る - task1 = task1->next(this, 0); - + //SchedMailの場合、Mailの待ちが入る + task1 = task1->next(this, 0); + } while (task1); delete task3;
--- a/TaskManager/kernel/schedule/Scheduler.h Sun Jul 15 17:33:50 2012 +0900 +++ b/TaskManager/kernel/schedule/Scheduler.h Sun Jul 15 17:42:10 2012 +0900 @@ -9,8 +9,13 @@ #include "DmaManager.h" #include "SchedTaskBase.h" #include "MemList.h" -#include "MemHash.h" +#include "MemHash.h" +#ifdef __APPLE__ +#include <OpenCL/opencl.h> +#else +#include <CL/cl.h> +#endif #define MAX_USER_TASK 100 #define MAX_SYSTEM_TASK 2 @@ -37,9 +42,10 @@ memaddr end; uint32 entry_offset; // offset for create(); MemorySegment *segment; - const char *name; + const char *name; void (*load)(Scheduler *,int); void (*wait)(Scheduler *,int); + cl_kernel *kernel; } __attribute__ ((aligned (DEFAULT_ALIGNMENT))) //sizeはどれくらい? TaskObject, *TaskObjectPtr; @@ -80,6 +86,7 @@ /* functions */ void init(TaskManagerImpl *m, int useRefDma=0); + virtual void run(){}; void run(SchedTaskBase* task1); virtual void init_impl(int useRefDma) {};
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/test/GpuRegistTaskTest/GpuRegistTaskTest.cc Sun Jul 15 17:42:10 2012 +0900 @@ -0,0 +1,105 @@ +#include <stdio.h> +#include <OpenCL/opencl.h> +#include <fcntl.h> +#include <sys/stat.h> +#include "GpuScheduler.h" +#include "CellTaskManagerImpl.h" +#include "GpuThreads.h" +#define DEFAULT 5 + +extern void gpu_register_task(int, const char*, const char*); +void +print_data(int *data, int size, const char *title) +{ + printf("%s ---\n", title); + for ( int i = 0; i < size; i++) { + printf("%2d ", data[i]); + } + printf("\n"); +} + +void +tester(int *indata,int *outdata, int num){ + + //チェック + int check = 0; + for (int c=0; c<num; c++) { + if(outdata[c] == indata[c]*2) { + check++; + } + } + + printf("Computed '%d/%d' correct values\n",check,num); + +} + +void +test(int task_array_num){ + + GpuThreads* gputhreads = GpuThreads::getInstance(); + gputhreads->init(); + + int cmd = 1; + GpuSchedRegister(cmd, "twice.cl", "twice"); + + + int *indata = new int[task_array_num]; + int *outdata = new int[task_array_num]; + int count; + for (count=0; count < task_array_num ;count++) { + indata[count] = count; + } + print_data(indata, count, "before"); + + + cl_int ret = gputhreads->ret; + cl_context context = gputhreads->context; + cl_mem memobj_in = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(int)*count, NULL, &ret); + cl_mem memobj_out = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(int)*count, NULL, &ret); + cl_mem data_count = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(int)*count, NULL, &ret); + + cl_command_queue command_queue = gputhreads->command_queue; + ret = clEnqueueWriteBuffer(command_queue, memobj_in, CL_TRUE, 0, + sizeof(int)*count, indata, 0, NULL, NULL); + ret = clEnqueueWriteBuffer(command_queue, data_count, CL_TRUE, 0, + sizeof(count), &count, 0, NULL, NULL); + + cl_kernel kernel = *(task_list[cmd].kernel); + + clSetKernelArg(kernel, 0, sizeof(cl_mem), (void *)&memobj_in); + + + clSetKernelArg(kernel, 1, sizeof(cl_mem), (void *)&memobj_out); + clSetKernelArg(kernel, 2, sizeof(cl_mem), (void *)&data_count); + + cl_event ev = NULL; + clEnqueueTask(command_queue, kernel, 0, NULL, &ev); + + clEnqueueReadBuffer(command_queue, memobj_out, CL_TRUE, 0, + sizeof(int)*count, outdata, 1, &ev, NULL); + + print_data(outdata, count, "after"); + tester(indata,outdata,count); + + delete [] indata; + delete [] outdata; + clReleaseCommandQueue(command_queue); + clReleaseContext(context); + clReleaseKernel(kernel); + + +} + +int +main(int argc, char* argv[]) +{ + int task_array_num = DEFAULT; + + if (argc > 1) { //引数が渡されていて、 + if(atoi(argv[1])) {//数字なら + task_array_num = atoi(argv[1]); + } + } + test(task_array_num); + return 0; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/test/GpuRegistTaskTest/GpuRegistTaskTest.cc.orig Sun Jul 15 17:42:10 2012 +0900 @@ -0,0 +1,101 @@ +#include <stdio.h> +#include <OpenCL/opencl.h> +#include "GpuThreads.h" +#include "GpuScheduler.h" +#include "CellTaskManagerImpl.h" + +#define DEFAULT 5 +extern void gpu_register_task(int, char*, char*); + +void +print_data(int *data, int size, const char *title){ + printf("%s ---\n", title); + + for ( int i = 0; i < size; i++) { + printf("%2d ", data[i]); + } + + printf("\n"); +} + +void +tester(int *indata,int *outdata, int num){ + //チェック + int check; + for (int c=0; c<num; c++){ + if(outdata[c] == indata[c]*2){ + check++; + } + printf("Computed '%d/%d' correct values\n",check,num); + } +} + +void +test(int task_array_num){ + + GpuThreads* gpuThreads = GpuThreads::getInstance(); + gpuThreads->init(); + + int *indata,*outdata; + int count; + indata = (int *)malloc(sizeof(int)*task_array_num); + outdata = (int *)malloc(sizeof(int)*task_array_num); + for (count=0; count < task_array_num ;count++) { + indata[count] = count; + } + printf("%d",count); + + GpuSchedRegister(1,"./twice.cl","Twice"); + + + cl_int ret; + cl_context context = gpuThreads->context; + cl_mem memobj_in, memobj_out, data_count = NULL; + memobj_in = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(int)*count, NULL, &ret); + memobj_out = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(int)*count, NULL, &ret); + data_count = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(int)*count, NULL, &ret); + + cl_command_queue command_queue = gpuThreads->command_queue; + ret = clEnqueueWriteBuffer(command_queue, memobj_in, CL_TRUE, 0, + sizeof(int)*count, indata, 0, NULL, NULL); + ret = clEnqueueWriteBuffer(command_queue, data_count, CL_TRUE, 0, + sizeof(count), &count, 0, NULL, NULL); + + print_data(indata, count, "before"); + + + cl_kernel *kernel = task_list[1].kernel; + clSetKernelArg(*kernel, 0, sizeof(cl_mem), (void *)&memobj_in); + clSetKernelArg(*kernel, 1, sizeof(cl_mem), (void *)&memobj_out); + clSetKernelArg(*kernel, 2, sizeof(cl_mem), (void *)&data_count); + + cl_event ev; + clEnqueueTask(command_queue, *kernel, 0, NULL, &ev); + + clEnqueueReadBuffer(command_queue, memobj_out, CL_TRUE, 0, + sizeof(int)*count, outdata, 1, &ev, NULL); + + + print_data(outdata, count, "after"); + + free(indata); + free(outdata); + clReleaseCommandQueue(command_queue); + clReleaseContext(context); + + tester(indata,outdata,count); + + delete gpuThreads; +} + +int +main(int argc, char* argv[]) +{ + int task_array_num; + if ( ((task_array_num = atoi(argv[1])) == 0) || argc != 1 ){ + // 無効な引数ならデフォルトの値として5を設定 + task_array_num = DEFAULT; + } + test(task_array_num); + printf("regist task succeed\n"); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/test/GpuRegistTaskTest/Makefile Sun Jul 15 17:42:10 2012 +0900 @@ -0,0 +1,15 @@ +include ../../Makefile.def + +CPPFLAGS += -g -Wall -I../../../include/TaskManager -m$(ABIBIT) + +TARGET=GpuRegistTaskTest + + + +LIBS += ../../libGpuManager.a -framework opencl + +GpuRegistTaskTest : GpuRegistTaskTest.o + $(CC) $(CFLAGS) -o $@ $? $(LIBS) + +clean: + rm -rf *.o $(TARGET)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/test/GpuRegistTaskTest/Makefile.orig Sun Jul 15 17:42:10 2012 +0900 @@ -0,0 +1,15 @@ +include ../../Makefile.def + +CPPFLAGS += -g -Wall -I../../../include/TaskManager -m$(ABIBIT) + +TARGET= GpuRegistTaskTest -framework opencl + +$(TARGET) : + +LIBS += ../../libGpuManager.a + +CpuRegistTaskTest : GpuRegistTaskTest.o + $(CC) $(CFLAGS) -o $@ $? $(LIBS) + +clean: + rm -rf *.o $(TARGET)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/test/GpuRegistTaskTest/twice.cl Sun Jul 15 17:42:10 2012 +0900 @@ -0,0 +1,11 @@ +__kernel void +twice(__global int *input_data, + __global int *output_data, + __global int *data_count) +{ + int count = *data_count; + for (int i = 0; i<count; i++) { + output_data[i] = input_data[i] * 2; + } + +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/test/GpuRunTest/GpuRunTest.cc Sun Jul 15 17:42:10 2012 +0900 @@ -0,0 +1,121 @@ +#include <stdio.h> +#include <fcntl.h> +#include <sys/stat.h> +#include "TaskManager.h" +#include "GpuScheduler.h" +#include "GpuThreads.h" +#include "GpuFunc.h" +#define DEFAULT 5 + + +extern void gpu_register_task(int, const char*, const char*); +extern void task_init(void); + +void +print_data(int *data, int size, const char *title) +{ + printf("%s ---\n", title); + for ( int i = 0; i < size; i++) { + printf("%2d ", data[i]); + } + printf("\n"); +} + + + +void +tester(int *indata, int *outdata, int num){ + + //チェック + int check = 0; + for (int c=0; c<num; c++) { + if(outdata[c] == indata[c]*2) { + check++; + } + } + + printf("Computed '%d/%d' correct values\n",check,num); + +} + +void +test(TaskManager *manager, long int length){ + + int cmd = 1; + GpuThreads* gputhreads = GpuThreads::getInstance(); + gputhreads->init(); + + GpuSchedRegister(cmd, "twice.cl", "twice"); + + int *indata = (int *)manager->allocate(sizeof(int)*length);//new int[length]; + int *outdata = new int[length]; + int count; + for (count=0; count < length ;count++) { + indata[count] = count; + } + print_data(indata, count, "before"); + + HTaskPtr schedtask = manager->create_task(SchedRun); + schedtask->set_inData(0, indata, sizeof (int)*length); + schedtask->set_outData(1, outdata, sizeof (int)*length); + schedtask->set_inData(2, &count, sizeof (int)); + schedtask->set_cpu(SPE_ANY); + schedtask->spawn(); + + + //以下をGpuScheduler のrunへ + /* + cl_int ret = gputhreads->ret; + cl_context context = gputhreads->context; + cl_mem memobj_in = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(int)*count, NULL, &ret); + cl_mem memobj_out = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(int)*count, NULL, &ret); + cl_mem data_count = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(int)*count, NULL, &ret); + + cl_command_queue command_queue = gputhreads->command_queue; + ret = clEnqueueWriteBuffer(command_queue, memobj_in, CL_TRUE, 0, + sizeof(int)*count, indata, 0, NULL, NULL); + ret = clEnqueueWriteBuffer(command_queue, data_count, CL_TRUE, 0, + sizeof(count), &count, 0, NULL, NULL); + + cl_kernel kernel = *(task_list[cmd].kernel); + + clSetKernelArg(kernel, 0, sizeof(cl_mem), (void *)&memobj_in); + + + clSetKernelArg(kernel, 1, sizeof(cl_mem), (void *)&memobj_out); + clSetKernelArg(kernel, 2, sizeof(cl_mem), (void *)&data_count); + + cl_event ev = NULL; + clEnqueueTask(command_queue, kernel, 0, NULL, &ev); + + clEnqueueReadBuffer(command_queue, memobj_out, CL_TRUE, 0, + sizeof(int)*count, outdata, 1, &ev, NULL); + + print_data(outdata, count, "after"); + tester(indata,outdata,count); + + delete [] indata; + delete [] outdata; + clReleaseCommandQueue(command_queue); + clReleaseContext(context); + clReleaseKernel(kernel); + */ + + } + +int +TMmain(TaskManager *manager, int argc, char* argv[]) +{ + long int length = DEFAULT; + + if (argc > 1) { //引数が渡されていて、 + if(atoi(argv[1])) {//数字なら + length = atoi(argv[1]); + } + } + task_init(); + + test(manager, length); + + return 0; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/test/GpuRunTest/Makefile Sun Jul 15 17:42:10 2012 +0900 @@ -0,0 +1,28 @@ +include ./Makefile.def + +SRCS_TMP = $(wildcard *.cc) +SRCS_EXCLUDE = # 除外するファイルを書く +SRCS = $(filter-out $(SRCS_EXCLUDE),$(SRCS_TMP)) +OBJS = $(SRCS:.cc=.o) + +LIBS += -lGpuManager -framework opencl `sdl-config --libs`#cflags` + +.SUFFIXES: .cc .o + +.cc.o: + $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ + +all: $(TARGET) + +$(TARGET): $(OBJS) + $(CC) -o $@ $(OBJS) $(TASK_OBJS) $(LIBS) + +link: + $(CC) -o $(TARGET) $(OBJS) $(LIBS) + +debug: $(TARGET) + sudo gdb ./$(TARGET) + +clean: + rm -f $(TARGET) $(OBJS) + rm -f *~ \#*
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/test/GpuRunTest/Makefile.bk Sun Jul 15 17:42:10 2012 +0900 @@ -0,0 +1,15 @@ +include ../../Makefile.def + +CPPFLAGS += -g -Wall -I../../../include/TaskManager -m$(ABIBIT) + +TARGET=GpuRunTest + + + +LIBS += ../../libGpuManager.a -framework opencl + +GpuRunTest : GpuRunTest.o + $(CC) $(CFLAGS) -o $@ $? $(LIBS) + +clean: + rm -rf *.o $(TARGET)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/test/GpuRunTest/Makefile.def Sun Jul 15 17:42:10 2012 +0900 @@ -0,0 +1,9 @@ +TARGET = GpuRunTest + +CERIUM = ../../../../Cerium + +CC = g++ +CFLAGS = -g -Wall + +INCLUDE = -I${CERIUM}/include/TaskManager -I. -I../.. +LIBS = -L${CERIUM}/TaskManager
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/test/GpuRunTest/twice.cl Sun Jul 15 17:42:10 2012 +0900 @@ -0,0 +1,11 @@ +__kernel void +twice(__global int *input_data, + __global int *output_data, + __global int *data_count) +{ + int count = *data_count; + for (int i = 0; i<count; i++) { + output_data[i] = input_data[i] * 2; + } + +} \ No newline at end of file
--- a/example/HelloWorld/main.cc Sun Jul 15 17:33:50 2012 +0900 +++ b/example/HelloWorld/main.cc Sun Jul 15 17:42:10 2012 +0900 @@ -37,18 +37,18 @@ static void simple_task_creater(int in_total_size, int out_total_size, - int command, int in_data_size, int out_data_size, - void *in_data, void *out_data, TaskManager *manager, - HTask *wait_i, HTask *wait_me) { - - - int in_task_size = 0; - int out_task_size = 0; - + int command, int in_data_size, int out_data_size, + void *in_data, void *out_data, TaskManager *manager, + HTask *wait_i, HTask *wait_me) { + + + int in_task_size = 0; + int out_task_size = 0; + if (in_total_size != 0) { - in_task_size = in_total_size / in_data_size; - if (in_total_size != in_task_size * in_data_size) { - printf("mismatch of in_total_size and in_data_size\n"); + in_task_size = in_total_size / in_data_size; + if (in_total_size != in_task_size * in_data_size) { + printf("mismatch of in_total_size and in_data_size\n"); } } @@ -140,17 +140,17 @@ { for (int i = 0; i < count; i++) { - /** - * Create Task - * create_task(Task ID); - */ - - - if (use_task_creater) { - - simple_task_creater(0,0,Hello,0,0,0,0,manager,0,0); - - } else { + /** + * Create Task + * create_task(Task ID); + */ + + + if (use_task_creater) { + + simple_task_creater(0,0,Hello,0,0,0,0,manager,0,0); + + } else { HTask *hello = manager->create_task(Hello);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/OpenCL/Makefile Sun Jul 15 17:42:10 2012 +0900 @@ -0,0 +1,11 @@ +CFLAGS = -g -Wall -framework opencl +CC = g++ +OPT = -g + +TARGET=twice + +twice : twice.o + $(CC) $(OPT) $(CFLAGS) -o $@ $? + +clean: + rm -rf *.o $(TARGET)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/OpenCL/twice.cc Sun Jul 15 17:42:10 2012 +0900 @@ -0,0 +1,125 @@ +#include <stdlib.h> +#include <OpenCL/opencl.h> +#include <stdio.h> +#include <fcntl.h> +#include <sys/stat.h> + +#define DEFAULT 432 + +void +print_data(int *data, int size, const char *title) +{ + printf("%s ---\n", title); + for ( int i = 0; i < size; i++) { + printf("%2d ", data[i]); + } + printf("\n"); +} + +int main(int argc, char *argv[]) { + + // 無効な引数ならデフォルトの値として432を設定 + int task_array_num = DEFAULT; + + if (argc>1) { + if (atoi(argv[1])) { + task_array_num = atoi(argv[1]); + } + } + + cl_platform_id platform_id = NULL; + cl_uint ret_num_platforms = NULL; + cl_device_id device_id = NULL; + cl_uint ret_num_devices = NULL; + cl_int ret; + + clGetPlatformIDs(1, &platform_id, &ret_num_platforms); + clGetDeviceIDs(platform_id, CL_DEVICE_TYPE_DEFAULT, 1, &device_id, + &ret_num_devices); + + cl_context context = clCreateContext( NULL, 1, &device_id, NULL, NULL, &ret); + cl_command_queue command_queue = clCreateCommandQueue(context, device_id, 0, &ret); + + //ファイルオープン + int fp; + char *kernel_src_str; + size_t kernel_code_size; + const char* filename = "twice.cl"; + const char* functionname = "twice"; + + fp = open(filename, O_RDONLY); + + if (!fp) { + fprintf(stderr, "Failed to load kernel.\n"); + exit(1); + } + + struct stat stats; + fstat(fp,&stats); + off_t size = stats.st_size; + + if (!size) { + fprintf(stderr, "Failed to load kernel.\n"); + } + + kernel_src_str = (char*)malloc(size); + + kernel_code_size = read(fp, kernel_src_str, size); + close(fp); + + + + cl_program program = NULL; + cl_kernel kernel = NULL; + program = clCreateProgramWithSource(context, 1, (const char **)&kernel_src_str, + (const size_t *)&kernel_code_size, &ret); + clBuildProgram(program, 1, &device_id, NULL, NULL, NULL); + kernel = clCreateKernel(program,functionname, &ret); + + int *data,*output_data; + data = (int *)malloc(sizeof(int)*task_array_num); + output_data = (int *)malloc(sizeof(int)*task_array_num); + + int count = 0; + for (int c = 0; c < task_array_num ; count++,c++){ + data[c] = c; + } + + cl_mem memobj_in, memobj_out, data_count = NULL; + //メモリバッファの作成 + memobj_in = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(int)*count, NULL, &ret); + memobj_out = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(int)*count, NULL, &ret); + data_count = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(int)*count, NULL, &ret); + + //メモリバッファに入力データを書き込み + ret = clEnqueueWriteBuffer(command_queue, memobj_in, CL_TRUE, 0, + sizeof(int)*count, data, 0, NULL, NULL); + ret = clEnqueueWriteBuffer(command_queue, data_count, CL_TRUE, 0, + sizeof(count), &count, 0, NULL, NULL); + + print_data(data, count, "before"); + + clSetKernelArg(kernel, 0, sizeof(cl_mem), (void *)&memobj_in); + clSetKernelArg(kernel, 1, sizeof(cl_mem), (void *)&memobj_out); + clSetKernelArg(kernel, 2, sizeof(cl_mem), (void *)&data_count); + + cl_event ev = NULL; + ret = clEnqueueTask(command_queue, kernel, 0, NULL, &ev); + + //メモリバッファから結果を取得 + ret = clEnqueueReadBuffer(command_queue, memobj_out, CL_TRUE, 0, + sizeof(int)*count, output_data, 1, &ev, NULL); + + print_data(output_data, count, "after"); + + free(data); + free(output_data); + clReleaseKernel(kernel); + clReleaseProgram(program); + clReleaseCommandQueue(command_queue); + clReleaseContext(context); + + free(kernel_src_str); + + return 0; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/OpenCL/twice.cl Sun Jul 15 17:42:10 2012 +0900 @@ -0,0 +1,11 @@ +__kernel void +twice(__global int *input_data, + __global int *output_data, + __global int *data_count) +{ + int count = *data_count; + for (int i = 0; i<count; i++) { + output_data[i] = input_data[i] * 2; + } + +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/log.rb Sun Jul 15 17:42:10 2012 +0900 @@ -0,0 +1,27 @@ +require 'yaml' +log_file = ARGV[0] + +puts 'digraph log {' +puts 'node [shape = record];' +YAML.load_documents(open(log_file)) do |doc| + print doc['task_id'].to_s + print '[' + print 'label = "{' + print doc['task_id'].to_s + '|' + print 'cmd:\ ' + doc['cmd'].to_s + '\l' + '\n' + print 'create:\ ' + doc['create_time'].to_s + '\l' + '\n' + print 'execute:\ ' + doc['execute_time'].to_s + '\l' + '\n' + print 'finish:\ ' + doc['finish_time'].to_s + '\l' + '\n' + print '}"];' + "\n" +end + +YAML.load_documents(open(log_file)) do |doc| + if doc['wait_for'] != nil then + doc['wait_for'].each do |task| + puts task['task_id'].to_s + ' -> ' + doc['task_id'].to_s + end + end + +end + +puts '}'