Skip to content

Commit

Permalink
[SYCL] Native event for default-ctored sycl::event has to be in COMPL…
Browse files Browse the repository at this point in the history
…ETE 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.
  • Loading branch information
aelovikov-intel authored Oct 25, 2022
1 parent 93d747f commit 7202173
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
10 changes: 8 additions & 2 deletions sycl/include/sycl/detail/pi.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@
// 10.13 Added new PI_EXT_ONEAPI_QUEUE_DISCARD_EVENTS queue property.
// 10.14 Add PI_EXT_INTEL_DEVICE_INFO_FREE_MEMORY as an extension for
// piDeviceGetInfo.
// 11.15 piEventCreate creates even in the signalled state now.

#define _PI_H_VERSION_MAJOR 10
#define _PI_H_VERSION_MINOR 14
#define _PI_H_VERSION_MAJOR 11
#define _PI_H_VERSION_MINOR 15

#define _PI_STRING_HELPER(a) #a
#define _PI_CONCAT(a, b) _PI_STRING_HELPER(a.b)
Expand Down Expand Up @@ -1397,6 +1398,11 @@ piextKernelGetNativeHandle(pi_kernel kernel, pi_native_handle *nativeHandle);
//
// Events
//

/// Create PI event object in a signalled/completed state.
///
/// \param context is the PI context of the event.
/// \param ret_event is the PI even created.
__SYCL_EXPORT pi_result piEventCreate(pi_context context, pi_event *ret_event);

__SYCL_EXPORT pi_result piEventGetInfo(pi_event event, pi_event_info param_name,
Expand Down
5 changes: 4 additions & 1 deletion sycl/plugins/level_zero/pi_level_zero.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5632,7 +5632,10 @@ static pi_result EventCreate(pi_context Context, pi_queue Queue,
pi_result piEventCreate(pi_context Context, pi_event *RetEvent) {
pi_result Result = EventCreate(Context, nullptr, true, RetEvent);
(*RetEvent)->RefCountExternal++;
return Result;
if (Result != PI_SUCCESS)
return Result;
ZE_CALL(zeEventHostSignal, ((*RetEvent)->ZeEvent));
return PI_SUCCESS;
}

pi_result piEventGetInfo(pi_event Event, pi_event_info ParamName,
Expand Down
9 changes: 7 additions & 2 deletions sycl/plugins/opencl/pi_opencl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -973,8 +973,13 @@ pi_result piKernelGetSubGroupInfo(pi_kernel kernel, pi_device device,
pi_result piEventCreate(pi_context context, pi_event *ret_event) {

pi_result ret_err = PI_ERROR_INVALID_OPERATION;
*ret_event = cast<pi_event>(
clCreateUserEvent(cast<cl_context>(context), cast<cl_int *>(&ret_err)));
auto *cl_err = cast<cl_int *>(&ret_err);

cl_event e = clCreateUserEvent(cast<cl_context>(context), cl_err);
*ret_event = cast<pi_event>(e);
if (*cl_err != CL_SUCCESS)
return ret_err;
*cl_err = clSetUserEventStatus(e, CL_COMPLETE);
return ret_err;
}

Expand Down

0 comments on commit 7202173

Please sign in to comment.