forked from NVIDIA/thrust
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfloat3_optimization.test
104 lines (82 loc) · 2.94 KB
/
float3_optimization.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
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
PREAMBLE = \
"""
#include <thrust/transform.h>
#include <thrust/iterator/zip_iterator.h>
#include <cmath>
template <typename T>
struct rotate_tuple
{
template <typename Tuple>
__host__ __device__
Tuple operator()(const Tuple& t) const
{
T x = thrust::get<0>(t);
T y = thrust::get<1>(t);
T z = thrust::get<2>(t);
T rx = 0.36f*x + 0.48f*y + -0.80f*z;
T ry =-0.80f*x + 0.60f*y + 0.00f*z;
T rz = 0.48f*x + 0.64f*y + 0.60f*z;
return Tuple(rx, ry, rz);
}
};
struct rotate_float3
{
__host__ __device__
float3 operator()(const float3& t) const
{
float x = t.x;
float y = t.y;
float z = t.z;
float3 rt;
rt.x = 0.36f*x + 0.48f*y + -0.80f*z;
rt.y =-0.80f*x + 0.60f*y + 0.00f*z;
rt.z = 0.48f*x + 0.64f*y + 0.60f*z;
return rt;
}
};
template <typename Vector, typename Vector3>
void rotate_fast(Vector& x, Vector& y, Vector& z, Vector3& v)
{
typedef typename Vector::value_type T;
size_t N = x.size();
thrust::transform(thrust::make_zip_iterator(thrust::make_tuple(x.begin(), y.begin(), z.begin())),
thrust::make_zip_iterator(thrust::make_tuple(x.begin(), y.begin(), z.begin())) + N,
thrust::make_zip_iterator(thrust::make_tuple(x.begin(), y.begin(), z.begin())),
rotate_tuple<T>());
}
template <typename Vector, typename Vector3>
void rotate_slow(Vector& x, Vector& y, Vector& z, Vector3& v)
{
thrust::transform(v.begin(), v.end(), v.begin(), rotate_float3());
}
"""
INITIALIZE = \
"""
thrust::host_vector<$InputType> h_x = unittest::random_samples<$InputType>($InputSize);
thrust::host_vector<$InputType> h_y = unittest::random_samples<$InputType>($InputSize);
thrust::host_vector<$InputType> h_z = unittest::random_samples<$InputType>($InputSize);
thrust::device_vector<$InputType> d_x = h_x;
thrust::device_vector<$InputType> d_y = h_y;
thrust::device_vector<$InputType> d_z = h_z;
thrust::host_vector<float3> h_v($InputSize, make_float3(1.0,0.4,0.2));
thrust::device_vector<float3> d_v = h_v;
$Method(h_x, h_y, h_z, h_v);
$Method(d_x, d_y, d_z, d_v);
ASSERT_ALMOST_EQUAL(h_x, d_x);
ASSERT_ALMOST_EQUAL(h_y, d_y);
ASSERT_ALMOST_EQUAL(h_z, d_z);
"""
TIME = \
"""
$Method(d_x, d_y, d_z, d_v);
"""
FINALIZE = \
"""
RECORD_TIME();
RECORD_THROUGHPUT(2*9*double($InputSize));
RECORD_BANDWIDTH(2*3*sizeof($InputType) * double($InputSize));
"""
InputTypes = ['float']
InputSizes = [2**24]
Methods = ['rotate_fast','rotate_slow']
TestVariables = [('InputType', InputTypes), ('InputSize', InputSizes), ('Method', Methods)]