annotate TaskManager/Cuda/CudaThreads.cc @ 2069:26aa08c9a1de draft default tip

cuda example fix
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 12 Feb 2017 10:04:55 +0900
parents fdffcf8feeab
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1915
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 #include "CudaThreads.h"
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 #include "CudaScheduler.h"
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 #include "TaskManagerImpl.h"
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 #include "SpeTaskManagerImpl.h"
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 const int gpu_num = 1;
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 CudaThreads::CudaThreads(int useRefDma) : use_refdma(useRefDma)
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 {
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 threads = new pthread_t[gpu_num];
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 args = new cuda_thread_arg_t;
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 }
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13
1925
cd5bbd8ec5d6 fix CudaScheduler
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1915
diff changeset
14 CudaThreads::~CudaThreads()
1915
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 {
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 memaddr mail = (memaddr)MY_SPE_COMMAND_EXIT;
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 send_mail(0,1,&mail);
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 pthread_join(threads[0], NULL);
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19
1962
fdffcf8feeab fix CudaScheduler
kkb
parents: 1925
diff changeset
20 delete args->scheduler;
fdffcf8feeab fix CudaScheduler
kkb
parents: 1925
diff changeset
21 delete[] threads;
1915
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 delete args;
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 }
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24
1962
fdffcf8feeab fix CudaScheduler
kkb
parents: 1925
diff changeset
25 /**
fdffcf8feeab fix CudaScheduler
kkb
parents: 1925
diff changeset
26 Called from CpuThreads::init()
fdffcf8feeab fix CudaScheduler
kkb
parents: 1925
diff changeset
27 This Semaphore tells that GpuThreads is initalized.
fdffcf8feeab fix CudaScheduler
kkb
parents: 1925
diff changeset
28 */
1915
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 void
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 CudaThreads::set_wait(SemPtr wait)
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 {
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 args->wait=wait;
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 }
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
34
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 void
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 CudaThreads::init()
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 {
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 args->scheduler = new CudaScheduler();
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 args->useRefDma = use_refdma;
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
40
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 pthread_create(&threads[0], NULL, &cuda_thread_run, args);
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 }
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
43
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 void
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 CudaThreads::set_mail_waiter(SemPtr w)
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 {
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 args->scheduler->connector->set_mail_waiter(w);
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 }
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
49
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 void *
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 CudaThreads::cuda_thread_run(void *args)
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 {
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 cuda_thread_arg_t *argt = (cuda_thread_arg_t *) args;
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 Scheduler *g_scheduler = argt->scheduler;
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
55
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 TaskManagerImpl *manager = new SpeTaskManagerImpl();
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 g_scheduler->init(manager, argt->useRefDma);
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
58
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 manager->set_scheduler(g_scheduler);
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
60
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 argt->wait->sem_v();
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
62
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 g_scheduler->run();
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 g_scheduler->finish();
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
65
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 return NULL;
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 }
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
68
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 int
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 CudaThreads::spawn_task(int id, TaskListPtr p) {
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 send_mail(id, 1, (memaddr*)p);
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
72 return 0;
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
73 }
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
74
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
75 int
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
76 CudaThreads::get_mail(int speid, int count, memaddr *ret)
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
77 {
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
78 *ret = args->scheduler->mail_read_from_host();
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
79 return 1;
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
80 }
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
81
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
82 int
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
83 CudaThreads::has_mail(int speid, int count, memaddr *ret)
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
84 {
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
85 if (args->scheduler->has_mail_from_host() != 0) {
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
86 return get_mail(0, 0, ret);
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
87 } else {
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
88 return 0;
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
89 }
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
90 }
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
91
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
92 void
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
93 CudaThreads::send_mail(int speid, int num, memaddr *data)
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
94 {
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
95 args->scheduler->mail_write_from_host(*data);
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
96 }
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
97
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
98 void
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
99 CudaThreads::add_output_tasklist(int command, memaddr buff, int alloc_size)
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
100 {
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
101 }