Mercurial > hg > Game > Cerium
changeset 1435:9f6ba00ca15c draft
add gpu_sched_register
author | Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 06 Apr 2012 07:57:27 +0900 |
parents | 05d480ab70ba |
children | 42057124fb44 |
files | TaskManager/Gpu/GpuScheduler.cc TaskManager/Gpu/GpuScheduler.h TaskManager/Gpu/GpuTaskManagerImpl.cc TaskManager/Gpu/GpuTaskManagerImpl.h TaskManager/Gpu/GpuThreads.cc TaskManager/Gpu/GpuThreads.h TaskManager/kernel/schedule/Scheduler.h |
diffstat | 7 files changed, 64 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/TaskManager/Gpu/GpuScheduler.cc Thu Apr 05 19:05:35 2012 +0900 +++ b/TaskManager/Gpu/GpuScheduler.cc Fri Apr 06 07:57:27 2012 +0900 @@ -1,5 +1,6 @@ #include "GpuScheduler.h" #include "GpuDmaManager.h" +#include "stdio.h" void GpuScheduler::init_impl(int useRefDma) @@ -13,3 +14,40 @@ // command_queueにここで、enqueueする? } + +void +gpu_register_task(int cmd, char* filename, char* functionname) +{ + 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); + + // contextとか、device_idはどうやって取る? + // gpuの情報はグローバルで持つべきなのか… + 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; + +}
--- a/TaskManager/Gpu/GpuScheduler.h Thu Apr 05 19:05:35 2012 +0900 +++ b/TaskManager/Gpu/GpuScheduler.h Fri Apr 06 07:57:27 2012 +0900 @@ -23,3 +23,6 @@ }; #endif + +#define GpuSchedRegister(str, filename, functionname) \ + gpu_register_task(str, filename, functionname);
--- a/TaskManager/Gpu/GpuTaskManagerImpl.cc Thu Apr 05 19:05:35 2012 +0900 +++ b/TaskManager/Gpu/GpuTaskManagerImpl.cc Fri Apr 06 07:57:27 2012 +0900 @@ -17,20 +17,22 @@ set_scheduler(mscheduler); ppeManager->init(mscheduler, this, useRefDma); - ret = clGetPlatformIDs(1, &platfrom_id, &ret_num_platforms); - ret = clGetDeviceIds(platform_id, CL_DEVICE_TYPE_GPU, 1, &device_id, &ret_num_devices); + htaskImpl = activeTaskQueue; + mscheduler->set_manager(this); + clGetPlatformIDs(1, &platfrom_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); } - - gpuThreads->init(device_id); + context = clCreateContext(NULL, 1, &device_id, NULL, NULL, &ret); + command_queue = clCreateCommandQueue(context, device_id, 0, &ret); - htaskImpl = activeTaskQueue; - mscheduler->set_manager(this); + gpuThreads->init(&command_queue); schedTaskManager = new SchedTask(); schedTaskManager->init(0, 0, 0, ppeManager->get_scheduler(), 0); ppeManager->schedTaskManager = schedTaskManager; } +
--- a/TaskManager/Gpu/GpuTaskManagerImpl.h Thu Apr 05 19:05:35 2012 +0900 +++ b/TaskManager/Gpu/GpuTaskManagerImpl.h Fri Apr 06 07:57:27 2012 +0900 @@ -34,8 +34,11 @@ cl_device_id device_id; cl_uint ret_num_platforms; cl_uint ret_num_devices; - cl_int ret; + cl_context context; + cl_command_queue command_queue; + }; #endif +
--- a/TaskManager/Gpu/GpuThreads.cc Thu Apr 05 19:05:35 2012 +0900 +++ b/TaskManager/Gpu/GpuThreads.cc Fri Apr 06 07:57:27 2012 +0900 @@ -7,8 +7,6 @@ threads = new pthread_t; args = new gpu_arg; - context = NULL; - command_queue = NULL; } GpuThreads::~GpuThreads() @@ -18,14 +16,11 @@ } void -GpuThreads::init(cl_device_id device_id) +GpuThreads::init(cl_command_queue* _command_queue) { - 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; - args.command_queue = &command_queue; + args.command_queue = _command_queue; pthread_create(&threads, NULL, &cpu_thread_run, (void*)&args);
--- a/TaskManager/Gpu/GpuThreads.h Thu Apr 05 19:05:35 2012 +0900 +++ b/TaskManager/Gpu/GpuThreads.h Fri Apr 06 07:57:27 2012 +0900 @@ -24,10 +24,8 @@ void init(cl_device_id device_id;); void *gpu_thread_run(void *args); - cl_context context; - cl_command_queue command_queue; +private: -private: gpu_arg *args; pthread_t *threads; int use_refdma;
--- a/TaskManager/kernel/schedule/Scheduler.h Thu Apr 05 19:05:35 2012 +0900 +++ b/TaskManager/kernel/schedule/Scheduler.h Fri Apr 06 07:57:27 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;