Skip to content

[SYCL] Change cast for vector<cl_event> if SYCL2020_CONFORMANT_APIS macro is defined #5498

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions sycl/include/CL/sycl/detail/pi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,15 @@ template <class To, class From> inline To cast(From value) {
return (To)(value);
}

// Cast for std::vector<cl_event>, according to the spec, make_event
// should create one(?) event from a vector of cl_event
template <class To> inline To cast(std::vector<cl_event> value) {
RT::assertion(value.size() == 1,
"Temporary workaround requires that the "
"size of the input vector for make_event be equal to one.");
return (To)(value[0]);
}

// These conversions should use PI interop API.
template <> inline pi::PiProgram cast(cl_program) {
RT::assertion(false, "pi::cast -> use piextCreateProgramWithNativeHandle");
Expand Down
25 changes: 16 additions & 9 deletions sycl/test/regression/check_vector_of_opencl_event.cpp
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
// RUN: %clangxx -fsycl -fsyntax-only -Xclang -verify -DSYCL2020_CONFORMANT_APIS %s
// expected-no-diagnostics
// RUN: %clangxx -fsycl -DSYCL2020_CONFORMANT_APIS %s -o %t.out
// RUN: %RUN_ON_HOST %t.out
//
//===----------------------------------------------------------------------===//
// This test checks that sycl::get_native<sycl::backend::opencl>(event) return
// std::vector<cl_event> when backend = opencl, according to:
// SYCL™ 2020 Specification (revision 3)
// This test verifies that sycl::get_native<backend::opencl> and
// sycl::make_event<backend::opencl> work according to the SYCL™ 2020
// Specification (revision 4)
//===----------------------------------------------------------------------===//

#include <sycl/sycl.hpp>

int main() {
#ifdef SYCL_BACKEND_OPENCL
sycl::queue Queue;
if (Queue.get_backend() == sycl::backend::opencl) {
sycl::event event = Queue.submit([&](sycl::handler &cgh) {
cgh.single_task<class event_kernel>([]() {});
});
std::vector<cl_event> interopEventVec =
sycl::get_native<sycl::backend::opencl>(event);
// Check that get_native function returns a vector
std::vector<cl_event> ClEventVec = get_native<sycl::backend::opencl>(event);
// Check that make_event is working properly with vector<cl_event> as a
// param
sycl::event SyclEvent = sycl::make_event<sycl::backend::opencl>(
ClEventVec, Queue.get_context());
std::vector<cl_event> ClEventVecFromMake =
sycl::get_native<sycl::backend::opencl>(SyclEvent);
if (ClEventVec[0] != ClEventVecFromMake[0])
throw std::runtime_error("Cl events are not the same");
}
#endif
return 0;
}