forked from kashif/node-cuda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththrust_func.cu
77 lines (59 loc) · 1.91 KB
/
thrust_func.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
77
#include <thrust/device_ptr.h>
#include <thrust/for_each.h>
#include <thrust/iterator/zip_iterator.h>
#include <thrust/sort.h>
#include <thrust/scan.h>
#include <thrust/extrema.h>
#include "thrust_func.cuh"
typedef unsigned int uint;
// thrust::remove( ptr, ptr+n, int )
void thrust_inclusiveScan_( uint *ptr1, uint *ptr2, uint *ptr3 ){
thrust::inclusive_scan(
thrust::device_ptr<uint>( ptr1 ),
thrust::device_ptr<uint>( ptr2 ),
thrust::device_ptr<uint>( ptr3 )
);
};
void thrust_floatSort_int_(float *ptr1, float *ptr2, uint *ptr3){
thrust::sort_by_key(
thrust::device_ptr<float>(ptr1),
thrust::device_ptr<float>(ptr2),
thrust::device_ptr<uint >(ptr3)
);
};
int thrust_remove_int_(int *ptr1, int *ptr2, int value){
thrust::device_ptr<int> new_end = thrust::remove(
thrust::device_ptr<int>(ptr1),
thrust::device_ptr<int>(ptr2),
value
);
return new_end.get() - ptr1;
};
float thrust_reduce_floatSum_(float *ptr1, float *ptr2){
return thrust::reduce(
thrust::device_ptr<float>(ptr1),
thrust::device_ptr<float>(ptr2),
0.0,
thrust::plus<float>()
);
};
posval thrust_reduce_floatMax_(float *ptr1, float *ptr2){
thrust::device_ptr<float> dev_ptr1 = thrust::device_ptr<float>(ptr1);
thrust::device_ptr<float> dev_ptr2 = thrust::device_ptr<float>(ptr2);
thrust::device_ptr<float> max_ptr = thrust::max_element( dev_ptr1, dev_ptr2 );
posval rv;
rv.pos = &max_ptr[0] - &dev_ptr1[0];
// íå ïîíÿòíî, êàê îí ñ÷èòûâàåò äàííûå èç ïàìÿòè âèäåîêàðòû?
rv.val = max_ptr[0];
return rv;
};
posval thrust_reduce_floatMin_(float *ptr1, float *ptr2){
thrust::device_ptr<float> dev_ptr1 = thrust::device_ptr<float>(ptr1);
thrust::device_ptr<float> dev_ptr2 = thrust::device_ptr<float>(ptr2);
thrust::device_ptr<float> min_ptr = thrust::min_element(dev_ptr1, dev_ptr2);
posval rv;
rv.pos = &min_ptr[0] - &dev_ptr1[0];
// íå ïîíÿòíî, êàê îí ñ÷èòûâàåò äàííûå èç ïàìÿòè âèäåîêàðòû?
rv.val = min_ptr[0];
return rv;
};