Skip to content

Commit 7089b6a

Browse files
committed
[SYCL][LIT] Enable test for non-OpenCL
Rewrite parallel_for_range.cpp test to work with non-OpenCL PI backends that behave like OpenCL 1.2. Level0 testing times out on Windows, mark `windows` as unsupported. Signed-off-by: Bjoern Knafla <[email protected]>
1 parent f7dd22c commit 7089b6a

File tree

1 file changed

+91
-82
lines changed

1 file changed

+91
-82
lines changed

sycl/test/basic_tests/parallel_for_range.cpp

Lines changed: 91 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
// XFAIL: cuda || level_zero
2-
// CUDA exposes broken hierarchical parallelism.
1+
// XFAIL: level_zero
2+
// UNSUPPORTED: windows
3+
// Level0 testing times out on Windows.
34

45
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
56
// RUN: %CPU_RUN_PLACEHOLDER %t.out
@@ -29,106 +30,111 @@ int main() {
2930
string_class DeviceVendorName = D.get_info<info::device::vendor>();
3031
auto DeviceType = D.get_info<info::device::device_type>();
3132

32-
// parallel_for, (16, 16, 16) global, (8, 8, 8) local, reqd_wg_size(4, 4, 4)
33-
// -> fail
34-
try {
35-
Q.submit([&](handler &CGH) {
36-
CGH.parallel_for<class ReqdWGSizeNegativeA>(
37-
nd_range<3>(range<3>(16, 16, 16), range<3>(8, 8, 8)),
38-
[=](nd_item<3>) { reqd_wg_size_helper(); });
39-
});
40-
Q.wait_and_throw();
41-
std::cerr << "Test case ReqdWGSizeNegativeA failed: no exception has been "
42-
"thrown\n";
43-
return 1; // We shouldn't be here, exception is expected
44-
} catch (nd_range_error &E) {
45-
if (string_class(E.what()).find(
46-
"Specified local size doesn't match the required work-group size "
47-
"specified in the program source") == string_class::npos) {
48-
std::cerr
49-
<< "Test case ReqdWGSizeNegativeA failed: unexpected exception: "
50-
<< E.what() << std::endl;
51-
return 1;
52-
}
53-
} catch (runtime_error &E) {
54-
std::cerr << "Test case ReqdWGSizeNegativeA failed: unexpected exception: "
55-
<< E.what() << std::endl;
56-
return 1;
57-
} catch (...) {
58-
std::cerr << "Test case ReqdWGSizeNegativeA failed: something unexpected "
59-
"has been caught"
60-
<< std::endl;
61-
return 1;
62-
}
63-
6433
string_class OCLVersionStr = D.get_info<info::device::version>();
65-
assert(OCLVersionStr.size() >= 10 &&
34+
const bool OCLBackend = (OCLVersionStr.find("OpenCL") != string_class::npos);
35+
assert((!OCLBackend || (OCLVersionStr.size() >= 10)) &&
6636
"Unexpected device version string"); // strlen("OpenCL X.Y")
6737
const char *OCLVersion = &OCLVersionStr[7]; // strlen("OpenCL ")
68-
if (OCLVersion[0] == '1' || (OCLVersion[0] == '2' && OCLVersion[2] == '0')) {
69-
// parallel_for, (16, 16, 16) global, null local, reqd_wg_size(4, 4, 4) //
38+
39+
// reqd_work_group_size is OpenCL specific.
40+
if (OCLBackend) {
41+
if (OCLVersion[0] == '1' || (OCLVersion[0] == '2' && OCLVersion[2] == '0')) {
42+
// parallel_for, (16, 16, 16) global, (8, 8, 8) local, reqd_wg_size(4, 4, 4)
7043
// -> fail
7144
try {
7245
Q.submit([&](handler &CGH) {
73-
CGH.parallel_for<class ReqdWGSizeNegativeB>(
74-
range<3>(16, 16, 16), [=](item<3>) { reqd_wg_size_helper(); });
46+
CGH.parallel_for<class ReqdWGSizeNegativeA>(
47+
nd_range<3>(range<3>(16, 16, 16), range<3>(8, 8, 8)),
48+
[=](nd_item<3>) { reqd_wg_size_helper(); });
7549
});
7650
Q.wait_and_throw();
77-
std::cerr
78-
<< "Test case ReqdWGSizeNegativeB failed: no exception has been "
79-
"thrown\n";
51+
std::cerr << "Test case ReqdWGSizeNegativeA failed: no exception has been "
52+
"thrown\n";
8053
return 1; // We shouldn't be here, exception is expected
8154
} catch (nd_range_error &E) {
8255
if (string_class(E.what()).find(
83-
"OpenCL 1.x and 2.0 requires to pass local size argument even if "
84-
"required work-group size was specified in the program source") ==
85-
string_class::npos) {
56+
"Specified local size doesn't match the required work-group size "
57+
"specified in the program source") == string_class::npos) {
8658
std::cerr
87-
<< "Test case ReqdWGSizeNegativeB failed: unexpected exception: "
59+
<< "Test case ReqdWGSizeNegativeA failed: unexpected exception: "
8860
<< E.what() << std::endl;
8961
return 1;
9062
}
9163
} catch (runtime_error &E) {
92-
std::cerr
93-
<< "Test case ReqdWGSizeNegativeB failed: unexpected exception: "
94-
<< E.what() << std::endl;
64+
std::cerr << "Test case ReqdWGSizeNegativeA failed: unexpected exception: "
65+
<< E.what() << std::endl;
9566
return 1;
9667
} catch (...) {
97-
std::cerr << "Test case ReqdWGSizeNegativeB failed: something unexpected "
68+
std::cerr << "Test case ReqdWGSizeNegativeA failed: something unexpected "
9869
"has been caught"
9970
<< std::endl;
10071
return 1;
10172
}
102-
}
10373

104-
// Positive test-cases that should pass on any underlying OpenCL runtime
105-
106-
// parallel_for, (8, 8, 8) global, (4, 4, 4) local, reqd_wg_size(4, 4, 4) ->
107-
// pass
108-
try {
109-
Q.submit([&](handler &CGH) {
110-
CGH.parallel_for<class ReqdWGSizePositiveA>(
111-
nd_range<3>(range<3>(8, 8, 8), range<3>(4, 4, 4)),
112-
[=](nd_item<3>) { reqd_wg_size_helper(); });
113-
});
114-
Q.wait_and_throw();
115-
} catch (nd_range_error &E) {
116-
std::cerr << "Test case ReqdWGSizePositiveA failed: unexpected exception: "
117-
<< E.what() << std::endl;
118-
return 1;
119-
} catch (runtime_error &E) {
120-
std::cerr << "Test case ReqdWGSizePositiveA failed: unexpected exception: "
74+
// parallel_for, (16, 16, 16) global, null local, reqd_wg_size(4, 4, 4) //
75+
// -> fail
76+
try {
77+
Q.submit([&](handler &CGH) {
78+
CGH.parallel_for<class ReqdWGSizeNegativeB>(
79+
range<3>(16, 16, 16), [=](item<3>) { reqd_wg_size_helper(); });
80+
});
81+
Q.wait_and_throw();
82+
std::cerr
83+
<< "Test case ReqdWGSizeNegativeB failed: no exception has been "
84+
"thrown\n";
85+
return 1; // We shouldn't be here, exception is expected
86+
} catch (nd_range_error &E) {
87+
if (string_class(E.what()).find(
88+
"OpenCL 1.x and 2.0 requires to pass local size argument even if "
89+
"required work-group size was specified in the program source") ==
90+
string_class::npos) {
91+
std::cerr
92+
<< "Test case ReqdWGSizeNegativeB failed: unexpected exception: "
12193
<< E.what() << std::endl;
122-
return 1;
123-
} catch (...) {
124-
std::cerr << "Test case ReqdWGSizePositiveA failed: something unexpected "
125-
"has been caught"
126-
<< std::endl;
127-
return 1;
128-
}
94+
return 1;
95+
}
96+
} catch (runtime_error &E) {
97+
std::cerr
98+
<< "Test case ReqdWGSizeNegativeB failed: unexpected exception: "
99+
<< E.what() << std::endl;
100+
return 1;
101+
} catch (...) {
102+
std::cerr << "Test case ReqdWGSizeNegativeB failed: something unexpected "
103+
"has been caught"
104+
<< std::endl;
105+
return 1;
106+
}
107+
}
129108

130-
if (OCLVersion[0] == '1') {
131-
// OpenCL 1.x
109+
// Positive test-cases that should pass on any underlying OpenCL runtime
110+
111+
// parallel_for, (8, 8, 8) global, (4, 4, 4) local, reqd_wg_size(4, 4, 4) ->
112+
// pass
113+
try {
114+
Q.submit([&](handler &CGH) {
115+
CGH.parallel_for<class ReqdWGSizePositiveA>(
116+
nd_range<3>(range<3>(8, 8, 8), range<3>(4, 4, 4)),
117+
[=](nd_item<3>) { reqd_wg_size_helper(); });
118+
});
119+
Q.wait_and_throw();
120+
} catch (nd_range_error &E) {
121+
std::cerr << "Test case ReqdWGSizePositiveA failed: unexpected exception: "
122+
<< E.what() << std::endl;
123+
return 1;
124+
} catch (runtime_error &E) {
125+
std::cerr << "Test case ReqdWGSizePositiveA failed: unexpected exception: "
126+
<< E.what() << std::endl;
127+
return 1;
128+
} catch (...) {
129+
std::cerr << "Test case ReqdWGSizePositiveA failed: something unexpected "
130+
"has been caught"
131+
<< std::endl;
132+
return 1;
133+
}
134+
} // if (OCLBackend)
135+
136+
if (!OCLBackend || (OCLVersion[0] == '1')) {
137+
// OpenCL 1.x or non-OpenCL backends which behave like OpenCl 1.2 in SYCL.
132138

133139
// CL_INVALID_WORK_GROUP_SIZE if local_work_size is specified and
134140
// number of workitems specified by global_work_size is not evenly
@@ -227,7 +233,8 @@ int main() {
227233
return 1; // We shouldn't be here, exception is expected
228234
}
229235
} catch (nd_range_error &E) {
230-
if (string_class(E.what()).find("Local workgroup size cannot be greater than global range in any dimension") == string_class::npos) {
236+
if ((string_class(E.what()).find("Local workgroup size cannot be greater than global range in any dimension") == string_class::npos) &&
237+
(string_class(E.what()).find("Non-uniform work-groups are not supported by the target device") == string_class::npos)) {
231238
std::cerr
232239
<< "Test case OpenCL1XNegativeA2 failed: unexpected exception: "
233240
<< E.what() << std::endl;
@@ -264,7 +271,8 @@ int main() {
264271
return 1; // We shouldn't be here, exception is expected
265272
}
266273
} catch (nd_range_error &E) {
267-
if (string_class(E.what()).find("Local workgroup size cannot be greater than global range in any dimension") == string_class::npos) {
274+
if ((string_class(E.what()).find("Local workgroup size cannot be greater than global range in any dimension") == string_class::npos) &&
275+
(string_class(E.what()).find("Non-uniform work-groups are not supported by the target device") == string_class::npos)) {
268276
std::cerr
269277
<< "Test case OpenCL1XNegativeB2 failed: unexpected exception: "
270278
<< E.what() << std::endl;
@@ -299,9 +307,10 @@ int main() {
299307
"thrown\n";
300308
return 1; // We shouldn't be here, exception is expected
301309
} catch (nd_range_error &E) {
302-
if (string_class(E.what()).find(
310+
if ((string_class(E.what()).find(
303311
"Total number of work-items in a work-group cannot exceed " +
304-
std::to_string(MaxDeviceWGSize)) == string_class::npos) {
312+
std::to_string(MaxDeviceWGSize)) == string_class::npos) &&
313+
(string_class(E.what()).find("Non-uniform work-groups are not supported by the target device") == string_class::npos)) {
305314
std::cerr
306315
<< "Test case OpenCL1XNegativeC failed: unexpected exception: "
307316
<< E.what() << std::endl;
@@ -317,7 +326,7 @@ int main() {
317326
<< std::endl;
318327
return 1;
319328
}
320-
} else if (OCLVersion[0] == '2') {
329+
} else if (OCLBackend && (OCLVersion[0] == '2')) {
321330
// OpenCL 2.x
322331

323332
// OpenCL 2.x:

0 commit comments

Comments
 (0)