Mercurial > hg > Game > Cerium
view TaskManager/test/GpuThreadTest/GpuScheduler.cc @ 1444:9de96bded518 draft
change GpuThreadsTest
author | Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 23 Apr 2012 21:58:29 +0900 |
parents | 50d2c1e85535 |
children |
line wrap: on
line source
#include "GpuScheduler.h" #include "GpuDmaManager.h" #include "GpuThreads.h" #include "stdio.h" #include <fcntl.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; int *fp; char *souce_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(fileno(fp),&stats); off_t size = stas.st_size; if (!size) { fprintf(stderr, "Failed to load kernel.\n"); } source_str = (char*)malloc(size); source_size = read(source_str, size, fp); close(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; }