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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1440
d66dcb067c89 create test program
YuuhiTOMARI
parents:
diff changeset
1 #include "GpuScheduler.h"
d66dcb067c89 create test program
YuuhiTOMARI
parents:
diff changeset
2 #include "GpuDmaManager.h"
d66dcb067c89 create test program
YuuhiTOMARI
parents:
diff changeset
3 #include "GpuThreads.h"
d66dcb067c89 create test program
YuuhiTOMARI
parents:
diff changeset
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
d66dcb067c89 create test program
YuuhiTOMARI
parents:
diff changeset
6
d66dcb067c89 create test program
YuuhiTOMARI
parents:
diff changeset
7 void
d66dcb067c89 create test program
YuuhiTOMARI
parents:
diff changeset
8 GpuScheduler::init_impl(int useRefDma)
d66dcb067c89 create test program
YuuhiTOMARI
parents:
diff changeset
9 {
d66dcb067c89 create test program
YuuhiTOMARI
parents:
diff changeset
10 connector = new GpuDmamanager;
d66dcb067c89 create test program
YuuhiTOMARI
parents:
diff changeset
11 }
d66dcb067c89 create test program
YuuhiTOMARI
parents:
diff changeset
12
d66dcb067c89 create test program
YuuhiTOMARI
parents:
diff changeset
13 int
d66dcb067c89 create test program
YuuhiTOMARI
parents:
diff changeset
14 GpuScheduler::run()
d66dcb067c89 create test program
YuuhiTOMARI
parents:
diff changeset
15 {
d66dcb067c89 create test program
YuuhiTOMARI
parents:
diff changeset
16 memaddr params_addr = connector->task_list_mail_read();
d66dcb067c89 create test program
YuuhiTOMARI
parents:
diff changeset
17
d66dcb067c89 create test program
YuuhiTOMARI
parents:
diff changeset
18 if ((memaddr)params_addr == (memaddr)MY_SPE_COMMAND_EXIT) {
d66dcb067c89 create test program
YuuhiTOMARI
parents:
diff changeset
19 // 終了確認
d66dcb067c89 create test program
YuuhiTOMARI
parents:
diff changeset
20 return 0;
d66dcb067c89 create test program
YuuhiTOMARI
parents:
diff changeset
21 }
d66dcb067c89 create test program
YuuhiTOMARI
parents:
diff changeset
22
d66dcb067c89 create test program
YuuhiTOMARI
parents:
diff changeset
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
d66dcb067c89 create test program
YuuhiTOMARI
parents:
diff changeset
25 GpuThreads gputhreads = GpuThreads::getInstance();
d66dcb067c89 create test program
YuuhiTOMARI
parents:
diff changeset
26 cl_command_queue& command_queue = gputhreads.cl_command_queue;
d66dcb067c89 create test program
YuuhiTOMARI
parents:
diff changeset
27
d66dcb067c89 create test program
YuuhiTOMARI
parents:
diff changeset
28 for (int cur_index = 0; cur_index < tasklist->length; cur_index++) {
d66dcb067c89 create test program
YuuhiTOMARI
parents:
diff changeset
29 TaskPtr task = tasklist.tasks[cur_index];
d66dcb067c89 create test program
YuuhiTOMARI
parents:
diff changeset
30 cl_kernel& kernel = task_list[task->command].kernel;
d66dcb067c89 create test program
YuuhiTOMARI
parents:
diff changeset
31 // メモリオブジェクトの生成? GpuThreadsでやるのがよい?
d66dcb067c89 create test program
YuuhiTOMARI
parents:
diff changeset
32 // カーネル引数の設定
d66dcb067c89 create test program
YuuhiTOMARI
parents:
diff changeset
33 clEnqueueTask(command_queue, kernel, 0, NULL, NULL);
d66dcb067c89 create test program
YuuhiTOMARI
parents:
diff changeset
34 // メモリオブジェクトからの読み込み
d66dcb067c89 create test program
YuuhiTOMARI
parents:
diff changeset
35 }
d66dcb067c89 create test program
YuuhiTOMARI
parents:
diff changeset
36 // TaskArrayの処理
d66dcb067c89 create test program
YuuhiTOMARI
parents:
diff changeset
37 }
d66dcb067c89 create test program
YuuhiTOMARI
parents:
diff changeset
38
d66dcb067c89 create test program
YuuhiTOMARI
parents:
diff changeset
39
d66dcb067c89 create test program
YuuhiTOMARI
parents:
diff changeset
40
d66dcb067c89 create test program
YuuhiTOMARI
parents:
diff changeset
41 void
d66dcb067c89 create test program
YuuhiTOMARI
parents:
diff changeset
42 gpu_register_task(int cmd, char* filename, char* functionname)
d66dcb067c89 create test program
YuuhiTOMARI
parents:
diff changeset
43 {
d66dcb067c89 create test program
YuuhiTOMARI
parents:
diff changeset
44 GpuThreads gputhreads = GpuThreads::getInstance();
d66dcb067c89 create test program
YuuhiTOMARI
parents:
diff changeset
45 cl_context& context = &gputhreads.context;
d66dcb067c89 create test program
YuuhiTOMARI
parents:
diff changeset
46 cl_device_id& device_id = &gputhreads.device_id;
d66dcb067c89 create test program
YuuhiTOMARI
parents:
diff changeset
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
d66dcb067c89 create test program
YuuhiTOMARI
parents:
diff changeset
49 char *souce_str;
d66dcb067c89 create test program
YuuhiTOMARI
parents:
diff changeset
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
d66dcb067c89 create test program
YuuhiTOMARI
parents:
diff changeset
54 if (!fp) {
d66dcb067c89 create test program
YuuhiTOMARI
parents:
diff changeset
55 fprintf(stderr, "Failed to load kernel.\n");
d66dcb067c89 create test program
YuuhiTOMARI
parents:
diff changeset
56 exit(1);
d66dcb067c89 create test program
YuuhiTOMARI
parents:
diff changeset
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
d66dcb067c89 create test program
YuuhiTOMARI
parents:
diff changeset
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
d66dcb067c89 create test program
YuuhiTOMARI
parents:
diff changeset
71
d66dcb067c89 create test program
YuuhiTOMARI
parents:
diff changeset
72 cl_program program = NULL;
d66dcb067c89 create test program
YuuhiTOMARI
parents:
diff changeset
73 cl_int ret;
d66dcb067c89 create test program
YuuhiTOMARI
parents:
diff changeset
74 program = clCreateProgramWithSource(context, 1, (const char **)&source_str,
d66dcb067c89 create test program
YuuhiTOMARI
parents:
diff changeset
75 (const size_t *)&source_size, &ret);
d66dcb067c89 create test program
YuuhiTOMARI
parents:
diff changeset
76
d66dcb067c89 create test program
YuuhiTOMARI
parents:
diff changeset
77 clBuildProgram(program, 1, &device_id, NULL, NULL, NULL);
d66dcb067c89 create test program
YuuhiTOMARI
parents:
diff changeset
78
d66dcb067c89 create test program
YuuhiTOMARI
parents:
diff changeset
79 cl_kernel *kernel = new cl_kernel;
d66dcb067c89 create test program
YuuhiTOMARI
parents:
diff changeset
80 *kernel = clCreateKernel(program, functionname, &ret);
d66dcb067c89 create test program
YuuhiTOMARI
parents:
diff changeset
81
d66dcb067c89 create test program
YuuhiTOMARI
parents:
diff changeset
82 task_list[cmd].run = run;
d66dcb067c89 create test program
YuuhiTOMARI
parents:
diff changeset
83 task_list[cmd].load = null_loader;
d66dcb067c89 create test program
YuuhiTOMARI
parents:
diff changeset
84 task_list[cmd].wait = null_waiter;
d66dcb067c89 create test program
YuuhiTOMARI
parents:
diff changeset
85 task_list[cmd].name = str;
d66dcb067c89 create test program
YuuhiTOMARI
parents:
diff changeset
86 task_list[cmd].kernel = kernel;
d66dcb067c89 create test program
YuuhiTOMARI
parents:
diff changeset
87
d66dcb067c89 create test program
YuuhiTOMARI
parents:
diff changeset
88 }