Skip to content

[UR] Add remaining calls shared with queue in level-zero v2 adapter #17061

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

Merged
merged 1 commit into from
Feb 20, 2025

Conversation

Xewar313
Copy link
Contributor

@Xewar313 Xewar313 commented Feb 19, 2025

Adds implements calls shared between command buffer and queue in unified-runtime level-zero v2 adapter and moves the shared code to command_list_manager.cpp

@Xewar313 Xewar313 requested review from a team as code owners February 19, 2025 09:43
@Xewar313 Xewar313 requested a review from reble February 19, 2025 09:43
@Xewar313 Xewar313 changed the title [v2] Add remaining calls shared with queue [UR] Add remaining calls shared with queue in level-zero v2 adapter Feb 19, 2025
ur_event_handle_t *phEvent) {
TRACK_SCOPE_LATENCY("ur_command_list_manager::appendUSMAdvise");

std::scoped_lock<ur_shared_mutex> lock(this->Mutex);
Copy link
Member

Choose a reason for hiding this comment

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

This isn;t related to this PR in particular but to the whole command_list_manager implementation. I didn't notice this before but now, we have 2 different mutexes: this one (from command_list_manager) and a separate one in queue_immediate_in_order class.

Some functions now lock this mutex, while others lock the one from queue_immediate_in_order which means there's no synchronization.

This should be fixed, probably by always using lock from ur_command_list_manager (in every queue_immediate_in_order and command_buffer function).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense - should I add it to this PR, or these changes should be in separate one?

Copy link
Member

Choose a reason for hiding this comment

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

You can do that in a separate PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

What we are really trying to protect is the state inside of the command list manager. Maybe we should create some sort of scoped locking abstraction for objects (like mutexes in Rust), e.g.,:

class CommandBuffer {
  Mutex<CommandListManager> cmdListMgr;
}

{
  auto mgr = cmdbuf->cmdListMgr.lock();
  mgr->AppendFoo();
}

This way it will be impossible to make the same mistake and we don't have to extend the scope of a lock to the outside of its member functions.

Copy link
Member

Choose a reason for hiding this comment

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

Hm, that's actually a pretty good idea, and it should be enough to just create a structure that holds a reference to the cmdListMgr and implements command_list_manager operator->(), then mgr->whatever() should work automatically.

@pbalcer
Copy link
Contributor

pbalcer commented Feb 20, 2025

The CI failure is a known issue - #16877
@intel/llvm-gatekeepers please merge

@steffenlarsen steffenlarsen merged commit 0b979bf into intel:sycl Feb 20, 2025
29 of 30 checks passed
sarnex pushed a commit that referenced this pull request Mar 14, 2025
…7297)

Changes:
Command_list_manager no longer synchronize its calls, instead the
responsibility to ensure exclusivity belongs to the caller.
To add synchronization I implemented the mechanism similar to rust lock
as suggested in
#17061 (comment).
kbenzie pushed a commit to oneapi-src/unified-runtime that referenced this pull request Mar 17, 2025
Changes:
Command_list_manager no longer synchronize its calls, instead the
responsibility to ensure exclusivity belongs to the caller.
To add synchronization I implemented the mechanism similar to rust lock
as suggested in
intel/llvm#17061 (comment).
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.

5 participants