Mercurial > hg > Game > Cerium
changeset 1434:05d480ab70ba draft
add GpuScheduler
author | Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 05 Apr 2012 19:05:35 +0900 |
parents | 11dcd8165424 |
children | 9f6ba00ca15c |
files | TaskManager/Gpu/GpuScheduler.cc TaskManager/Gpu/GpuScheduler.h TaskManager/Gpu/GpuThreads.cc TaskManager/Gpu/GpuThreads.h |
diffstat | 4 files changed, 78 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Gpu/GpuScheduler.cc Thu Apr 05 19:05:35 2012 +0900 @@ -0,0 +1,15 @@ +#include "GpuScheduler.h" +#include "GpuDmaManager.h" + +void +GpuScheduler::init_impl(int useRefDma) +{ + connector = new GpuDmamanager; +} + +void +GpuScheduler::run() +{ + // command_queueにここで、enqueueする? + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Gpu/GpuScheduler.h Thu Apr 05 19:05:35 2012 +0900 @@ -0,0 +1,25 @@ +#ifndef INCLUDED_GPU_SCHEDULER +#define INCLUDED_GPU_SCHEDULER + +#include "Scheduler.h" + +#ifdef __APPLE__ +#include <OpenCL/opencl.h> +#else +#include <CL/cl.h> +#endif + +class GpuScheduler : public Scheduler { +public: + void init_impl(int useRefDma); + void set_command_queue(cl_command_queue* _command_queue) { + command_queue = _command_queue; + } + + +private: + cl_command_queue *command_queue; + +}; + +#endif
--- a/TaskManager/Gpu/GpuThreads.cc Thu Apr 05 12:15:08 2012 +0900 +++ b/TaskManager/Gpu/GpuThreads.cc Thu Apr 05 19:05:35 2012 +0900 @@ -1,13 +1,20 @@ #include "GpuThreads.h" +#include "GpuScheduler.h" +#include "TaskManagerImpl.h" -GpuThreads::GpuThreads(int num, int useRefDma, int start_id) +GpuThreads::GpuThreads(int num, int useRefDma, int start_id) : use_refdma(useRefDma) { + threads = new pthread_t; + args = new gpu_arg; + context = NULL; command_queue = NULL; } GpuThreads::~GpuThreads() { + delete threads; + delete args; } void @@ -16,18 +23,29 @@ context = clCreateContext(NULL, 1, &device_id, NULL, NULL, &ret); command_queue = clCreateCommandQueue(context, device_id, 0, &ret); - // schedulerの作成 - // schedulerは、GpuDmaManagerを持っている。 - // get_write_bufから、allocate経由で - // メモリオブジェクトを作成する。 + args.scheduler = new GpuScheduler(); + args.useRefDma = use_refdma; + args.command_queue = &command_queue; - // Thread立てる + pthread_create(&threads, NULL, &cpu_thread_run, (void*)&args); } void * GpuThreads::gpu_thread_run(void *args) { - // scheduler->run - // schedulerはメールを受け取り、enqueueする。 + gpu_arg *argt = (gpu_arg *) args; + Scheduler *g_scheduler = argt->scheduler; + cl_command_queue *command_queue = argt->command_queue; + + TaskManagerImpl *manager = new GpuTaskManagerImpl(); + g_scheduler->init(manager, argt->useRefDma); + g_scheduler->set_command_queue(command_queue); + + manager->set_scheduler(g_scheduler); + + g_scheduler->run(); + g_scheduler->finish(); + + return NULL }
--- a/TaskManager/Gpu/GpuThreads.h Thu Apr 05 12:15:08 2012 +0900 +++ b/TaskManager/Gpu/GpuThreads.h Thu Apr 05 19:05:35 2012 +0900 @@ -1,6 +1,7 @@ #ifndef INCLUDED_GPU_THREADS #define INCLUDED_GPU_THREADS +#include <pthread.h> #include "Threads.h" #ifdef __APPLE__ @@ -9,6 +10,12 @@ #include <CL/cl.h> #endif +struct gpu_arg { + GpuScheduler *scheduler; + cl_command_queue *command_queue; + int useRefDma; +} + class GpuThreads : public Threads { public: GpuThreads(int num, int useRefDma, int start_id); @@ -19,6 +26,11 @@ cl_context context; cl_command_queue command_queue; + +private: + gpu_arg *args; + pthread_t *threads; + int use_refdma; cl_int ret; };