Mercurial > hg > Game > Cerium
annotate 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 |
rev | line source |
---|---|
1440 | 1 #include "GpuScheduler.h" |
2 #include "GpuDmaManager.h" | |
3 #include "GpuThreads.h" | |
4 #include "stdio.h" | |
1441
50d2c1e85535
change to get size for fstat
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1440
diff
changeset
|
5 #include <fcntl.h> |
1440 | 6 |
7 void | |
8 GpuScheduler::init_impl(int useRefDma) | |
9 { | |
10 connector = new GpuDmamanager; | |
11 } | |
12 | |
13 int | |
14 GpuScheduler::run() | |
15 { | |
16 memaddr params_addr = connector->task_list_mail_read(); | |
17 | |
18 if ((memaddr)params_addr == (memaddr)MY_SPE_COMMAND_EXIT) { | |
19 // 終了確認 | |
20 return 0; | |
21 } | |
22 | |
23 TaskListPtr *tasklist = (TaskListPtr)connector->dma_load(tasklist, params_addr, | |
1441
50d2c1e85535
change to get size for fstat
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1440
diff
changeset
|
24 sizeof(TaskList), DMA_READ_TASKLIST); |
1440 | 25 GpuThreads gputhreads = GpuThreads::getInstance(); |
26 cl_command_queue& command_queue = gputhreads.cl_command_queue; | |
27 | |
28 for (int cur_index = 0; cur_index < tasklist->length; cur_index++) { | |
29 TaskPtr task = tasklist.tasks[cur_index]; | |
30 cl_kernel& kernel = task_list[task->command].kernel; | |
31 // メモリオブジェクトの生成? GpuThreadsでやるのがよい? | |
32 // カーネル引数の設定 | |
33 clEnqueueTask(command_queue, kernel, 0, NULL, NULL); | |
34 // メモリオブジェクトからの読み込み | |
35 } | |
36 // TaskArrayの処理 | |
37 } | |
38 | |
39 | |
40 | |
41 void | |
42 gpu_register_task(int cmd, char* filename, char* functionname) | |
43 { | |
44 GpuThreads gputhreads = GpuThreads::getInstance(); | |
45 cl_context& context = &gputhreads.context; | |
46 cl_device_id& device_id = &gputhreads.device_id; | |
47 | |
1441
50d2c1e85535
change to get size for fstat
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1440
diff
changeset
|
48 int *fp; |
1440 | 49 char *souce_str; |
50 size_t source_size; | |
1441
50d2c1e85535
change to get size for fstat
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1440
diff
changeset
|
51 |
50d2c1e85535
change to get size for fstat
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1440
diff
changeset
|
52 fp = open(filename, O_RDONLY); |
50d2c1e85535
change to get size for fstat
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1440
diff
changeset
|
53 |
1440 | 54 if (!fp) { |
55 fprintf(stderr, "Failed to load kernel.\n"); | |
56 exit(1); | |
57 } | |
1441
50d2c1e85535
change to get size for fstat
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1440
diff
changeset
|
58 |
50d2c1e85535
change to get size for fstat
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1440
diff
changeset
|
59 struct stat stats; |
50d2c1e85535
change to get size for fstat
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1440
diff
changeset
|
60 fstat(fileno(fp),&stats); |
50d2c1e85535
change to get size for fstat
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1440
diff
changeset
|
61 off_t size = stas.st_size; |
50d2c1e85535
change to get size for fstat
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1440
diff
changeset
|
62 |
50d2c1e85535
change to get size for fstat
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1440
diff
changeset
|
63 if (!size) { |
50d2c1e85535
change to get size for fstat
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1440
diff
changeset
|
64 fprintf(stderr, "Failed to load kernel.\n"); |
50d2c1e85535
change to get size for fstat
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1440
diff
changeset
|
65 } |
50d2c1e85535
change to get size for fstat
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1440
diff
changeset
|
66 |
50d2c1e85535
change to get size for fstat
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1440
diff
changeset
|
67 source_str = (char*)malloc(size); |
1440 | 68 |
1441
50d2c1e85535
change to get size for fstat
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1440
diff
changeset
|
69 source_size = read(source_str, size, fp); |
50d2c1e85535
change to get size for fstat
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1440
diff
changeset
|
70 close(fp); |
1440 | 71 |
72 cl_program program = NULL; | |
73 cl_int ret; | |
74 program = clCreateProgramWithSource(context, 1, (const char **)&source_str, | |
75 (const size_t *)&source_size, &ret); | |
76 | |
77 clBuildProgram(program, 1, &device_id, NULL, NULL, NULL); | |
78 | |
79 cl_kernel *kernel = new cl_kernel; | |
80 *kernel = clCreateKernel(program, functionname, &ret); | |
81 | |
82 task_list[cmd].run = run; | |
83 task_list[cmd].load = null_loader; | |
84 task_list[cmd].wait = null_waiter; | |
85 task_list[cmd].name = str; | |
86 task_list[cmd].kernel = kernel; | |
87 | |
88 } |