forked from NVIDIA/thrust
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcopy_if.test
50 lines (38 loc) · 1.43 KB
/
copy_if.test
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
PREAMBLE = \
"""
#include <thrust/copy.h>
#include <thrust/device_vector.h>
#include <thrust/host_vector.h>
#include <unittest/unittest.h>
#include <thrust/sequence.h>
struct pred
{
__host__ __device__
bool operator()(int x) { return bool(x); }
};
"""
INITIALIZE = \
"""
thrust::host_vector<int> h_input($InputSize); thrust::sequence(h_input.begin(), h_input.end());
thrust::host_vector<int> h_stencil = unittest::random_integers<bool>($InputSize);
thrust::host_vector<int> h_output($InputSize, -1);
thrust::device_vector<int> d_input = h_input;
thrust::device_vector<int> d_stencil = h_stencil;
thrust::device_vector<int> d_output = h_output;
size_t h_count = thrust::copy_if(h_input.begin(), h_input.end(), h_stencil.begin(), h_output.begin(), pred()) - h_output.begin();
size_t d_count = thrust::copy_if(d_input.begin(), d_input.end(), d_stencil.begin(), d_output.begin(), pred()) - d_output.begin();
ASSERT_EQUAL(h_output, d_output);
ASSERT_EQUAL(h_count, d_count);
"""
TIME = \
"""
thrust::copy_if(d_input.begin(), d_input.end(), d_stencil.begin(), d_output.begin(), pred());
"""
FINALIZE = \
"""
RECORD_TIME();
RECORD_THROUGHPUT(double($InputSize));
RECORD_BANDWIDTH((2*sizeof(int) + 2*sizeof(float)) * double($InputSize));
"""
InputSizes = [2**N for N in range(20, 27)]
TestVariables = [('InputSize', InputSizes)]