Skip to content

Commit 7202173

Browse files
[SYCL] Native event for default-ctored sycl::event has to be in COMPLETE state (#7148)
Per SYCL 2020 for event(): > Constructs an event that is immediately ready. The event has no > dependencies and no associated commands. Waiting on this event will > return immediately and querying its status will return > info::event_command_status::complete. Modify piEventCreate to create an event in such a state. There is a more general problem that isn't addressed here: auto e = q.submit(... h.host_task(...) ..) This event would be a host one and we assert that no get_native could be called on it (see existing sycl::detail::getImplBackend). If we will ever want to support such scenario we'd need to implement some tracking of host/backed events in the SYCL RT and keep updating the latter whenever the host one changes the state. Alternatively, SYCL spec could be updated to prohibit such scenario or specify that such event has no native counterpart.
1 parent 93d747f commit 7202173

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

sycl/include/sycl/detail/pi.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,10 @@
5252
// 10.13 Added new PI_EXT_ONEAPI_QUEUE_DISCARD_EVENTS queue property.
5353
// 10.14 Add PI_EXT_INTEL_DEVICE_INFO_FREE_MEMORY as an extension for
5454
// piDeviceGetInfo.
55+
// 11.15 piEventCreate creates even in the signalled state now.
5556

56-
#define _PI_H_VERSION_MAJOR 10
57-
#define _PI_H_VERSION_MINOR 14
57+
#define _PI_H_VERSION_MAJOR 11
58+
#define _PI_H_VERSION_MINOR 15
5859

5960
#define _PI_STRING_HELPER(a) #a
6061
#define _PI_CONCAT(a, b) _PI_STRING_HELPER(a.b)
@@ -1397,6 +1398,11 @@ piextKernelGetNativeHandle(pi_kernel kernel, pi_native_handle *nativeHandle);
13971398
//
13981399
// Events
13991400
//
1401+
1402+
/// Create PI event object in a signalled/completed state.
1403+
///
1404+
/// \param context is the PI context of the event.
1405+
/// \param ret_event is the PI even created.
14001406
__SYCL_EXPORT pi_result piEventCreate(pi_context context, pi_event *ret_event);
14011407

14021408
__SYCL_EXPORT pi_result piEventGetInfo(pi_event event, pi_event_info param_name,

sycl/plugins/level_zero/pi_level_zero.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5632,7 +5632,10 @@ static pi_result EventCreate(pi_context Context, pi_queue Queue,
56325632
pi_result piEventCreate(pi_context Context, pi_event *RetEvent) {
56335633
pi_result Result = EventCreate(Context, nullptr, true, RetEvent);
56345634
(*RetEvent)->RefCountExternal++;
5635-
return Result;
5635+
if (Result != PI_SUCCESS)
5636+
return Result;
5637+
ZE_CALL(zeEventHostSignal, ((*RetEvent)->ZeEvent));
5638+
return PI_SUCCESS;
56365639
}
56375640

56385641
pi_result piEventGetInfo(pi_event Event, pi_event_info ParamName,

sycl/plugins/opencl/pi_opencl.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -973,8 +973,13 @@ pi_result piKernelGetSubGroupInfo(pi_kernel kernel, pi_device device,
973973
pi_result piEventCreate(pi_context context, pi_event *ret_event) {
974974

975975
pi_result ret_err = PI_ERROR_INVALID_OPERATION;
976-
*ret_event = cast<pi_event>(
977-
clCreateUserEvent(cast<cl_context>(context), cast<cl_int *>(&ret_err)));
976+
auto *cl_err = cast<cl_int *>(&ret_err);
977+
978+
cl_event e = clCreateUserEvent(cast<cl_context>(context), cl_err);
979+
*ret_event = cast<pi_event>(e);
980+
if (*cl_err != CL_SUCCESS)
981+
return ret_err;
982+
*cl_err = clSetUserEventStatus(e, CL_COMPLETE);
978983
return ret_err;
979984
}
980985

0 commit comments

Comments
 (0)