Skip to content
This repository was archived by the owner on Mar 28, 2023. It is now read-only.

Commit 1f44112

Browse files
[SYCL] Use float instead of double in some SpecConstants tests (#1247)
1 parent 2adfa38 commit 1f44112

File tree

2 files changed

+50
-50
lines changed

2 files changed

+50
-50
lines changed

SYCL/SpecConstants/2020/handler-api.cpp

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
constexpr sycl::specialization_id<int> int_id;
2525
constexpr sycl::specialization_id<int> int_id2(2);
26-
constexpr sycl::specialization_id<double> double_id(3.14);
26+
constexpr sycl::specialization_id<float> float_id(3.14);
2727
constexpr sycl::specialization_id<custom_type> custom_type_id;
2828

2929
class TestDefaultValuesKernel;
@@ -71,19 +71,19 @@ int main() {
7171
bool test_default_values(sycl::queue q) {
7272
sycl::buffer<int> int_buffer(1);
7373
sycl::buffer<int> int_buffer2(1);
74-
sycl::buffer<double> double_buffer(1);
74+
sycl::buffer<float> float_buffer(1);
7575
sycl::buffer<custom_type> custom_type_buffer(1);
7676

7777
q.submit([&](sycl::handler &cgh) {
7878
auto int_acc = int_buffer.get_access<sycl::access::mode::write>(cgh);
7979
auto int_acc2 = int_buffer2.get_access<sycl::access::mode::write>(cgh);
80-
auto double_acc = double_buffer.get_access<sycl::access::mode::write>(cgh);
80+
auto float_acc = float_buffer.get_access<sycl::access::mode::write>(cgh);
8181
auto custom_type_acc =
8282
custom_type_buffer.get_access<sycl::access::mode::write>(cgh);
8383
cgh.single_task<TestDefaultValuesKernel>([=](sycl::kernel_handler kh) {
8484
int_acc[0] = kh.get_specialization_constant<int_id>();
8585
int_acc2[0] = kh.get_specialization_constant<int_id2>();
86-
double_acc[0] = kh.get_specialization_constant<double_id>();
86+
float_acc[0] = kh.get_specialization_constant<float_id>();
8787
custom_type_acc[0] = kh.get_specialization_constant<custom_type_id>();
8888
});
8989
});
@@ -98,8 +98,8 @@ bool test_default_values(sycl::queue q) {
9898
if (!check_value(2, int_acc2[0], "integer specialization constant"))
9999
return false;
100100

101-
auto double_acc = double_buffer.get_access<sycl::access::mode::read>();
102-
if (!check_value(3.14, double_acc[0], "double specialization constant"))
101+
auto float_acc = float_buffer.get_access<sycl::access::mode::read>();
102+
if (!check_value(3.14f, float_acc[0], "float specialization constant"))
103103
return false;
104104

105105
auto custom_type_acc =
@@ -120,8 +120,8 @@ bool test_set_and_get_on_host(sycl::queue q) {
120120
"integer specializaiton constant before setting any value"))
121121
++errors;
122122

123-
if (!check_value(3.14, cgh.get_specialization_constant<double_id>(),
124-
"double specializaiton constant before setting any value"))
123+
if (!check_value(3.14f, cgh.get_specialization_constant<float_id>(),
124+
"float specializaiton constant before setting any value"))
125125
++errors;
126126

127127
custom_type custom_type_ref;
@@ -131,20 +131,20 @@ bool test_set_and_get_on_host(sycl::queue q) {
131131
++errors;
132132

133133
int new_int_value = 8;
134-
double new_double_value = 3.0;
135-
custom_type new_custom_type_value('b', 1.0, 12);
134+
float new_float_value = 3.0f;
135+
custom_type new_custom_type_value('b', 1.0f, 12);
136136
cgh.set_specialization_constant<int_id>(new_int_value);
137-
cgh.set_specialization_constant<double_id>(new_double_value);
137+
cgh.set_specialization_constant<float_id>(new_float_value);
138138
cgh.set_specialization_constant<custom_type_id>(new_custom_type_value);
139139

140140
if (!check_value(
141141
new_int_value, cgh.get_specialization_constant<int_id>(),
142142
"integer specializaiton constant after setting a new value"))
143143
++errors;
144144

145-
if (!check_value(
146-
new_double_value, cgh.get_specialization_constant<double_id>(),
147-
"double specializaiton constant after setting a new value"))
145+
if (!check_value(new_float_value,
146+
cgh.get_specialization_constant<float_id>(),
147+
"float specializaiton constant after setting a new value"))
148148
++errors;
149149

150150
if (!check_value(
@@ -162,30 +162,30 @@ bool test_set_and_get_on_host(sycl::queue q) {
162162
bool test_set_and_get_on_device(sycl::queue q) {
163163
sycl::buffer<int> int_buffer(1);
164164
sycl::buffer<int> int_buffer2(1);
165-
sycl::buffer<double> double_buffer(1);
165+
sycl::buffer<float> float_buffer(1);
166166
sycl::buffer<custom_type> custom_type_buffer(1);
167167

168168
int new_int_value = 8;
169169
int new_int_value2 = 0;
170-
double new_double_value = 3.0;
171-
custom_type new_custom_type_value('b', 1.0, 12);
170+
float new_float_value = 3.0f;
171+
custom_type new_custom_type_value('b', 1.0f, 12);
172172

173173
q.submit([&](sycl::handler &cgh) {
174174
auto int_acc = int_buffer.get_access<sycl::access::mode::write>(cgh);
175175
auto int_acc2 = int_buffer2.get_access<sycl::access::mode::write>(cgh);
176-
auto double_acc = double_buffer.get_access<sycl::access::mode::write>(cgh);
176+
auto float_acc = float_buffer.get_access<sycl::access::mode::write>(cgh);
177177
auto custom_type_acc =
178178
custom_type_buffer.get_access<sycl::access::mode::write>(cgh);
179179

180180
cgh.set_specialization_constant<int_id>(new_int_value);
181181
cgh.set_specialization_constant<int_id2>(new_int_value2);
182-
cgh.set_specialization_constant<double_id>(new_double_value);
182+
cgh.set_specialization_constant<float_id>(new_float_value);
183183
cgh.set_specialization_constant<custom_type_id>(new_custom_type_value);
184184

185185
cgh.single_task<TestSetAndGetOnDevice>([=](sycl::kernel_handler kh) {
186186
int_acc[0] = kh.get_specialization_constant<int_id>();
187187
int_acc2[0] = kh.get_specialization_constant<int_id2>();
188-
double_acc[0] = kh.get_specialization_constant<double_id>();
188+
float_acc[0] = kh.get_specialization_constant<float_id>();
189189
custom_type_acc[0] = kh.get_specialization_constant<custom_type_id>();
190190
});
191191
});
@@ -200,9 +200,9 @@ bool test_set_and_get_on_device(sycl::queue q) {
200200
"integer specialization constant"))
201201
return false;
202202

203-
auto double_acc = double_buffer.get_access<sycl::access::mode::read>();
204-
if (!check_value(new_double_value, double_acc[0],
205-
"double specialization constant"))
203+
auto float_acc = float_buffer.get_access<sycl::access::mode::read>();
204+
if (!check_value(new_float_value, float_acc[0],
205+
"float specialization constant"))
206206
return false;
207207

208208
auto custom_type_acc =

SYCL/SpecConstants/2020/kernel-bundle-api.cpp

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include "common.hpp"
2222

2323
constexpr sycl::specialization_id<int> int_id;
24-
constexpr sycl::specialization_id<double> double_id(3.14);
24+
constexpr sycl::specialization_id<float> float_id(3.14f);
2525
constexpr sycl::specialization_id<custom_type> custom_type_id;
2626

2727
class TestDefaultValuesKernel;
@@ -76,7 +76,7 @@ bool test_default_values(sycl::queue q) {
7676
}
7777

7878
sycl::buffer<int> int_buffer(1);
79-
sycl::buffer<double> double_buffer(1);
79+
sycl::buffer<float> float_buffer(1);
8080
sycl::buffer<custom_type> custom_type_buffer(1);
8181

8282
auto input_bundle =
@@ -86,12 +86,12 @@ bool test_default_values(sycl::queue q) {
8686
q.submit([&](sycl::handler &cgh) {
8787
cgh.use_kernel_bundle(exec_bundle);
8888
auto int_acc = int_buffer.get_access<sycl::access::mode::write>(cgh);
89-
auto double_acc = double_buffer.get_access<sycl::access::mode::write>(cgh);
89+
auto float_acc = float_buffer.get_access<sycl::access::mode::write>(cgh);
9090
auto custom_type_acc =
9191
custom_type_buffer.get_access<sycl::access::mode::write>(cgh);
9292
cgh.single_task<TestDefaultValuesKernel>([=](sycl::kernel_handler kh) {
9393
int_acc[0] = kh.get_specialization_constant<int_id>();
94-
double_acc[0] = kh.get_specialization_constant<double_id>();
94+
float_acc[0] = kh.get_specialization_constant<float_id>();
9595
custom_type_acc[0] = kh.get_specialization_constant<custom_type_id>();
9696
});
9797
});
@@ -102,8 +102,8 @@ bool test_default_values(sycl::queue q) {
102102
"integer specialization constant (defined without default value)"))
103103
return false;
104104

105-
auto double_acc = double_buffer.get_access<sycl::access::mode::read>();
106-
if (!check_value(3.14, double_acc[0], "double specialization constant"))
105+
auto float_acc = float_buffer.get_access<sycl::access::mode::read>();
106+
if (!check_value(3.14f, float_acc[0], "float specialization constant"))
107107
return false;
108108

109109
auto custom_type_acc =
@@ -145,9 +145,9 @@ bool test_set_and_get_on_host(sycl::queue q) {
145145
"integer specializaiton constant before setting any value"))
146146
++errors;
147147

148-
if (!check_value(3.14,
149-
input_bundle.get_specialization_constant<double_id>(),
150-
"double specializaiton constant before setting any value"))
148+
if (!check_value(3.14f,
149+
input_bundle.get_specialization_constant<float_id>(),
150+
"float specializaiton constant before setting any value"))
151151
++errors;
152152

153153
custom_type custom_type_ref;
@@ -159,11 +159,11 @@ bool test_set_and_get_on_host(sycl::queue q) {
159159

160160
// Update values
161161
int new_int_value = 42;
162-
double new_double_value = 3.0;
163-
custom_type new_custom_type_value('b', 1.0, 12);
162+
float new_float_value = 3.0f;
163+
custom_type new_custom_type_value('b', 1.0f, 12);
164164

165165
input_bundle.set_specialization_constant<int_id>(new_int_value);
166-
input_bundle.set_specialization_constant<double_id>(new_double_value);
166+
input_bundle.set_specialization_constant<float_id>(new_float_value);
167167
input_bundle.set_specialization_constant<custom_type_id>(
168168
new_custom_type_value);
169169

@@ -173,9 +173,9 @@ bool test_set_and_get_on_host(sycl::queue q) {
173173
"integer specializaiton constant after setting a new value"))
174174
++errors;
175175

176-
if (!check_value(new_double_value,
177-
input_bundle.get_specialization_constant<double_id>(),
178-
"double specializaiton constant after setting a value"))
176+
if (!check_value(new_float_value,
177+
input_bundle.get_specialization_constant<float_id>(),
178+
"float specializaiton constant after setting a value"))
179179
++errors;
180180

181181
if (!check_value(
@@ -193,9 +193,9 @@ bool test_set_and_get_on_host(sycl::queue q) {
193193
"integer specializaiton constant after build"))
194194
++errors;
195195

196-
if (!check_value(new_double_value,
197-
exec_bundle.get_specialization_constant<double_id>(),
198-
"double specializaiton constant after build"))
196+
if (!check_value(new_float_value,
197+
exec_bundle.get_specialization_constant<float_id>(),
198+
"float specializaiton constant after build"))
199199
++errors;
200200

201201
if (!check_value(new_custom_type_value,
@@ -210,31 +210,31 @@ bool test_set_and_get_on_host(sycl::queue q) {
210210

211211
bool test_set_and_get_on_device(sycl::queue q) {
212212
sycl::buffer<int> int_buffer(1);
213-
sycl::buffer<double> double_buffer(1);
213+
sycl::buffer<float> float_buffer(1);
214214
sycl::buffer<custom_type> custom_type_buffer(1);
215215

216216
int new_int_value = 42;
217-
double new_double_value = 3.0;
218-
custom_type new_custom_type_value('b', 1.0, 12);
217+
float new_float_value = 3.0f;
218+
custom_type new_custom_type_value('b', 1.0f, 12);
219219

220220
auto input_bundle =
221221
sycl::get_kernel_bundle<sycl::bundle_state::input>(q.get_context());
222222
input_bundle.set_specialization_constant<int_id>(new_int_value);
223-
input_bundle.set_specialization_constant<double_id>(new_double_value);
223+
input_bundle.set_specialization_constant<float_id>(new_float_value);
224224
input_bundle.set_specialization_constant<custom_type_id>(
225225
new_custom_type_value);
226226
auto exec_bundle = sycl::build(input_bundle);
227227

228228
q.submit([&](sycl::handler &cgh) {
229229
cgh.use_kernel_bundle(exec_bundle);
230230
auto int_acc = int_buffer.get_access<sycl::access::mode::write>(cgh);
231-
auto double_acc = double_buffer.get_access<sycl::access::mode::write>(cgh);
231+
auto float_acc = float_buffer.get_access<sycl::access::mode::write>(cgh);
232232
auto custom_type_acc =
233233
custom_type_buffer.get_access<sycl::access::mode::write>(cgh);
234234

235235
cgh.single_task<TestSetAndGetOnDevice>([=](sycl::kernel_handler kh) {
236236
int_acc[0] = kh.get_specialization_constant<int_id>();
237-
double_acc[0] = kh.get_specialization_constant<double_id>();
237+
float_acc[0] = kh.get_specialization_constant<float_id>();
238238
custom_type_acc[0] = kh.get_specialization_constant<custom_type_id>();
239239
});
240240
});
@@ -244,9 +244,9 @@ bool test_set_and_get_on_device(sycl::queue q) {
244244
"integer specialization constant"))
245245
return false;
246246

247-
auto double_acc = double_buffer.get_access<sycl::access::mode::read>();
248-
if (!check_value(new_double_value, double_acc[0],
249-
"double specialization constant"))
247+
auto float_acc = float_buffer.get_access<sycl::access::mode::read>();
248+
if (!check_value(new_float_value, float_acc[0],
249+
"float specialization constant"))
250250
return false;
251251

252252
auto custom_type_acc =

0 commit comments

Comments
 (0)