13
13
bool operator ()(sycl::queue &Q, cmplx<T> init, \
14
14
cmplx<T> ref = cmplx<T>(0 , 0 ), bool use_ref = false) { \
15
15
bool pass = true ; \
16
- \
17
16
auto std_in = init_std_complex (init.re , init.im ); \
18
17
experimental::complex<T> cplx_input{init.re , init.im }; \
19
- \
20
- auto *cplx_out = sycl::malloc_shared<experimental::complex<T>>(1 , Q); \
21
- \
18
+ sycl::buffer<experimental::complex<T>> cplx_out_buf{sycl::range{1 }}; \
22
19
/* Get std::complex output*/ \
23
20
std::complex<T> std_out{ref.re , ref.im }; \
24
21
if (!use_ref) \
25
22
std_out = std::math_func (std_in); \
26
- \
27
23
/* Check cplx::complex output from device*/ \
28
- Q.single_task ([=]() { \
29
- cplx_out[0 ] = experimental::math_func<T>(cplx_input); \
30
- }).wait (); \
31
- \
32
- pass &= check_results (cplx_out[0 ], std_out, /* is_device*/ true ); \
24
+ Q.submit ([&](sycl::handler &h) { \
25
+ sycl::accessor cplx_out{cplx_out_buf, h}; \
26
+ h.single_task ( \
27
+ [=]() { cplx_out[0 ] = experimental::math_func<T>(cplx_input); }); \
28
+ }); \
29
+ sycl::host_accessor cplx_out_acc{cplx_out_buf}; \
30
+ pass &= check_results (cplx_out_acc[0 ], std_out, /* is_device*/ true ); \
33
31
\
34
32
/* Check cplx::complex output from host*/ \
35
- cplx_out[0 ] = experimental::math_func<T>(cplx_input); \
36
- \
37
- pass &= check_results (cplx_out[0 ], std_out, /* is_device*/ false ); \
38
- \
39
- sycl::free (cplx_out, Q); \
33
+ cplx_out_acc[0 ] = experimental::math_func<T>(cplx_input); \
40
34
\
35
+ pass &= check_results (cplx_out_acc[0 ], std_out, /* is_device*/ false ); \
41
36
return pass; \
42
37
} \
43
38
};
@@ -73,28 +68,26 @@ TEST_MATH_OP_TYPE(tanh)
73
68
\
74
69
auto std_in = init_std_complex (init.re , init.im ); \
75
70
experimental::complex<T> cplx_input{init.re , init.im }; \
76
- \
77
- auto *cplx_out = sycl::malloc_shared<T>(1 , Q); \
71
+ sycl::buffer<T> cplx_out_buf{sycl::range{1 }}; \
78
72
\
79
73
/* Get std::complex output*/ \
80
74
T std_out = ref.re ; \
81
75
if (!use_ref) \
82
76
std_out = std::math_func (std_in); \
83
77
\
84
78
/* Check cplx::complex output from device*/ \
85
- Q.single_task ([=]() { \
86
- cplx_out[0 ] = experimental::math_func<T>(cplx_input); \
87
- }).wait (); \
88
- \
89
- pass &= check_results (cplx_out[0 ], std_out, /* is_device*/ true ); \
79
+ Q.submit ([&](sycl::handler &h) { \
80
+ sycl::accessor cplx_out{cplx_out_buf, h}; \
81
+ h.single_task ( \
82
+ [=]() { cplx_out[0 ] = experimental::math_func<T>(cplx_input); }); \
83
+ }); \
84
+ sycl::host_accessor cplx_out_acc{cplx_out_buf}; \
85
+ pass &= check_results (cplx_out_acc[0 ], std_out, /* is_device*/ true ); \
90
86
\
91
87
/* Check cplx::complex output from host*/ \
92
- cplx_out[0 ] = experimental::math_func<T>(cplx_input); \
93
- \
94
- pass &= check_results (cplx_out[0 ], std_out, /* is_device*/ false ); \
95
- \
96
- sycl::free (cplx_out, Q); \
88
+ cplx_out_acc[0 ] = experimental::math_func<T>(cplx_input); \
97
89
\
90
+ pass &= check_results (cplx_out_acc[0 ], std_out, /* is_device*/ false ); \
98
91
return pass; \
99
92
} \
100
93
};
@@ -121,23 +114,21 @@ TEST_MATH_OP_TYPE(imag)
121
114
std::complex<T> std_out = ref; \
122
115
if (!use_ref) \
123
116
std_out = std::math_func (std_in); \
124
- \
125
- auto *cplx_out = sycl::malloc_shared<experimental::complex<T>>(1 , Q); \
126
- \
117
+ sycl::buffer<experimental::complex<T>> cplx_out_buf{sycl::range{1 }}; \
127
118
/* Check cplx::complex output from device*/ \
128
- Q.single_task ([=]() { \
129
- cplx_out[0 ] = experimental::math_func<X>(std_in); \
130
- }).wait (); \
119
+ Q.submit ([&](sycl::handler &h) { \
120
+ sycl::accessor cplx_out{cplx_out_buf, h}; \
121
+ h.single_task ( \
122
+ [=]() { cplx_out[0 ] = experimental::math_func<X>(std_in); }); \
123
+ }); \
124
+ sycl::host_accessor cplx_out_acc{cplx_out_buf}; \
131
125
\
132
- pass &= check_results (cplx_out [0 ], std_out, /* is_device*/ true ); \
126
+ pass &= check_results (cplx_out_acc [0 ], std_out, /* is_device*/ true ); \
133
127
\
134
128
/* Check cplx::complex output from host*/ \
135
- cplx_out[0 ] = experimental::math_func<X>(std_in); \
136
- \
137
- pass &= check_results (cplx_out[0 ], std_out, /* is_device*/ false ); \
138
- \
139
- sycl::free (cplx_out, Q); \
129
+ cplx_out_acc[0 ] = experimental::math_func<X>(std_in); \
140
130
\
131
+ pass &= check_results (cplx_out_acc[0 ], std_out, /* is_device*/ false ); \
141
132
return pass; \
142
133
} \
143
134
};
@@ -161,23 +152,21 @@ TEST_MATH_OP_TYPE(proj)
161
152
T std_out = ref; \
162
153
if (!use_ref) \
163
154
std_out = std::math_func (std_in); \
164
- \
165
- auto *cplx_out = sycl::malloc_shared<T>(1 , Q); \
166
- \
155
+ sycl::buffer<T> cplx_out_buf{sycl::range{1 }}; \
167
156
/* Check cplx::complex output from device*/ \
168
- Q.single_task ([=]() { \
169
- cplx_out[0 ] = experimental::math_func<X>(init); \
170
- }).wait (); \
157
+ Q.submit ([&](sycl::handler &h) { \
158
+ sycl::accessor cplx_out{cplx_out_buf, h}; \
159
+ h.single_task ( \
160
+ [=]() { cplx_out[0 ] = experimental::math_func<X>(std_in); }); \
161
+ }); \
162
+ sycl::host_accessor cplx_out_acc{cplx_out_buf}; \
171
163
\
172
- pass &= check_results (cplx_out [0 ], std_out, /* is_device*/ true ); \
164
+ pass &= check_results (cplx_out_acc [0 ], std_out, /* is_device*/ true ); \
173
165
\
174
166
/* Check cplx::complex output from host*/ \
175
- cplx_out[0 ] = experimental::math_func<X>(init); \
176
- \
177
- pass &= check_results (cplx_out[0 ], std_out, /* is_device*/ false ); \
178
- \
179
- sycl::free (cplx_out, Q); \
167
+ cplx_out_acc[0 ] = experimental::math_func<X>(init); \
180
168
\
169
+ pass &= check_results (cplx_out_acc[0 ], std_out, /* is_device*/ false ); \
181
170
return pass; \
182
171
} \
183
172
};
@@ -197,26 +186,25 @@ template <typename T> struct test_polar {
197
186
bool use_ref = false) {
198
187
bool pass = true ;
199
188
200
- auto *cplx_out = sycl::malloc_shared<experimental::complex<T>>(1 , Q);
201
-
189
+ sycl::buffer<experimental::complex<T>> cplx_out_buf{sycl::range (1 )};
202
190
/* Get std::complex output*/
203
191
std::complex<T> std_out{ref.re , ref.im };
204
192
if (!use_ref)
205
193
std_out = std::polar (init.re , init.im );
206
194
207
195
/* Check cplx::complex output from device*/
208
- Q.single_task ([=]() {
209
- cplx_out[0 ] = experimental::polar<T>(init.re , init.im );
210
- }).wait ();
211
-
212
- pass &= check_results (cplx_out[0 ], std_out, /* is_device*/ true );
196
+ Q.submit ([&](sycl::handler &h) {
197
+ sycl::accessor cplx_out{cplx_out_buf, h};
198
+ h.single_task (
199
+ [=]() { cplx_out[0 ] = experimental::polar<T>(init.re , init.im ); });
200
+ });
201
+ sycl::host_accessor cplx_out_acc{cplx_out_buf};
202
+ pass &= check_results (cplx_out_acc[0 ], std_out, /* is_device*/ true );
213
203
214
204
/* Check cplx::complex output from host*/
215
- cplx_out[0 ] = experimental::polar<T>(init.re , init.im );
216
-
217
- pass &= check_results (cplx_out[0 ], std_out, /* is_device*/ false );
205
+ cplx_out_acc[0 ] = experimental::polar<T>(init.re , init.im );
218
206
219
- sycl::free (cplx_out, Q );
207
+ pass &= check_results (cplx_out_acc[ 0 ], std_out, /* is_device */ false );
220
208
221
209
return pass;
222
210
}
0 commit comments