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

Update spec to clarify event list contents #2195

Merged
merged 1 commit into from
Oct 14, 2024

Conversation

RossBrunton
Copy link
Contributor

@RossBrunton RossBrunton commented Oct 11, 2024

Updated the spec to state that "If phEventWaitList and phEvent
are not NULL, phEvent must not refer to an element of
the phEventWaitList array."

This is required for OpenCL, and probably makes sense for other
backends as well.

@RossBrunton RossBrunton requested review from a team as code owners October 11, 2024 15:29
@github-actions github-actions bot added loader Loader related feature/bug images UR images specification Changes or additions to the specification experimental Experimental feature additions/changes/specification command-buffer Command Buffer feature addition/changes/specification labels Oct 11, 2024
@pbalcer
Copy link
Contributor

pbalcer commented Oct 14, 2024

Event lists should not contain the output event. This updates all functions that have an event list input and event list output to explicitly state that.

But how would that even be possible? From the user's perspective, it doesn't matter what they set the output event to, since it's going to be overwritten, and the adapter should never read the output event pointer anyway (because it may be uninitialized, and reading uninitialized memory is UB). So even if a user sets the output event to something that exists in the WaitList, it should not matter.

From the adapter's perspective, it cannot modify the input WaitList. So it would not be able to insert the newly allocated output event handle into it.

Am I missing something?

Copy link
Contributor

@EwanC EwanC left a comment

Choose a reason for hiding this comment

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

My thoughts on this are the same as @pbalcer , the input ur_event_handle_t list cannot contain the output ur_event_handle_t list, because it has not been returned yet.

I'm not sure if the intent of this wording to forbid useful like this, however I think this is could be a valid usage idiom to create a linear dependency between commands (although it would leak events without being smarter.)

ur_event_handle_t myEvent;
for (unsigned i=0; i<N; i++) {
  if (i=0) {
     urEnqueueFoo(0, nullptr /*no wait event*/, &myEvent /*set as output*/);
  } else {
     urEnqueueFoo(1, &myEvent /*wait on event*/, &myEvent /*set as output*/);
  }
}

Edit: I see now you need to respect the OpenCL language for "If event_wait_list and event are not NULL, event must not refer to an element of the event_wait_list array." I'm not sure of another solution than propagating this restriction to UR

@pbalcer
Copy link
Contributor

pbalcer commented Oct 14, 2024

Edit: I see now you need to respect the OpenCL language for "If event_wait_list and event are not NULL, event must not refer to an element of the event_wait_list array." I'm not sure of another solution than propagating this restriction to UR

I'm not a native speaker, so maybe that's on me, but I understand this completely differently than "If phEventWaitList is specified, it must not contain phEvent.".
The OpenCL language states clearly that the pointer to the output event must not be a pointer into the wait list array. The way I understood this PR is that the event wait list can't contain the pointer to the output event.
At the very least the UR language is confusing. 👍 to just copying the OpenCL docs.

Updated the spec to state that "If phEventWaitList and phEvent
are not NULL, phEvent must not refer to an element of
the phEventWaitList array."

This is required for OpenCL, and probably makes sense for other
backends as well.
@RossBrunton
Copy link
Contributor Author

@pbalcer I've updated the text to just copy the OpenCL wording, hopefully it's clearer now.

@EwanC The example you've posted is actually what I was trying to stop. I tried doing that pattern elsewhere, and it causes the OpenCL driver on CI to hang.

@pbalcer
Copy link
Contributor

pbalcer commented Oct 14, 2024

@EwanC The example you've posted is actually what I was trying to stop. I tried doing that pattern elsewhere, and it causes the OpenCL driver on CI to hang.

Maybe we should add a validation layer feature to detect this?

@RossBrunton
Copy link
Contributor Author

#2196 @pbalcer @EwanC created a ticket for validation here.

@RossBrunton
Copy link
Contributor Author

Merging without LLVM change - this only touches the spec and comments.

@RossBrunton RossBrunton merged commit 090d4fb into oneapi-src:main Oct 14, 2024
76 of 78 checks passed
@RossBrunton RossBrunton deleted the ross/specevent branch November 6, 2024 11:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
command-buffer Command Buffer feature addition/changes/specification experimental Experimental feature additions/changes/specification images UR images loader Loader related feature/bug specification Changes or additions to the specification
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants