forked from NVIDIA/thrust
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathaxpy.test
84 lines (62 loc) · 1.96 KB
/
axpy.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
PREAMBLE = \
"""
#include <thrust/transform.h>
#include <thrust/functional.h>
//#include <cublas.h>
#include <cmath>
template <typename T>
struct axpy
{
T a;
axpy(T a) : a(a) {}
__host__ __device__
T operator()(T x, T y) const
{
return a * x + y;
}
};
template <typename Vector>
void axpy_fast(const typename Vector::value_type a, const Vector& x, Vector& y)
{
typedef typename Vector::value_type T;
thrust::transform(x.begin(), x.end(), y.begin(), y.begin(), axpy<T>(a));
}
template <typename Vector>
void axpy_slow(const typename Vector::value_type a, const Vector& x, Vector& y)
{
typedef typename Vector::value_type T;
// temp <- a
Vector temp(x.size(), a);
// temp <- a * x
thrust::transform(x.begin(), x.end(), temp.begin(), temp.begin(), thrust::multiplies<float>());
// y <- a * x + y
thrust::transform(temp.begin(), temp.end(), y.begin(), y.begin(), thrust::plus<float>());
}
"""
INITIALIZE = \
"""
//cublasInit();
thrust::host_vector<$InputType> h_x = unittest::random_samples<$InputType>($InputSize);
thrust::host_vector<$InputType> h_y = unittest::random_samples<$InputType>($InputSize);
thrust::device_vector<$InputType> d_x = h_x;
thrust::device_vector<$InputType> d_y = h_y;
$InputType a = 2.0;
$Method(a, h_x, h_y);
$Method(a, d_x, d_y);
ASSERT_EQUAL(h_x, d_x);
ASSERT_EQUAL(h_y, d_y);
"""
TIME = \
"""
$Method(a, d_x, d_y);
"""
FINALIZE = \
"""
RECORD_TIME();
RECORD_THROUGHPUT(2 * double($InputSize));
RECORD_BANDWIDTH(3* sizeof($InputType) * double($InputSize));
"""
InputTypes = ['float', 'double']
InputSizes = [2**24]
Methods = ['axpy_fast', 'axpy_slow']
TestVariables = [('InputType', InputTypes), ('InputSize', InputSizes), ('Method', Methods)]