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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1433
11dcd8165424 add GpuTaskManagerImpl
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 #include "GpuThreads.h"
1434
05d480ab70ba add GpuScheduler
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents: 1433
diff changeset
2 #include "GpuScheduler.h"
05d480ab70ba add GpuScheduler
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents: 1433
diff changeset
3 #include "TaskManagerImpl.h"
1433
11dcd8165424 add GpuTaskManagerImpl
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4
1436
42057124fb44 change to Singleton Pattern
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents: 1435
diff changeset
5 GpuThreads::GpuThreads()
1433
11dcd8165424 add GpuTaskManagerImpl
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 {
1434
05d480ab70ba add GpuScheduler
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents: 1433
diff changeset
7 threads = new pthread_t;
05d480ab70ba add GpuScheduler
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents: 1433
diff changeset
8 args = new gpu_arg;
1433
11dcd8165424 add GpuTaskManagerImpl
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 }
11dcd8165424 add GpuTaskManagerImpl
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10
11dcd8165424 add GpuTaskManagerImpl
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 GpuThreads::~GpuThreads()
11dcd8165424 add GpuTaskManagerImpl
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 {
1434
05d480ab70ba add GpuScheduler
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents: 1433
diff changeset
13 delete threads;
05d480ab70ba add GpuScheduler
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents: 1433
diff changeset
14 delete args;
1433
11dcd8165424 add GpuTaskManagerImpl
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 }
11dcd8165424 add GpuTaskManagerImpl
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16
11dcd8165424 add GpuTaskManagerImpl
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
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
11dcd8165424 add GpuTaskManagerImpl
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
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
05d480ab70ba add GpuScheduler
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents: 1433
diff changeset
29 args.scheduler = new GpuScheduler();
05d480ab70ba add GpuScheduler
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents: 1433
diff changeset
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
11dcd8165424 add GpuTaskManagerImpl
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
32
1434
05d480ab70ba add GpuScheduler
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents: 1433
diff changeset
33 pthread_create(&threads, NULL, &cpu_thread_run, (void*)&args);
1433
11dcd8165424 add GpuTaskManagerImpl
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
34
11dcd8165424 add GpuTaskManagerImpl
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 }
11dcd8165424 add GpuTaskManagerImpl
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
36
11dcd8165424 add GpuTaskManagerImpl
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 void *
11dcd8165424 add GpuTaskManagerImpl
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 GpuThreads::gpu_thread_run(void *args)
11dcd8165424 add GpuTaskManagerImpl
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 {
1434
05d480ab70ba add GpuScheduler
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents: 1433
diff changeset
40 gpu_arg *argt = (gpu_arg *) args;
05d480ab70ba add GpuScheduler
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents: 1433
diff changeset
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
05d480ab70ba add GpuScheduler
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents: 1433
diff changeset
43 cl_command_queue *command_queue = argt->command_queue;
05d480ab70ba add GpuScheduler
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents: 1433
diff changeset
44
05d480ab70ba add GpuScheduler
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents: 1433
diff changeset
45 TaskManagerImpl *manager = new GpuTaskManagerImpl();
05d480ab70ba add GpuScheduler
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents: 1433
diff changeset
46 g_scheduler->init(manager, argt->useRefDma);
05d480ab70ba add GpuScheduler
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents: 1433
diff changeset
47 g_scheduler->set_command_queue(command_queue);
05d480ab70ba add GpuScheduler
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents: 1433
diff changeset
48
05d480ab70ba add GpuScheduler
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents: 1433
diff changeset
49 manager->set_scheduler(g_scheduler);
05d480ab70ba add GpuScheduler
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents: 1433
diff changeset
50
05d480ab70ba add GpuScheduler
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents: 1433
diff changeset
51 g_scheduler->run();
05d480ab70ba add GpuScheduler
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents: 1433
diff changeset
52 g_scheduler->finish();
05d480ab70ba add GpuScheduler
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents: 1433
diff changeset
53
05d480ab70ba add GpuScheduler
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents: 1433
diff changeset
54 return NULL
1433
11dcd8165424 add GpuTaskManagerImpl
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
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 }