Skip to content

[UR][L0V2] implement host-mediated buffer migration fallback#22152

Draft
kweronsx wants to merge 1 commit into
intel:syclfrom
kweronsx:fix-pvc-unsupported-feature
Draft

[UR][L0V2] implement host-mediated buffer migration fallback#22152
kweronsx wants to merge 1 commit into
intel:syclfrom
kweronsx:fix-pvc-unsupported-feature

Conversation

@kweronsx

@kweronsx kweronsx commented May 28, 2026

Copy link
Copy Markdown
Contributor

When two devices lack P2P access, getDevicePtr() was unconditionally throwing UR_RESULT_ERROR_UNSUPPORTED_FEATURE instead of migrating the buffer through a temporary host allocation. Implement the fallback: copy active-device -> host -> target device.

@kweronsx kweronsx requested a review from a team as a code owner May 28, 2026 12:34
@kweronsx kweronsx requested a review from Copilot May 28, 2026 12:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Replaces the UR_RESULT_ERROR_UNSUPPORTED_FEATURE failure in ur_discrete_buffer_handle_t::getDevicePtr (Level Zero v2 adapter) with a host-mediated migration fallback when peer-to-peer access between the active allocation device and the requested device is unavailable. The fallback allocates a temporary USM host buffer, copies device→host from the active allocation, then host→device into the target allocation via migrateBufferTo, and updates activeAllocationDevice.

Changes:

  • Removes the unconditional throw on the non-P2P path and downgrades the log to DEBUG with a migration message.
  • Adds a temporary USM host allocation (RAII-guarded via usm_unique_ptr_t) and performs source-device→host→target-device copies using synchronousZeCopy and migrateBufferTo.
  • Sets activeAllocationDevice to the target device and returns the offset pointer into the new active allocation.

Comment thread unified-runtime/source/adapters/level_zero/v2/memory.cpp Outdated
Comment thread unified-runtime/source/adapters/level_zero/v2/memory.cpp Outdated
@kweronsx kweronsx force-pushed the fix-pvc-unsupported-feature branch 2 times, most recently from 116faca to 75ea41d Compare May 29, 2026 10:01
@kweronsx kweronsx requested a review from a team as a code owner May 29, 2026 10:01
@kweronsx kweronsx requested a review from Copilot May 29, 2026 10:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@ldorau

ldorau commented May 29, 2026

Copy link
Copy Markdown
Contributor

@kweronsx Rebase on the current sycl branch so that CI builds could start.

@kweronsx kweronsx force-pushed the fix-pvc-unsupported-feature branch 2 times, most recently from 6fbeb9d to 1abfeb7 Compare May 29, 2026 10:46
@kweronsx kweronsx requested a review from Copilot May 29, 2026 10:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@ldorau ldorau requested a review from Copilot May 29, 2026 11:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@ldorau ldorau requested a review from Copilot May 29, 2026 11:01

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@kswiecicki kswiecicki requested a review from Copilot May 29, 2026 13:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Comment thread unified-runtime/source/adapters/level_zero/v2/memory.cpp Outdated
@kweronsx kweronsx force-pushed the fix-pvc-unsupported-feature branch from 1abfeb7 to 461bfb3 Compare June 1, 2026 10:03
@kweronsx kweronsx requested a review from Copilot June 2, 2026 11:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

@kweronsx

kweronsx commented Jun 2, 2026

Copy link
Copy Markdown
Contributor Author

@intel/unified-runtime-reviewers @intel/unified-runtime-reviewers-level-zero please review. Thank you

Comment thread unified-runtime/source/adapters/level_zero/v2/memory.cpp
@kweronsx kweronsx requested a review from ldorau June 3, 2026 08:39
Comment thread unified-runtime/source/adapters/level_zero/v2/memory.cpp Outdated
ze_bool_t isImmediate = false;
ZE2UR_CALL_THROWS(zeCommandListIsImmediate, (cmdList, &isImmediate));

if (isImmediate) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm wondering whether there's any benefit in using the provided cmdList, we are essentially doing the following here:
appendWait->syncEventsWithHost->syncCopy->appendCopy->syncEventsWithHost
meanwhile the case below does:
syncEventsWithHost->syncCopy->syncCopy

@ldorau, @pbalcer what do you think?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

When can cmdlist be null? I don't think the current implementation will work for non-immediate cmdlists. The staging buffer copy needs to be order with the already appended cmdlist operations, not just events. Also, if the events themselves are from non-immediate queue, this may hang, because the non-immediate cmdlist (i.e., a batch) may not have been ran yet.

This either needs to be done fully asynchronously (which would be my preference), or the non-immediate path needs to make sure the batch/cmdlist, and related associated events, are complete prior to executing this synchronous copy.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I see that cmdList is explicitly passed as nullptr only here. Command list manager always passes its own internal command list to getDevicePtr, which can be of regular type.
To make it fully asynchronous we would have to:

  1. create host staging buffer and keep its lifetime until the copy is finished (or the ur_discrete_buffer_handle_t lifetime)
  2. append wait on waitlist events
  3. append copy srcPtr -> hostPtr
  4. append copy hostPtr -> dstPtr
  5. no synchronization - the events are ordered
    and the !cmdList path stays as is, is that correct?

@kweronsx kweronsx requested a review from pbalcer June 3, 2026 12:38
@kweronsx kweronsx force-pushed the fix-pvc-unsupported-feature branch 2 times, most recently from 1b09598 to 36cff3a Compare June 9, 2026 12:49

@pbalcer pbalcer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It looks like my comments from #22010 weren't considered.

Comment thread unified-runtime/source/adapters/level_zero/v2/memory.cpp Outdated
ze_bool_t isImmediate = false;
ZE2UR_CALL_THROWS(zeCommandListIsImmediate, (cmdList, &isImmediate));

if (isImmediate) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

When can cmdlist be null? I don't think the current implementation will work for non-immediate cmdlists. The staging buffer copy needs to be order with the already appended cmdlist operations, not just events. Also, if the events themselves are from non-immediate queue, this may hang, because the non-immediate cmdlist (i.e., a batch) may not have been ran yet.

This either needs to be done fully asynchronously (which would be my preference), or the non-immediate path needs to make sure the batch/cmdlist, and related associated events, are complete prior to executing this synchronous copy.

@kweronsx kweronsx requested review from kswiecicki and pbalcer June 9, 2026 13:20
Comment thread unified-runtime/source/adapters/level_zero/v2/memory.cpp
@kweronsx kweronsx requested a review from kswiecicki June 11, 2026 07:37
@kweronsx kweronsx marked this pull request as draft June 29, 2026 08:45
@kweronsx kweronsx force-pushed the fix-pvc-unsupported-feature branch 4 times, most recently from e8b8b9a to 167d748 Compare July 13, 2026 13:43
When two devices lack P2P access, getDevicePtr() unconditionally
threw UR_RESULT_ERROR_UNSUPPORTED_FEATURE instead of migrating the
buffer through a temporary host allocation.

Implement the fallback:
copy active device -> host -> target device

Resumes work on intel#22010
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