Skip to content

[SYCL] Implement event_profiling::command_submit for level-zero #7403

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

Closed
wants to merge 8 commits into from

Conversation

raaiq1
Copy link
Contributor

@raaiq1 raaiq1 commented Nov 15, 2022

This feature implements calculating and returning the submission time of a command group associated with an event in level-zero. The submission time calculated by querying the device's wall-clock time right before a commandlist is submitted for execution.

Signed-off-by: Rauf, Rana [email protected]

@raaiq1 raaiq1 requested review from a team as code owners November 15, 2022 18:50
Signed-off-by: Rauf, Rana <[email protected]>
Signed-off-by: Rauf, Rana <[email protected]>
Signed-off-by: Rauf, Rana <[email protected]>
@romanovvlad
Copy link
Contributor

romanovvlad commented Nov 16, 2022

Not sure the approach is correct.
The specification says:

info::event_command_status::submitted
Indicates that the command has been submitted to the SYCL queue but has not yet started running on the device.

So, it sounds like the submitted timestamp should be taken when a command enqueued to the SYCL queue rather than to L0 queue, they could be different timestamps. For example:

auto HostAcc = Buf.get_access();
Q.submit(/*a kernel writing to Buf*/); // Command1

The Command1 is not enqueued to L0 queue until HostAcc is destroyed while submission to the SYCL queue happens before.
Also we need a solution for host and interop tasks, and I would expect that their timestamp are aligned with kernel tasks for a given SYCL queue.

What about having something like:

In device c'tor:

InitTimeDiff = piGetDeviceTime(PIDevice) - get_host_time();

In the queue::submit:

ResEvent->SubmitTime = get_host_time();

In the event::get_info:

case command_submit:
  return SubmitTime;
case command_start:
  return Device->InitTimeDiff + piGetEventInfo(PIEvent, START_TIME);
case command_end:
  return Device->InitTimeDiff + piGetEventInfo(PIEvent, END_TIME);

Signed-off-by: Rauf, Rana <[email protected]>
Signed-off-by: Rauf, Rana <[email protected]>
Signed-off-by: Rauf, Rana <[email protected]>
@smaslov-intel
Copy link
Contributor

This feature implements calculating and returning the submission time of a command group associated with an event in level-zero. The submission time calculated by querying the device's wall-clock time right before a commandlist is submitted for execution.

I don't fully understand what it is trying to do and why, please elaborate. How are currently returned times not OK?

@raaiq1
Copy link
Contributor Author

raaiq1 commented Nov 21, 2022

I don't fully understand what it is trying to do and why, please elaborate. How are currently returned times not OK?

Currently, level-zero constantly returns 0 when querying for command submission time. Which is very misleading

@smaslov-intel
Copy link
Contributor

I don't fully understand what it is trying to do and why, please elaborate. How are currently returned times not OK?

Currently, level-zero constantly returns 0 when querying for command submission time. Which is very misleading

I am rather asking about the code in piDeviceTime::get
What it does and why? And when is that OK to call?

@raaiq1
Copy link
Contributor Author

raaiq1 commented Nov 21, 2022

Ohh, sorry I misunderstood. All piDeviceTime::get does is get the current device time when called.

And when is that OK to call?

I'm not sure if I understand correctly what you mean. If you're asking at what point it's called when submitting a command to L0; for that, I've set the arbitrary point of right before the call to queue->executeCommandList()

@raaiq1
Copy link
Contributor Author

raaiq1 commented Nov 21, 2022

@smaslov-intel If you mean in what functions it should be used in. It should be where commands are being enqueued such as piEnqueueEventsWaitWithBarrier, piEnqueueKernelLaunch, etc.

@@ -5408,6 +5408,11 @@ piEnqueueKernelLaunch(pi_queue Queue, pi_kernel Kernel, pi_uint32 WorkDim,
// reference count on the kernel, using the kernel saved in CommandData.
PI_CALL(piKernelRetain(Kernel));

auto res=Queue->Device->getSubmitTime(*Event);
Copy link
Contributor

Choose a reason for hiding this comment

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

can this be moved to executeCommandList?

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 would need to add a pi_event parameter to executeCommandList and executeOpenCommandList. Is that okay?

Copy link
Contributor

Choose a reason for hiding this comment

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

Why don't you just record ALL events in the command-list? Maybe we should actually do this at batch submission?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why don't you just record ALL events in the command-list?

Wouldn't it be redundant to record all events as their profiling information wouldn't be visible to the user?

Maybe we should actually do this at batch submission?

I might be wrong but doesn't executeCommandList submit to the command to a batch if were not using immediatecommandlist ?

Copy link
Contributor

Choose a reason for hiding this comment

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

The executeCommandList does add commands to a batch, but closes it and submits if the batch is full. This is the time when I think you should record the "command_submit" time. All events in the command-list are from these enqueue interfaces, so you are already recording submit time for all of the commands.

Copy link
Contributor Author

@raaiq1 raaiq1 Nov 23, 2022

Choose a reason for hiding this comment

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

According to SYCL specifications, the submission time has to be calculated before the submit method returns. If we record the submission time when the batch is submitted, can't we run into a possibility that the time is recorded after queue.submit() returns ?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think you are right here, still you'd do it inside executeCommandList

@raaiq1
Copy link
Contributor Author

raaiq1 commented Nov 24, 2022

There seems to be an with issue with this design and SYCL RT as well, as @romanovvlad highlighted. The following code in hanging indefinetly under the current design:

accessor HostAcc = Buf.get_access();
auto e=Q.submit(/*a kernel writing to Buf*/); // Command1
std::cout << e.get_profiling_info<info::event_profiling::command_submit>(); //program hangs here
HostAcc.~accessor();

Seems like get_profiling_info() is waiting for Command1 to complete even though querying the submission time shouldn't require such operation and the Command1 cannot execute untill HostAcc is destroyed. Even if I fix that problem, the returned time is always 0. Calculating the submission time in SYCL not L0 seems to solve this issue. I've opened a draft PR for the alternate design: #7526

@smaslov-intel
Copy link
Contributor

I've lost track of where this is going.

There seems to be an with issue with this design and SYCL RT as well, as @romanovvlad highlighted. The following code in hanging indefinetly under the current design:

accessor HostAcc = Buf.get_access();
auto e=Q.submit(/*a kernel writing to Buf*/); // Command1
std::cout << e.get_profiling_info<info::event_profiling::command_submit>(); //program hangs here
HostAcc.~accessor();

Seems like get_profiling_info() is waiting for Command1 to complete even though querying the submission time shouldn't require such operation and the Command1 cannot execute untill HostAcc is destroyed. Even if I fix that problem, the returned time is always 0. Calculating the submission time in SYCL not L0 seems to solve this issue. I've opened a draft PR for the alternate design: #7526

There is no "waiting" in the L0 Plugin, just querying:

pi_result piEventGetProfilingInfo(pi_event Event, pi_profiling_info ParamName,

@raaiq1
Copy link
Contributor Author

raaiq1 commented Nov 29, 2022

There is no waiting in the plugin layer but there is at SYCL runtime, where all specializations of event::get_profiling_info() have a wait before they query for profiling info. If I remove the wait operation for the command_submit specialization, I get constantly get 0 in return.

@smaslov-intel
Copy link
Contributor

There is no waiting in the plugin layer but there is at SYCL runtime, where all specializations of event::get_profiling_info() have a wait before they query for profiling info. If I remove the wait operation for the command_submit specialization, I get constantly get 0 in return.

So, are you going to remove the wait() since it's against the spec? Why "0" is returned always after that?

@raaiq1
Copy link
Contributor Author

raaiq1 commented Nov 29, 2022

So, are you going to remove the wait() since it's against the spec?

Yes, I'll prepare a separate PR to resolve that issue soon.

Why "0" is returned always after that?

I'm not sure. I still need to figure that out.

@raaiq1
Copy link
Contributor Author

raaiq1 commented Nov 29, 2022

Why "0" is returned always after that?

Seems like the host_accessor is blocking the enqueue of the kernel in "Command1" (from the example in my earlier post), which in turn queries the submit time

@raaiq1 raaiq1 deleted the event_submit branch December 13, 2022 17:30
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.

3 participants