forked from jaredhoberock/bulk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfutures.cu
More file actions
52 lines (40 loc) · 794 Bytes
/
futures.cu
File metadata and controls
52 lines (40 loc) · 794 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <bulk/bulk.hpp>
#include <cstdio>
#include <typeinfo>
struct task1
{
__device__
void operator()()
{
printf("Hello world from task1\n");
}
};
struct task2
{
__device__
void operator()()
{
printf("Hello world from task2\n");
}
};
void task3()
{
printf("Hello world from task3\n");
};
int main()
{
cudaStream_t s1;
cudaStreamCreate(&s1);
using bulk::par;
using bulk::async;
// we can insert a task into a stream directly
bulk::future<void> t1 = async(par(s1, 1), task1());
// or we can make a new task depend on a previous future
bulk::future<void> t2 = async(par(t1, 1), task2());
// task3 is independent of both task1 & task2 and executes in this thread
task3();
t1.wait();
t2.wait();
cudaStreamDestroy(s1);
return 0;
}