14
14
*
15
15
* SYCLcompat API
16
16
*
17
- * math_fast_length_test .cpp
17
+ * math_length_test .cpp
18
18
*
19
19
* Description:
20
- * Fast length tests
20
+ * vector length tests
21
21
**************************************************************************/
22
22
23
23
// The original source was under the license below:
41
41
42
42
#define MAX_LEN 5
43
43
44
- void compute_length (float *d_A, size_t n, float *ans) {
44
+ void compute_fast_length (float *d_A, size_t n, float *ans) {
45
45
*ans = syclcompat::fast_length (d_A, n);
46
46
}
47
47
48
- class FastLengthLauncher {
48
+ void compute_length (float *d_A, size_t n, float *ans) {
49
+ *ans = syclcompat::length (d_A, n);
50
+ }
51
+
52
+ class LengthLauncher {
49
53
protected:
50
54
float *data_;
51
55
float *result_;
52
56
float host_result_{0.0 };
53
57
54
58
public:
55
- FastLengthLauncher () {
59
+ LengthLauncher () {
56
60
data_ = (float *)syclcompat::malloc (MAX_LEN * sizeof (float ));
57
61
result_ = (float *)syclcompat::malloc (sizeof (float ));
58
62
};
59
- ~FastLengthLauncher () {
63
+ ~LengthLauncher () {
60
64
syclcompat::free (data_);
61
65
syclcompat::free (result_);
62
66
}
@@ -68,13 +72,13 @@ class FastLengthLauncher {
68
72
assert (diff <= 1 .e -5 );
69
73
}
70
74
71
- void launch (std::vector<float > vec) {
75
+ template < auto F> void launch (std::vector<float > vec) {
72
76
size_t n = vec.size ();
73
77
syclcompat::memcpy (data_, vec.data (), sizeof (float ) * n);
74
78
auto data = data_;
75
79
auto result = result_;
76
80
syclcompat::get_default_queue ().single_task (
77
- [data, result, n]() { compute_length (data, n, result); });
81
+ [data, result, n]() { F (data, n, result); });
78
82
syclcompat::memcpy (&host_result_, result_, sizeof (float ));
79
83
check_result (vec);
80
84
}
@@ -83,18 +87,36 @@ class FastLengthLauncher {
83
87
void test_fast_length () {
84
88
std::cout << __PRETTY_FUNCTION__ << std::endl;
85
89
86
- auto launcher = FastLengthLauncher ();
87
- launcher.launch (std::vector<float >{0.8970062715 });
88
- launcher.launch (std::vector<float >{0.8335529744 , 0.7346600673 });
89
- launcher.launch (std::vector<float >{0.1658983906 , 0.590226484 , 0.4891553616 });
90
- launcher.launch (std::vector<float >{0.6041178723 , 0.7760620605 , 0.2944284976 ,
91
- 0.6851913766 });
92
- launcher.launch (std::vector<float >{0.6041178723 , 0.7760620605 , 0.2944284976 ,
93
- 0.6851913766 , 0.6851913766 });
90
+ auto launcher = LengthLauncher ();
91
+ launcher.launch <compute_fast_length>(std::vector<float >{0.8970062715 });
92
+ launcher.launch <compute_fast_length>(
93
+ std::vector<float >{0.8335529744 , 0.7346600673 });
94
+ launcher.launch <compute_fast_length>(
95
+ std::vector<float >{0.1658983906 , 0.590226484 , 0.4891553616 });
96
+ launcher.launch <compute_fast_length>(std::vector<float >{
97
+ 0.6041178723 , 0.7760620605 , 0.2944284976 , 0.6851913766 });
98
+ launcher.launch <compute_fast_length>(std::vector<float >{
99
+ 0.6041178723 , 0.7760620605 , 0.2944284976 , 0.6851913766 , 0.6851913766 });
100
+ }
101
+
102
+ void test_length () {
103
+ std::cout << __PRETTY_FUNCTION__ << std::endl;
104
+
105
+ auto launcher = LengthLauncher ();
106
+ launcher.launch <compute_length>(std::vector<float >{0.8970062715 });
107
+ launcher.launch <compute_length>(
108
+ std::vector<float >{0.8335529744 , 0.7346600673 });
109
+ launcher.launch <compute_length>(
110
+ std::vector<float >{0.1658983906 , 0.590226484 , 0.4891553616 });
111
+ launcher.launch <compute_length>(std::vector<float >{
112
+ 0.6041178723 , 0.7760620605 , 0.2944284976 , 0.6851913766 });
113
+ launcher.launch <compute_length>(std::vector<float >{
114
+ 0.6041178723 , 0.7760620605 , 0.2944284976 , 0.6851913766 , 0.6851913766 });
94
115
}
95
116
96
117
int main () {
97
118
test_fast_length ();
119
+ test_length ();
98
120
99
121
return 0 ;
100
122
}
0 commit comments