Skip to content

[xpu] Add ext_oneapi_wait_and_throw API calls for device_synchronize - #191900

Closed
Stonepia wants to merge 6 commits into
pytorch:mainfrom
Stonepia:xpu/device_sync
Closed

Stonepia wants to merge 6 commits into
pytorch:mainfrom
Stonepia:xpu/device_sync

Conversation

@Stonepia

@Stonepia Stonepia commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

1.Re-land #182630 . Formerly it is disabled because of bug on XPUGraph

Motivation

This PR adds a device synchronization feature to XPU. It will block the calling until all commands previously submitted to any queue on this device have completed.

Related Spec: https://github.com/intel/llvm/blob/sycl/sycl/doc/extensions/experimental/sycl_ext_oneapi_device_wait.asciidoc

Next Plan

Since the LTS driver for platforms like PVC are not rolled out for the full support, we are not deprecating the old syncStreamsOnDevice, will switch to device_synchronize once LTS driver are fully supported.

cc @gujinghui @EikanWang @fengyuan14 @guangyey

@pytorch-bot

pytorch-bot Bot commented Aug 3, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/191900

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit a315126 with merge base 3d99896 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@Stonepia

Stonepia commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

@pytorchbot label "module: xpu" "topic: not user facing"

@pytorch-bot pytorch-bot Bot added module: xpu Intel XPU related issues topic: not user facing topic category labels Aug 3, 2026
@Stonepia
Stonepia marked this pull request as ready for review August 3, 2026 08:14
Comment thread c10/xpu/XPUStream.h Resolved
@Stonepia
Stonepia requested a review from guangyey August 4, 2026 02:58
Comment thread c10/xpu/XPUStream.h
*/
C10_DEPRECATED_MESSAGE(
"c10::xpu::syncStreamsOnDevice is deprecated. Please use c10::xpu::device_synchronize instead.")
C10_XPU_API void syncStreamsOnDevice(DeviceIndex device = -1);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It is still used in torch-xpu-ops, if we deprecate it here, pytorch build CI will fail.

Comment thread c10/xpu/XPUFunctions.cpp Outdated
#include <c10/core/impl/GPUTrace.h>
#include <c10/util/Exception.h>
#include <c10/xpu/XPUFunctions.h>
#include <c10/xpu/XPUStream.h>

@guangyey guangyey Aug 4, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

XPUFunctions should not depend on XPUStream. So we shouldn't do this.

To keep thing simple, only introduce device_synchronize, and give a chance for PVC+ to use device-wide sync under syncStreamsOnDevice. Deprecate it until PVC upgrade LTS driver

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks! reverted back, now the API calls in PyTorch I still keep using the old syncStreamsOnDevice, the API not changed, only added the device_synchronize APIs.

@guangyey guangyey left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for your update!

@guangyey guangyey added the ciflow/xpu Run XPU CI tasks label Aug 4, 2026
@pytorch-bot

pytorch-bot Bot commented Aug 4, 2026 •

Copy link
Copy Markdown

Workflows were awaiting approval. CI has now been triggered for the ciflow labels on this PR.

@guangyey guangyey added the ciflow/trunk Trigger trunk jobs on your pull request label Aug 4, 2026
@guangyey

guangyey commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

Please make sure that the bug has been fixed on BMG.

@Stonepia

Stonepia commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

Please make sure that the bug has been fixed on BMG.

I tested on the B60 for the issue reported at #187277 with the new API and it is passed. So I think it should be ok.

icpx: 2026.1.0 (2026.1.0.20260617)
[level_zero:gpu][level_zero:0] Intel(R) oneAPI Unified Runtime over Level-Zero V2, Intel(R) Arc(TM) Pro B60 Graphics 20.1.0 [1.15.38646+6]

@guangyey

guangyey commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

Thanks!

@guangyey

guangyey commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

@pytorchbot merge

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@guangyey guangyey changed the title [xpu][feat] Add ext_oneapi_wait_and_throw API calls for device_synchronize [xpu] Add ext_oneapi_wait_and_throw API calls for device_synchronize Aug 5, 2026
@Stonepia
Stonepia deleted the xpu/device_sync branch August 5, 2026 04:50
@Stonepia

Stonepia commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

@pytorchbot revert

@pytorch-bot

pytorch-bot Bot commented Sep 2, 2026

Copy link
Copy Markdown

❌ 🤖 pytorchbot command failed:

@pytorchbot revert: error: the following arguments are required: -m/--message, -c/--classification

usage: @pytorchbot revert -m MESSAGE -c
                          {nosignal,ignoredsignal,landrace,weird,ghfirst,autorevert}

Try @pytorchbot --help for more info.

@Stonepia

Stonepia commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

@pytorchbot revert -m "Revert due to performance regression" -c nosignal

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

@pytorchbot successfully started a revert job. Check the current status here.
Questions? Feedback? Please reach out to the PyTorch DevX Team

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Will not revert as @Stonepia is not one of [COLLABORATOR, MEMBER, OWNER], but instead is CONTRIBUTOR.

chiangchenghsin-hash added a commit to chiangchenghsin-hash/pytorch that referenced this pull request Oct 21, 2026
PR pytorch#191900 made syncStreamsOnDevice prefer a device-wide wait
(ext_oneapi_wait_and_throw -> urDeviceWaitExp -> zeDeviceSynchronize).
On Arc A-Series + Windows + the 2026.1 UR/Level-Zero runtime that wait
returns SUCCESS without draining in-flight work, so empty_cache()'s
subsequent sycl::free releases USM that in-flight GPU commands still
reference: silent all-NaN corruption (pytorch#197520) or a hard crash in the
next kernel (pytorch#198522). Root cause bisected to pytorch#191900 in pytorch#197520
(comment 6170166929), with a same-binary A/B showing the legacy
per-queue wait() passes 3/3.

This keeps the device-wide wait as a best-effort first step (one call,
also covers SYCL queues outside our pools) but restores the per-queue
wait() walk as the authoritative drain on every call, exactly as the
pre-pytorch#191900 code did (UR trace: one urQueueFinish per queue). The walk
is cheap and only runs in the already-slow sync/free path.
Stonepia added a commit to Stonepia/pytorch that referenced this pull request Oct 27, 2026
…h commands

Fixes pytorch#197520

pytorch#191900 made syncStreamsOnDevice use the SYCL device-wide wait
(ext_oneapi_wait_and_throw) when built with SYCL >= 2026.1. In the Level Zero
UR adapter this is urDeviceWaitExp, which only calls zeDeviceSynchronize.
zeDeviceSynchronize waits for work already submitted to the device, but on
architectures where the adapter defaults to batched (non-immediate) command
lists, kernels can still sit in an open host-side command list. The wait then
returns early and empty_cache() frees USM that pending kernels still use, which
shows up as all-NaN results or DEVICE_LOST on Arc A-Series + Windows. The
per-queue wait() (urQueueFinish) flushes the open batch first, so the legacy
path is correct.

The UR adapter defaults to batched command lists for DG2 and older on Windows,
pre-DG2 on Linux, and MTL/ARL on Linux, and to immediate command lists on PVC
and on BMG or newer (v2 adapter). This change only uses the device-wide wait on
PVC and on BMG or newer; the BMG check also matches architectures the runtime
reports as unknown, so future devices keep the device-wide wait. The gate is on
the architecture only rather than mirroring UR's OS and driver-version checks,
so DG2 on Linux and MTL/ARL on Windows fall back to the 2.13 behavior.

pytorch#201632 instead runs both the device-wide wait and the per-queue drain on every
device, which adds 96 queue waits to every torch.xpu.synchronize() and
empty_cache() on devices that are not affected.

Test Plan:

On Arc A770 + Windows, the pytorch#197520 reproducer passes on an unpatched build when
UR_L0_USE_IMMEDIATE_COMMANDLISTS=1 is set, which confirms the batched command
list root cause. This change itself has not been built or run yet. To verify,
run the pytorch#197520 reproducer on an affected device without that env var:

```
python repro.py
```

This PR was authored with the help of an AI assistant (Claude via OpenCode).
Stonepia added a commit to Stonepia/pytorch that referenced this pull request Oct 27, 2026
Fixes pytorch#197520

pytorch#191900 made syncStreamsOnDevice use the SYCL device-wide wait
(ext_oneapi_wait_and_throw) when built with SYCL >= 2026.1. In the Level Zero
UR adapter this is urDeviceWaitExp, which only calls zeDeviceSynchronize.
zeDeviceSynchronize waits for work already submitted to the device, but on
architectures where the adapter defaults to batched (non-immediate) command
lists, kernels can still sit in an open host-side command list. The wait then
returns early and empty_cache() frees USM that pending kernels still use, which
shows up as all-NaN results or DEVICE_LOST on Arc A-Series + Windows. The
per-queue wait() (urQueueFinish) flushes the open batch first, so the legacy
path is correct.

On Windows, the UR adapter defaults to batched command lists for DG2 and older,
while BMG and newer use the v2 adapter with immediate command lists. This change
keeps architectures older than BMG on the per-queue path on Windows; the BMG
check also matches architectures the runtime reports as unknown, so future
devices keep the device-wide wait. MTL/ARL use immediate command lists on
Windows and fall back to the 2.13 behavior only to keep the check simple. Linux
is unchanged. UR also defaults to batched command lists for MTL/ARL and pre-DG2
iGPUs on Linux, so they may hit the same issue; that is not verified and not
handled here.

pytorch#201632 instead runs both the device-wide wait and the per-queue drain on every
device, which adds 96 queue waits to every torch.xpu.synchronize() and
empty_cache() on devices that are not affected.

Test Plan:

On Arc A770 + Windows, the pytorch#197520 reproducer passes on an unpatched build when
UR_L0_USE_IMMEDIATE_COMMANDLISTS=1 is set, which confirms the batched command
list root cause. This change itself has not been built or run yet. To verify,
run the pytorch#197520 reproducer on an affected device without that env var:

```
python repro.py
```

This PR was authored with the help of an AI assistant (Claude via OpenCode).
Stonepia added a commit to Stonepia/pytorch that referenced this pull request Oct 27, 2026
Fixes pytorch#197520

pytorch#191900 made syncStreamsOnDevice use the SYCL device-wide wait
(ext_oneapi_wait_and_throw) when built with SYCL >= 2026.1. In the Level Zero
UR adapter this is urDeviceWaitExp, which only calls zeDeviceSynchronize.
zeDeviceSynchronize waits for work already submitted to the device, but on
architectures where the adapter defaults to batched (non-immediate) command
lists, kernels can still sit in an open host-side command list. The wait then
returns early and empty_cache() frees USM that pending kernels still use, which
shows up as all-NaN results or DEVICE_LOST on Arc A-Series + Windows. The
per-queue wait() (urQueueFinish) flushes the open batch first, so the legacy
path is correct.

On Windows, the UR adapter defaults to batched command lists for DG2 and older,
while BMG and newer use the v2 adapter with immediate command lists. This change
keeps architectures older than BMG on the per-queue path on Windows; the BMG
check also matches architectures the runtime reports as unknown, so future
devices keep the device-wide wait. MTL/ARL use immediate command lists on
Windows and fall back to the 2.13 behavior only to keep the check simple. Linux
is unchanged. UR also defaults to batched command lists for MTL/ARL and pre-DG2
iGPUs on Linux, so they may hit the same issue; that is not verified and not
handled here.

pytorch#201632 instead runs both the device-wide wait and the per-queue drain on every
device, which adds 96 queue waits to every torch.xpu.synchronize() and
empty_cache() on devices that are not affected.

Test Plan:

On Arc A770 + Windows, the pytorch#197520 reproducer passes on an unpatched build when
UR_L0_USE_IMMEDIATE_COMMANDLISTS=1 is set, which confirms the batched command
list root cause. This change itself has not been built or run yet. To verify,
run the pytorch#197520 reproducer on an affected device without that env var:

```
python repro.py
```

This PR was authored with the help of an AI assistant (Claude via OpenCode).
pytorchmergebot pushed a commit that referenced this pull request Oct 28, 2026
…BMG (#202188)

## Linked issue or supporting maintainer

Fixes #197520

## BC-breaking?

No

## Summary (human written only)

We got a report from #197520, that the #191900 introduced `NaN` and `DEVICE_LOST` on A770M. The reason is because the non-immediate command lists in those devices using v1 adapter are waiting for a batch submit. The `wait` returns early, and the `empty_cache()` frees USM those kernels still in use. Resulting `NaN` or `DEVICE_LOST`.

By using the `UR_L0_USE_IMMEDIATE_COMMANDLISTS=1` to force immediage command list, the issue is gone.  Also, the per-queue wait would solve the issue.

# Solution:
1. For the long-term solution, it depends on the fix from the driver side, we are submitting the UR JIRA to the driver team. We will switch to the v2 adapter once ready for the final solution (Target 2026.3).
2. For the short-term solution, we fallback to legacy per-queue `wait` for the old device on Windows (MTL/ARL/Arc). For Linux, since we didn't get the report, and we are going to support platforms like PVC, we by default enable all of them.

<details>
## Agent details (if applicable)
The analysis below was generated by an AI assistant (Claude via OpenCode).

> **Root cause.** #191900 switched `syncStreamsOnDevice` to the SYCL device-wide wait when built with SYCL >= 2026.1. In the Level Zero UR adapter this is `urDeviceWaitExp`, which only calls `zeDeviceSynchronize` ([source](https://github.com/intel/llvm/blob/f86e7533623aa695b1b20ce8be6c896a1cfcb146/unified-runtime/source/adapters/level_zero/common/device.cpp#L1936-L1940)). `zeDeviceSynchronize` waits for work already submitted to the device, but where the adapter defaults to batched (non-immediate) command lists ([`useImmediateCommandLists`](https://github.com/intel/llvm/blob/f86e7533623aa695b1b20ce8be6c896a1cfcb146/unified-runtime/source/adapters/level_zero/common/device.cpp#L1971-L2024)), kernels can still sit in an open host-side command list. The wait returns early and `empty_cache()` frees USM those kernels still use (all-NaN on A730M, DEVICE_LOST on A770M). The per-queue `wait()` (`urQueueFinish`) flushes the batch first, so the legacy path is correct.
>
> **Fix.** On Windows, use the device-wide wait only for BMG and newer (`arch >= intel_gpu_bmg_g21`, which also matches `architecture::unknown`, so future devices keep it); older architectures go back to the per-queue path. On Windows the UR adapter batches by default for DG2 and older, while BMG and newer use the v2 adapter with immediate command lists. MTL/ARL use immediate command lists on Windows and fall back to the 2.13 behavior only to keep the check simple. Linux is unchanged. UR also batches by default for MTL/ARL and pre-DG2 iGPUs on Linux, so they may hit the same issue; that is not verified and not handled here. The comparison relies on the enumerator ordering guarantee in [`sycl_ext_oneapi_device_architecture`](https://github.com/intel/llvm/blob/sycl/sycl/doc/extensions/experimental/sycl_ext_oneapi_device_architecture.asciidoc).
>
> **Alternative rejected.** #201632 runs both the device-wide wait and the 96-queue drain on every device, adding cost to every `torch.xpu.synchronize()` / `empty_cache()` on unaffected devices (PVC, BMG and newer).
>
> **Test status.** On Arc A770 + Windows, the #197520 reproducer passes on an unpatched build with `UR_L0_USE_IMMEDIATE_COMMANDLISTS=1`. This change has not been built or run yet. To verify: run the #197520 reproducer on Arc A-Series + Windows without that env var, and confirm with a UR trace that PVC/BMG still call `urDeviceWaitExp`.
>
> The UR-side issue (`urDeviceWaitExp` does not flush batched command lists, while `sycl_ext_oneapi_device_wait` requires waiting for all commands submitted to any queue on the device) has not been reported to intel/llvm yet.
</details>

Pull Request resolved: #202188
Approved by: https://github.com/guangyey

Co-authored-by: Yu, Guangye <[email protected]>
dominikjastrzebskix pushed a commit to dominikjastrzebskix/pytorch that referenced this pull request Nov 5, 2026
…BMG (pytorch#202188)

## Linked issue or supporting maintainer

Fixes pytorch#197520

## BC-breaking?

No

## Summary (human written only)

We got a report from pytorch#197520, that the pytorch#191900 introduced `NaN` and `DEVICE_LOST` on A770M. The reason is because the non-immediate command lists in those devices using v1 adapter are waiting for a batch submit. The `wait` returns early, and the `empty_cache()` frees USM those kernels still in use. Resulting `NaN` or `DEVICE_LOST`.

By using the `UR_L0_USE_IMMEDIATE_COMMANDLISTS=1` to force immediage command list, the issue is gone.  Also, the per-queue wait would solve the issue.

# Solution:
1. For the long-term solution, it depends on the fix from the driver side, we are submitting the UR JIRA to the driver team. We will switch to the v2 adapter once ready for the final solution (Target 2026.3).
2. For the short-term solution, we fallback to legacy per-queue `wait` for the old device on Windows (MTL/ARL/Arc). For Linux, since we didn't get the report, and we are going to support platforms like PVC, we by default enable all of them.

<details>
## Agent details (if applicable)
The analysis below was generated by an AI assistant (Claude via OpenCode).

> **Root cause.** pytorch#191900 switched `syncStreamsOnDevice` to the SYCL device-wide wait when built with SYCL >= 2026.1. In the Level Zero UR adapter this is `urDeviceWaitExp`, which only calls `zeDeviceSynchronize` ([source](https://github.com/intel/llvm/blob/f86e7533623aa695b1b20ce8be6c896a1cfcb146/unified-runtime/source/adapters/level_zero/common/device.cpp#L1936-L1940)). `zeDeviceSynchronize` waits for work already submitted to the device, but where the adapter defaults to batched (non-immediate) command lists ([`useImmediateCommandLists`](https://github.com/intel/llvm/blob/f86e7533623aa695b1b20ce8be6c896a1cfcb146/unified-runtime/source/adapters/level_zero/common/device.cpp#L1971-L2024)), kernels can still sit in an open host-side command list. The wait returns early and `empty_cache()` frees USM those kernels still use (all-NaN on A730M, DEVICE_LOST on A770M). The per-queue `wait()` (`urQueueFinish`) flushes the batch first, so the legacy path is correct.
>
> **Fix.** On Windows, use the device-wide wait only for BMG and newer (`arch >= intel_gpu_bmg_g21`, which also matches `architecture::unknown`, so future devices keep it); older architectures go back to the per-queue path. On Windows the UR adapter batches by default for DG2 and older, while BMG and newer use the v2 adapter with immediate command lists. MTL/ARL use immediate command lists on Windows and fall back to the 2.13 behavior only to keep the check simple. Linux is unchanged. UR also batches by default for MTL/ARL and pre-DG2 iGPUs on Linux, so they may hit the same issue; that is not verified and not handled here. The comparison relies on the enumerator ordering guarantee in [`sycl_ext_oneapi_device_architecture`](https://github.com/intel/llvm/blob/sycl/sycl/doc/extensions/experimental/sycl_ext_oneapi_device_architecture.asciidoc).
>
> **Alternative rejected.** pytorch#201632 runs both the device-wide wait and the 96-queue drain on every device, adding cost to every `torch.xpu.synchronize()` / `empty_cache()` on unaffected devices (PVC, BMG and newer).
>
> **Test status.** On Arc A770 + Windows, the pytorch#197520 reproducer passes on an unpatched build with `UR_L0_USE_IMMEDIATE_COMMANDLISTS=1`. This change has not been built or run yet. To verify: run the pytorch#197520 reproducer on Arc A-Series + Windows without that env var, and confirm with a UR trace that PVC/BMG still call `urDeviceWaitExp`.
>
> The UR-side issue (`urDeviceWaitExp` does not flush batched command lists, while `sycl_ext_oneapi_device_wait` requires waiting for all commands submitted to any queue on the device) has not been reported to intel/llvm yet.
</details>

Pull Request resolved: pytorch#202188
Approved by: https://github.com/guangyey

Co-authored-by: Yu, Guangye <[email protected]>
dominikjastrzebskix pushed a commit to dominikjastrzebskix/pytorch that referenced this pull request Nov 9, 2026
…BMG (pytorch#202188)

## Linked issue or supporting maintainer

Fixes pytorch#197520

## BC-breaking?

No

## Summary (human written only)

We got a report from pytorch#197520, that the pytorch#191900 introduced `NaN` and `DEVICE_LOST` on A770M. The reason is because the non-immediate command lists in those devices using v1 adapter are waiting for a batch submit. The `wait` returns early, and the `empty_cache()` frees USM those kernels still in use. Resulting `NaN` or `DEVICE_LOST`.

By using the `UR_L0_USE_IMMEDIATE_COMMANDLISTS=1` to force immediage command list, the issue is gone.  Also, the per-queue wait would solve the issue.

# Solution:
1. For the long-term solution, it depends on the fix from the driver side, we are submitting the UR JIRA to the driver team. We will switch to the v2 adapter once ready for the final solution (Target 2026.3).
2. For the short-term solution, we fallback to legacy per-queue `wait` for the old device on Windows (MTL/ARL/Arc). For Linux, since we didn't get the report, and we are going to support platforms like PVC, we by default enable all of them.

<details>
## Agent details (if applicable)
The analysis below was generated by an AI assistant (Claude via OpenCode).

> **Root cause.** pytorch#191900 switched `syncStreamsOnDevice` to the SYCL device-wide wait when built with SYCL >= 2026.1. In the Level Zero UR adapter this is `urDeviceWaitExp`, which only calls `zeDeviceSynchronize` ([source](https://github.com/intel/llvm/blob/f86e7533623aa695b1b20ce8be6c896a1cfcb146/unified-runtime/source/adapters/level_zero/common/device.cpp#L1936-L1940)). `zeDeviceSynchronize` waits for work already submitted to the device, but where the adapter defaults to batched (non-immediate) command lists ([`useImmediateCommandLists`](https://github.com/intel/llvm/blob/f86e7533623aa695b1b20ce8be6c896a1cfcb146/unified-runtime/source/adapters/level_zero/common/device.cpp#L1971-L2024)), kernels can still sit in an open host-side command list. The wait returns early and `empty_cache()` frees USM those kernels still use (all-NaN on A730M, DEVICE_LOST on A770M). The per-queue `wait()` (`urQueueFinish`) flushes the batch first, so the legacy path is correct.
>
> **Fix.** On Windows, use the device-wide wait only for BMG and newer (`arch >= intel_gpu_bmg_g21`, which also matches `architecture::unknown`, so future devices keep it); older architectures go back to the per-queue path. On Windows the UR adapter batches by default for DG2 and older, while BMG and newer use the v2 adapter with immediate command lists. MTL/ARL use immediate command lists on Windows and fall back to the 2.13 behavior only to keep the check simple. Linux is unchanged. UR also batches by default for MTL/ARL and pre-DG2 iGPUs on Linux, so they may hit the same issue; that is not verified and not handled here. The comparison relies on the enumerator ordering guarantee in [`sycl_ext_oneapi_device_architecture`](https://github.com/intel/llvm/blob/sycl/sycl/doc/extensions/experimental/sycl_ext_oneapi_device_architecture.asciidoc).
>
> **Alternative rejected.** pytorch#201632 runs both the device-wide wait and the 96-queue drain on every device, adding cost to every `torch.xpu.synchronize()` / `empty_cache()` on unaffected devices (PVC, BMG and newer).
>
> **Test status.** On Arc A770 + Windows, the pytorch#197520 reproducer passes on an unpatched build with `UR_L0_USE_IMMEDIATE_COMMANDLISTS=1`. This change has not been built or run yet. To verify: run the pytorch#197520 reproducer on Arc A-Series + Windows without that env var, and confirm with a UR trace that PVC/BMG still call `urDeviceWaitExp`.
>
> The UR-side issue (`urDeviceWaitExp` does not flush batched command lists, while `sycl_ext_oneapi_device_wait` requires waiting for all commands submitted to any queue on the device) has not been reported to intel/llvm yet.
</details>

Pull Request resolved: pytorch#202188
Approved by: https://github.com/guangyey

Co-authored-by: Yu, Guangye <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk Trigger trunk jobs on your pull request ciflow/xpu Run XPU CI tasks Merged module: xpu Intel XPU related issues open source topic: not user facing topic category

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

5 participants