Skip to content

Commit e25f97c

Browse files
[SYCL] Change cast for vector<cl_event> if SYCL2020_CONFORMANT_APIS macro is defined (#5498)
1 parent 5b62ee0 commit e25f97c

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

sycl/include/CL/sycl/detail/pi.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,15 @@ template <class To, class From> inline To cast(From value) {
420420
return (To)(value);
421421
}
422422

423+
// Cast for std::vector<cl_event>, according to the spec, make_event
424+
// should create one(?) event from a vector of cl_event
425+
template <class To> inline To cast(std::vector<cl_event> value) {
426+
RT::assertion(value.size() == 1,
427+
"Temporary workaround requires that the "
428+
"size of the input vector for make_event be equal to one.");
429+
return (To)(value[0]);
430+
}
431+
423432
// These conversions should use PI interop API.
424433
template <> inline pi::PiProgram cast(cl_program) {
425434
RT::assertion(false, "pi::cast -> use piextCreateProgramWithNativeHandle");
Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,30 @@
1-
// RUN: %clangxx -fsycl -fsyntax-only -Xclang -verify -DSYCL2020_CONFORMANT_APIS %s
2-
// expected-no-diagnostics
1+
// RUN: %clangxx -fsycl -DSYCL2020_CONFORMANT_APIS %s -o %t.out
2+
// RUN: %RUN_ON_HOST %t.out
33
//
44
//===----------------------------------------------------------------------===//
5-
// This test checks that sycl::get_native<sycl::backend::opencl>(event) return
6-
// std::vector<cl_event> when backend = opencl, according to:
7-
// SYCL™ 2020 Specification (revision 3)
5+
// This test verifies that sycl::get_native<backend::opencl> and
6+
// sycl::make_event<backend::opencl> work according to the SYCL™ 2020
7+
// Specification (revision 4)
88
//===----------------------------------------------------------------------===//
99

1010
#include <sycl/sycl.hpp>
1111

1212
int main() {
13-
#ifdef SYCL_BACKEND_OPENCL
1413
sycl::queue Queue;
1514
if (Queue.get_backend() == sycl::backend::opencl) {
1615
sycl::event event = Queue.submit([&](sycl::handler &cgh) {
1716
cgh.single_task<class event_kernel>([]() {});
1817
});
19-
std::vector<cl_event> interopEventVec =
20-
sycl::get_native<sycl::backend::opencl>(event);
18+
// Check that get_native function returns a vector
19+
std::vector<cl_event> ClEventVec = get_native<sycl::backend::opencl>(event);
20+
// Check that make_event is working properly with vector<cl_event> as a
21+
// param
22+
sycl::event SyclEvent = sycl::make_event<sycl::backend::opencl>(
23+
ClEventVec, Queue.get_context());
24+
std::vector<cl_event> ClEventVecFromMake =
25+
sycl::get_native<sycl::backend::opencl>(SyclEvent);
26+
if (ClEventVec[0] != ClEventVecFromMake[0])
27+
throw std::runtime_error("Cl events are not the same");
2128
}
22-
#endif
29+
return 0;
2330
}

0 commit comments

Comments
 (0)