Skip to content
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

[SYCL] Native event for default-ctored sycl::event has to be in COMPLETE state #7148

Merged
merged 3 commits into from
Oct 25, 2022

Conversation

aelovikov-intel
Copy link
Contributor

@aelovikov-intel aelovikov-intel commented Oct 21, 2022

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.

…ETE state

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.

piEventCreate on the other hand creates an event that isn't completed.
As such an extra call to piEventSetStatus is needed making that API
not-deprecated.

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.
assert(!isDiscarded() && "Can't ask getNative of a discarded event!");
// Wouldn't be true if MHostEvent could be true.
assert(MState == HES_Complete && "Expected to have a completed event!");
Plugin.call<PiApiKind::piEventSetStatus>(MEvent, PI_EVENT_COMPLETE);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we instead change the "piEventCreate" to create a completed event?
BTW, in what circumstances is it called? How is such event used afterwards?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, in what circumstances is it called? How is such event used afterwards?

Not sure, I've only got a reduced example from the customer. I'd expect (without any grounds for those expectations) something like this is possible

  auto event = [&]() {
    if (needs_some_preprocessing) {
      return q.submit();
    } else {
      return event();
    }
  } ();
  
  q.parallel_for<MAIN>(..., event);

Can we instead change the "piEventCreate" to create a completed event?

From what I see in the codebase currently, that's possible although I don't see any substantial benefits.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean why do we even need to create a native event (call to piEventCreate) when we need to create a completed event, for which I assume there is no SYCL API to reset such event? We'd just mark the SYCL event as completed without going to native plugins.

Can we instead change the "piEventCreate" to create a completed event?

From what I see in the codebase currently, that's possible although I don't see any substantial benefits.

To continue deprecating and removing the piEventSetStatus

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean why do we even need to create a native event (call to piEventCreate) when we need to create a completed event, for which I assume there is no SYCL API to reset such event? We'd just mark the SYCL event as completed without going to native plugins.

Because SYCL spec says that such event

is constructed as though it was created from a default-constructed queue. Therefore, its backend is the same as the backend from the default device.

which means it is subject to interop API and its state can be modified using native backend APIs (which seems to be what the customer is doing).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, makes sense. So what about changing piEventCreate instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So what about changing piEventCreate instead?

I'm already working on that.

(void)ExecutionStatus;
die("piEventSetStatus: deprecated, to be removed");
if (ExecutionStatus == PI_EVENT_COMPLETE)
zeEventHostSignal(Event->ZeEvent);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has to properly process error codes.

@aelovikov-intel
Copy link
Contributor Author

@intel/llvm-reviewers-runtime , 2nd iteration of the PR evolved into plugin-side fix. Can I get an approval/merge?

Copy link
Contributor

@bso-intel bso-intel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@aelovikov-intel
Copy link
Contributor Author

@intel/llvm-gatekeepers , PR is ready.

@pvchupin pvchupin merged commit 7202173 into intel:sycl Oct 25, 2022
@aelovikov-intel aelovikov-intel deleted the native-default-event branch November 8, 2022 20:43
codeplay-sycl pushed a commit to codeplaysoftware/intel-llvm-mirror that referenced this pull request Nov 14, 2022
…ETE state (intel#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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants