-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathmss.cu
76 lines (64 loc) · 2.22 KB
/
mss.cu
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <thrust/device_vector.h>
#include <thrust/functional.h>
#include <thrust/transform_scan.h>
#include <iostream>
#include <cstdlib>
#include <sys/time.h>
#include "common.hpp"
typedef thrust::tuple<int, int, int, int> MSSTuple;
class prepare : public thrust::unary_function<const int, MSSTuple> {
public:
__host__ __device__ MSSTuple operator()(const int x) const {
return MSSTuple(max(x,0), max(x,0), max(x,0), x);
}
};
class combine : public thrust::binary_function<const MSSTuple &, const MSSTuple &, MSSTuple> {
public:
__host__ __device__ MSSTuple operator()(const MSSTuple &x,
const MSSTuple &y) const {
int mssx = thrust::get<0>(x);
int misx = thrust::get<1>(x);
int mcsx = thrust::get<2>(x);
int tsx = thrust::get<3>(x);
int mssy = thrust::get<0>(y);
int misy = thrust::get<1>(y);
int mcsy = thrust::get<2>(y);
int tsy = thrust::get<3>(y);
return MSSTuple(max(mssx, max(mssy, mcsx + misy)),
max(misx, tsx+misy),
max(mcsy, mcsx+tsy),
tsx + tsy);
}
};
int main(int argc, char **argv) {
int runs, n;
runs_and_n(argc, argv, &runs, &n);
thrust::device_vector<int> d(n);
thrust::device_vector<int> dres(n);
init_vector(&d);
// Warmup
thrust::transform_inclusive_scan
(d.begin(), d.end(),
thrust::make_zip_iterator(thrust::make_tuple
(dres.begin(),
thrust::make_discard_iterator(),
thrust::make_discard_iterator(),
thrust::make_discard_iterator())),
prepare(),
combine());
start_timing();
for (size_t i = 0; i < runs; ++i) {
thrust::transform_inclusive_scan
(d.begin(), d.end(),
thrust::make_zip_iterator(thrust::make_tuple
(dres.begin(),
thrust::make_discard_iterator(),
thrust::make_discard_iterator(),
thrust::make_discard_iterator())),
prepare(),
combine());
}
end_timing();
std::cout << "Result: " << dres[n-1] << std::endl;
report_time(runs);
}