Mercurial > hg > Game > Cerium
annotate TaskManager/Gpu/GpuThreads.cc @ 1437:fa6723e7d329 draft
fix GpuTaskManagerImpl
author | Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sat, 07 Apr 2012 09:29:09 +0900 |
parents | 42057124fb44 |
children | 3c787a21ff10 |
rev | line source |
---|---|
1433 | 1 #include "GpuThreads.h" |
1434 | 2 #include "GpuScheduler.h" |
3 #include "TaskManagerImpl.h" | |
1433 | 4 |
1436
42057124fb44
change to Singleton Pattern
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
1435
diff
changeset
|
5 GpuThreads::GpuThreads() |
1433 | 6 { |
1434 | 7 threads = new pthread_t; |
8 args = new gpu_arg; | |
1433 | 9 } |
10 | |
11 GpuThreads::~GpuThreads() | |
12 { | |
1434 | 13 delete threads; |
14 delete args; | |
1433 | 15 } |
16 | |
17 void | |
1436
42057124fb44
change to Singleton Pattern
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
1435
diff
changeset
|
18 GpuThreads::init() |
1433 | 19 { |
1436
42057124fb44
change to Singleton Pattern
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
1435
diff
changeset
|
20 clGetPlatformIDs(1, &platfrom_id, &ret_num_platforms); |
42057124fb44
change to Singleton Pattern
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
1435
diff
changeset
|
21 clGetDeviceIds(platform_id, CL_DEVICE_TYPE_GPU, 1, &device_id, &ret_num_devices); |
42057124fb44
change to Singleton Pattern
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
1435
diff
changeset
|
22 // unavailable GPU |
42057124fb44
change to Singleton Pattern
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
1435
diff
changeset
|
23 if( ret_num_devices == 0) { |
42057124fb44
change to Singleton Pattern
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
1435
diff
changeset
|
24 exit(EXIT_FAILURE); |
42057124fb44
change to Singleton Pattern
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
1435
diff
changeset
|
25 } |
42057124fb44
change to Singleton Pattern
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
1435
diff
changeset
|
26 context = clCreateContext(NULL, 1, device_id, NULL, NULL, &ret); |
42057124fb44
change to Singleton Pattern
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
1435
diff
changeset
|
27 command_queue = clCreateCommandQueue(context, *device_id, 0, &ret); |
42057124fb44
change to Singleton Pattern
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
1435
diff
changeset
|
28 |
1434 | 29 args.scheduler = new GpuScheduler(); |
30 args.useRefDma = use_refdma; | |
1436
42057124fb44
change to Singleton Pattern
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
1435
diff
changeset
|
31 args.command_queue = command_queue; |
1433 | 32 |
1434 | 33 pthread_create(&threads, NULL, &cpu_thread_run, (void*)&args); |
1433 | 34 |
35 } | |
36 | |
37 void * | |
38 GpuThreads::gpu_thread_run(void *args) | |
39 { | |
1434 | 40 gpu_arg *argt = (gpu_arg *) args; |
41 Scheduler *g_scheduler = argt->scheduler; | |
1436
42057124fb44
change to Singleton Pattern
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
1435
diff
changeset
|
42 // command_queueがThreadセーフじゃない。 |
1434 | 43 cl_command_queue *command_queue = argt->command_queue; |
44 | |
45 TaskManagerImpl *manager = new GpuTaskManagerImpl(); | |
46 g_scheduler->init(manager, argt->useRefDma); | |
47 g_scheduler->set_command_queue(command_queue); | |
48 | |
49 manager->set_scheduler(g_scheduler); | |
50 | |
51 g_scheduler->run(); | |
52 g_scheduler->finish(); | |
53 | |
54 return NULL | |
1433 | 55 } |
1437
fa6723e7d329
fix GpuTaskManagerImpl
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
1436
diff
changeset
|
56 |
fa6723e7d329
fix GpuTaskManagerImpl
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
1436
diff
changeset
|
57 int |
fa6723e7d329
fix GpuTaskManagerImpl
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
1436
diff
changeset
|
58 GpuThreads::get_mail(memaddr *ret) |
fa6723e7d329
fix GpuTaskManagerImpl
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
1436
diff
changeset
|
59 { |
fa6723e7d329
fix GpuTaskManagerImpl
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
1436
diff
changeset
|
60 *ret = args.scheduler->mail_read_from_host(); |
fa6723e7d329
fix GpuTaskManagerImpl
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
1436
diff
changeset
|
61 return 1; |
fa6723e7d329
fix GpuTaskManagerImpl
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
1436
diff
changeset
|
62 } |
fa6723e7d329
fix GpuTaskManagerImpl
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
1436
diff
changeset
|
63 |
fa6723e7d329
fix GpuTaskManagerImpl
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
1436
diff
changeset
|
64 int |
fa6723e7d329
fix GpuTaskManagerImpl
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
1436
diff
changeset
|
65 GpuThreads::has_mail(memaddr *ret) |
fa6723e7d329
fix GpuTaskManagerImpl
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
1436
diff
changeset
|
66 { |
fa6723e7d329
fix GpuTaskManagerImpl
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
1436
diff
changeset
|
67 if (args.scheduler->has_mail_from_host() != 0) { |
fa6723e7d329
fix GpuTaskManagerImpl
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
1436
diff
changeset
|
68 return get_mail(ret); |
fa6723e7d329
fix GpuTaskManagerImpl
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
1436
diff
changeset
|
69 } else { |
fa6723e7d329
fix GpuTaskManagerImpl
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
1436
diff
changeset
|
70 return 0; |
fa6723e7d329
fix GpuTaskManagerImpl
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
1436
diff
changeset
|
71 } |
fa6723e7d329
fix GpuTaskManagerImpl
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
1436
diff
changeset
|
72 } |
fa6723e7d329
fix GpuTaskManagerImpl
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
1436
diff
changeset
|
73 |
fa6723e7d329
fix GpuTaskManagerImpl
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
1436
diff
changeset
|
74 void |
fa6723e7d329
fix GpuTaskManagerImpl
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
1436
diff
changeset
|
75 CpuThreads::send_mail(int cpuid, int num, memaddr *data) |
fa6723e7d329
fix GpuTaskManagerImpl
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
1436
diff
changeset
|
76 { |
fa6723e7d329
fix GpuTaskManagerImpl
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
1436
diff
changeset
|
77 args.scheduler->mail_write_from_host(*data); |
fa6723e7d329
fix GpuTaskManagerImpl
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
1436
diff
changeset
|
78 } |