Mercurial > hg > Game > Cerium
diff TaskManager/test/GpuThreadTest/GpuScheduler.cc @ 1440:d66dcb067c89 draft
create test program
author | YuuhiTOMARI |
---|---|
date | Mon, 23 Apr 2012 05:48:02 +0900 |
parents | |
children | 50d2c1e85535 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/test/GpuThreadTest/GpuScheduler.cc Mon Apr 23 05:48:02 2012 +0900 @@ -0,0 +1,77 @@ +#include "GpuScheduler.h" +#include "GpuDmaManager.h" +#include "GpuThreads.h" +#include "stdio.h" + +void +GpuScheduler::init_impl(int useRefDma) +{ + connector = new GpuDmamanager; +} + +int +GpuScheduler::run() +{ + 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); + GpuThreads gputhreads = GpuThreads::getInstance(); + cl_command_queue& command_queue = gputhreads.cl_command_queue; + + for (int cur_index = 0; cur_index < tasklist->length; cur_index++) { + TaskPtr task = tasklist.tasks[cur_index]; + cl_kernel& kernel = task_list[task->command].kernel; + // メモリオブジェクトの生成? GpuThreadsでやるのがよい? + // カーネル引数の設定 + clEnqueueTask(command_queue, kernel, 0, NULL, NULL); + // メモリオブジェクトからの読み込み + } + // TaskArrayの処理 +} + + + +void +gpu_register_task(int cmd, char* filename, char* functionname) +{ + GpuThreads gputhreads = GpuThreads::getInstance(); + cl_context& context = &gputhreads.context; + cl_device_id& device_id = &gputhreads.device_id; + + FILE *fp; + char *souce_str; + size_t source_size; + + fp = fopen(filename, "r"); + if (!fp) { + fprintf(stderr, "Failed to load kernel.\n"); + exit(1); + } + + source_str = (char*)malloc(MAX_SOURCE_SIZE); + source_size = fread(source_str, 1, MAX_SOURCE_SIZE, fp); + fclose(fp); + + cl_program program = NULL; + cl_int 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 = run; + task_list[cmd].load = null_loader; + task_list[cmd].wait = null_waiter; + task_list[cmd].name = str; + task_list[cmd].kernel = kernel; + +}