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

Add basic command buffer support to level zero adapter v2 #2532

Closed
wants to merge 61 commits into from

Conversation

Xewar313
Copy link
Contributor

@Xewar313 Xewar313 commented Jan 8, 2025

This pull request implements basic calls to command buffer in level zero v2 adapter. These calls are required by sycl graph functionality implemented inside llvm, such as record and replay.

@Xewar313 Xewar313 requested review from a team as code owners January 8, 2025 11:51
@Xewar313 Xewar313 requested a review from reble January 8, 2025 11:51
@github-actions github-actions bot added level-zero L0 adapter specific issues command-buffer Command Buffer feature addition/changes/specification labels Jan 8, 2025
source/adapters/level_zero/v2/queue_api.hpp Outdated Show resolved Hide resolved
source/adapters/level_zero/v2/command_buffer.hpp Outdated Show resolved Hide resolved
source/adapters/level_zero/v2/command_buffer.hpp Outdated Show resolved Hide resolved
source/adapters/level_zero/v2/command_buffer.cpp Outdated Show resolved Hide resolved
source/adapters/level_zero/v2/command_buffer.cpp Outdated Show resolved Hide resolved
source/adapters/level_zero/v2/command_buffer.cpp Outdated Show resolved Hide resolved
source/adapters/level_zero/v2/command_buffer.hpp Outdated Show resolved Hide resolved
@Xewar313 Xewar313 requested a review from a team as a code owner January 10, 2025 14:19
@@ -19,6 +19,8 @@ from templates import helper as th
*
*/

// This file was generated basing on scripts/templates/queue_api.cpp.mako
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:

Do not edit. This file is auto generated from a template:
scripts/templates/queue_api.cpp.mako

} // namespace

std::pair<ze_event_handle_t *, uint32_t>
ur_exp_command_buffer_handle_t_::getWaitListView(
Copy link
Contributor

Choose a reason for hiding this comment

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

This is identical to the implementation in queue. Please create simple WaitListView abstraction usable in both.

ze_command_list_handle_t &commandList) {

using queue_group_type = ur_device_handle_t_::queue_group_info_t::type;
// that should be call to queue getZeOrdinal,
Copy link
Contributor

Choose a reason for hiding this comment

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

This, together with the fact that we have no way to allocate events from the correct queue, makes me think we either need to defer creation of these objects until the first enqueue of the command buffer or urCommandBufferCreateExp should take a queue.
@EwanC thoughts?

I'm also thinking whether it wouldn't make sense just to make the CommandBuffer allocate a whole pool of events from the context. That way, when we need an event, we don't have to acquire context locks.

Copy link
Contributor

Choose a reason for hiding this comment

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

This, together with the fact that we have no way to allocate events from the correct queue, makes me think we either need to defer creation of these objects until the first enqueue of the command buffer or urCommandBufferCreateExp should take a queue.
@EwanC thoughts?

I'm not that keen on urCommandBufferCreateExp taking a queue. 1) it doesn't match the SYCL API, where we don't have a queue object when creating the UR command-buffer. 2) It is the opposite direction to where the OpenCL WG is going with command-buffers in KhronosGroup/OpenCL-Docs#1292 to separate the queues used on command-buffer creation and enqueue.

Are there only 2 types of queue ordinal relevant here, compute and copy? If so I would suggest creating command-lists for both. This PR doesn't have the v1 functionality of splitting commands from the UR command-buffers into compute and copy command-lists. But we saw this having good perf benefits on V1, so would be imagine creating a copy engine command-list is something we'll need to do at some point anyway.

Copy link
Contributor

Choose a reason for hiding this comment

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

Are there only 2 types of queue ordinal relevant here, compute and copy?

In v2 by default we are only going to use the compute ordinal, letting the UMD decide whether to offload the copy to a separate engine. So the answer here is: "just use compute". I was more thinking about the general direction.
What you say makes sense.

Copy link
Contributor

Choose a reason for hiding this comment

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

cool, letting the UMD handle this consideration definitely sounds like it will simplify the adapter code

checkImmediateAppendSupport(context);

if (isUpdatable) {
UR_ASSERT(context->getPlatform()->ZeMutableCmdListExt.Supported,
Copy link
Contributor

Choose a reason for hiding this comment

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

Please don't use these "asserts". Do a normal if and return UR_RESULT_ERROR_UNSUPPORTED_FEATURE.
I just dislike overloading the term "assert" to mean fail with error.

* @param[out] commandList The L0 command-list created by this function.
* @return UR_RESULT_SUCCESS or an error code on failure
*/
ur_result_t createMainCommandList(ur_context_handle_t context,
Copy link
Contributor

Choose a reason for hiding this comment

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

this isn't used anywhere.

source/adapters/level_zero/v2/command_buffer.cpp Outdated Show resolved Hide resolved
std::pair<ze_event_handle_t *, uint32_t>
getWaitListView(const ur_event_handle_t *phWaitEvents,
uint32_t numWaitEvents);

Copy link
Contributor

Choose a reason for hiding this comment

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

private:

Copy link
Contributor

Choose a reason for hiding this comment

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

bump

pbalcer and others added 8 commits January 16, 2025 12:30
The cache action is stopping support for anything but the
very latest version. We need to update to 4.2.0 for the
cache to continue functioning.

actions/cache#1510
…he WaitEvent is done at the right time.

This fixes a potential race condition where, if the SignalCommandList executes before the ComputeCommandList, the WaitEvent could be reset before the ComputeCommandList can wait on it and, consequently, create a deadlock.
bratpiorka and others added 18 commits January 24, 2025 10:50
Added implementation details to OpenCL adapter for processing image format structs.
Added a couple missing enums to spec for ur_image_info_t and added CTS tests for these.
…fo-unswitch

Move urMemImageGetInfo success test from a switch to individual test
…/memimage-info-unswitch

Revert "Move urMemImageGetInfo success test from a switch to individual test"
…oref-arg

Fix passing struct object by value
…s-images-host-usm

Enable creation of bindless images backed by host USM
…ool_config_parse

fix parseDisjointPoolConfig and add tests
…ssaryCLSkip

Remove unnecessary OpenCL KNOWN_FAILURE from urKernelGetInfoTest.
# This is the 1st commit message:

parent 9824163
author Mikołaj Komar <mikolaj.komar@intel.com> 1734527193 +0000
committer Mateusz P. Nowak <mateusz.p.nowak@intel.com> 1738059437 +0000

Prepare ground for command_buffer in v2

Enforce in order list usage, and add initialization and destruction to buffer

Add initial support of command buffers to adapter v2

Update UR calls handling

Remove unnecessary comment

Move not implemented command buffer commands to previous position

Fix most issues with code

Fix formatting and modify queue_api template

Move command buffer cleanup to destructor

Use cached command lists instead of created ones

Remove not needed function and change phrasing

Add initial implementation of command list manager

Use list manager instead of custom implementation in queue

Optimalize imports

Remove not needed destructor

Revert "Fix formatting"

This reverts commit 545e577.

# This is the commit message oneapi-src#2:

Move command list close to the command buffer

# This is the commit message oneapi-src#3:

Moved try outside function block

# This is the commit message oneapi-src#4:

Move enqueue generic command list back to queue
author Mikołaj Komar <mikolaj.komar@intel.com> 1734527193 +0000
committer Mateusz P. Nowak <mateusz.p.nowak@intel.com> 1738059437 +0000

Prepare ground for command_buffer in v2

Enforce in order list usage, and add initialization and destruction to buffer

Add initial support of command buffers to adapter v2

Update UR calls handling

Remove unnecessary comment

Move not implemented command buffer commands to previous position

Fix most issues with code

Fix formatting and modify queue_api template

Move command buffer cleanup to destructor

Use cached command lists instead of created ones

Remove not needed function and change phrasing

Add initial implementation of command list manager

Use list manager instead of custom implementation in queue

Optimalize imports

Remove not needed destructor

Revert "Fix formatting"

This reverts commit 545e577.

Move command list close to the command buffer

Moved try outside function block

Move enqueue generic command list back to queue

Share events and lists between queue and command list manager

Use ze events instead of ur in getSignalEvent
# This is the 1st commit message:

parent 9824163
author Mikołaj Komar <mikolaj.komar@intel.com> 1734527193 +0000
committer Mateusz P. Nowak <mateusz.p.nowak@intel.com> 1738059437 +0000

Prepare ground for command_buffer in v2

Enforce in order list usage, and add initialization and destruction to buffer

Add initial support of command buffers to adapter v2

Update UR calls handling

Remove unnecessary comment

Move not implemented command buffer commands to previous position

Fix most issues with code

Fix formatting and modify queue_api template

Move command buffer cleanup to destructor

Use cached command lists instead of created ones

Remove not needed function and change phrasing

Add initial implementation of command list manager

Use list manager instead of custom implementation in queue

Optimalize imports

Remove not needed destructor

Revert "Fix formatting"

This reverts commit 545e577.

Move command list close to the command buffer

Moved try outside function block

Move enqueue generic command list back to queue

Share events and lists between queue and command list manager

Use ze events instead of ur in getSignalEvent

# This is the commit message oneapi-src#2:

Remove not needed structs and reformat code

# This is the commit message oneapi-src#3:

Fix PR comments
# This is the 1st commit message:

parent 9824163
author Mikołaj Komar <mikolaj.komar@intel.com> 1734527193 +0000
committer Mateusz P. Nowak <mateusz.p.nowak@intel.com> 1738059437 +0000

Prepare ground for command_buffer in v2

Enforce in order list usage, and add initialization and destruction to buffer

Add initial support of command buffers to adapter v2

Update UR calls handling

Remove unnecessary comment

Move not implemented command buffer commands to previous position

Fix most issues with code

Fix formatting and modify queue_api template

Move command buffer cleanup to destructor

Use cached command lists instead of created ones

Remove not needed function and change phrasing

Add initial implementation of command list manager

Use list manager instead of custom implementation in queue

Optimalize imports

Remove not needed destructor

Revert "Fix formatting"

This reverts commit 545e577.

Move command list close to the command buffer

Moved try outside function block

Move enqueue generic command list back to queue

Share events and lists between queue and command list manager

Use ze events instead of ur in getSignalEvent

# This is the commit message oneapi-src#2:

Remove not needed structs and reformat code

# This is the commit message oneapi-src#3:

Fix PR comments

# This is the commit message oneapi-src#4:

Fix ze function calling

# This is the commit message oneapi-src#5:

Fix access to some fields in command buffer v2

# This is the commit message oneapi-src#6:

Fix compilation
@mateuszpn mateuszpn requested review from a team as code owners January 28, 2025 10:35
@github-actions github-actions bot added ci/cd Continuous integration/devliery common Changes or additions to common utilities conformance Conformance test suite issues. images UR images cuda CUDA adapter specific issues hip HIP adapter specific issues labels Jan 28, 2025
@pbalcer pbalcer closed this Jan 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci/cd Continuous integration/devliery command-buffer Command Buffer feature addition/changes/specification common Changes or additions to common utilities conformance Conformance test suite issues. cuda CUDA adapter specific issues hip HIP adapter specific issues images UR images level-zero L0 adapter specific issues loader Loader related feature/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.