Skip to content

[Cpp API Compatibility] Add XPU device tests#78647

Merged
SigureMo merged 4 commits intoPaddlePaddle:developfrom
youge325:cXPU
Apr 15, 2026
Merged

[Cpp API Compatibility] Add XPU device tests#78647
SigureMo merged 4 commits intoPaddlePaddle:developfrom
youge325:cXPU

Conversation

@youge325
Copy link
Copy Markdown
Contributor

@youge325 youge325 commented Apr 11, 2026

PR Category

Execute Infrastructure

PR Types

New features

Description

新增 XPU 相关测试,未显式指定 index 的 XPU device 现在会解析到当前 XPU device

是否引起精度变化

Copilot AI review requested due to automatic review settings April 11, 2026 11:41
@paddle-bot
Copy link
Copy Markdown

paddle-bot bot commented Apr 11, 2026

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@paddle-bot paddle-bot bot added the contributor External developers label Apr 11, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR extends the C++ ATen/c10 compatibility test suite to cover XPU device behaviors, and updates the compat device→place mapping so “device without index” follows the current XPU device (mirroring existing CUDA behavior).

Changes:

  • Add XPU-aware test branches for c10::Device, at::Tensor::to(...), at::empty(...), and Tensor::toBackend(...).
  • Change compat c10::Device(DeviceType::XPU) (no index) to use paddle::DefaultXPUPlace() instead of always using device 0.
  • Refactor compat Tensor::to(...) device handling to use dev._PD_GetInner() for supported device types.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
test/cpp/compat/c10_Device_test.cc Adds XPU current-device assertions for no-index c10::Device(c10::kXPU) when XPU is available.
test/cpp/compat/ATen_to_test.cc Adds CPU→XPU and no-index-XPU-current-device to(...) tests; updates unsupported-device test.
test/cpp/compat/ATen_empty_test.cc Adds XPU default-device (no index) coverage for at::empty(... device(at::kXPU)).
test/cpp/compat/ATen_basic_test.cc Adds XPU current-device coverage for Tensor::toBackend(c10::Backend::XPU).
paddle/phi/api/include/compat/c10/core/Device.h Changes XPU no-index device→place mapping to use DefaultXPUPlace() (current device).
paddle/phi/api/include/compat/ATen/ops/to.h Uses Device::_PD_GetInner() for device transfer place resolution (covers XPU/IPU/CUSTOM).
paddle/phi/api/include/compat/ATen/core/TensorBody.h Makes toBackend(XPU) use DefaultXPUPlace() (current device).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 133 to 139
case DeviceType::CUDA:
return has_index() ? phi::GPUPlace(index_) : paddle::DefaultGPUPlace();
case DeviceType::XPU:
return phi::XPUPlace(has_index() ? index_ : 0);
return has_index() ? phi::XPUPlace(index_) : paddle::DefaultXPUPlace();
case DeviceType::IPU:
return phi::IPUPlace(has_index() ? index_ : 0);
return has_index() ? phi::IPUPlace(index_) : phi::IPUPlace();
case DeviceType::CUSTOM:
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

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

The PR description says it only adds XPU-related tests, but this change also modifies runtime behavior: XPU devices without an explicit index now resolve to paddle::DefaultXPUPlace() (current device) instead of always using device 0. Please update the PR description (or add release notes) to explicitly call out this semantics change, since it can affect existing users relying on the previous default-device behavior.

Copilot uses AI. Check for mistakes.
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 11, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (develop@0442435). Learn more about missing BASE report.

Additional details and impacted files
@@             Coverage Diff             @@
##             develop    #78647   +/-   ##
===========================================
  Coverage           ?   100.00%           
===========================================
  Files              ?         3           
  Lines              ?        17           
  Branches           ?         0           
===========================================
  Hits               ?        17           
  Misses             ?         0           
  Partials           ?         0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@youge325
Copy link
Copy Markdown
Contributor Author

/re-run all-failed

@SigureMo
Copy link
Copy Markdown
Member

#78655 在修 fleet 流水线,需要等这个 PR 合入了

@SigureMo
Copy link
Copy Markdown
Member

#78655 合入了,可以 merge 下 develop 了

@youge325
Copy link
Copy Markdown
Contributor Author

/re-run all-failed

place = phi::CPUPlace();
break;
case c10::DeviceType::CUDA:
place = dev.has_index() ? phi::GPUPlace(dev.index())
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

这里是 #78631 刚改的,修改后是否会带来回归?

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.

没问题,都是调用同一个 Device 对象里的方法,成员变量是相同的,_PD_GetInner 方法里有同样的处理逻辑

Comment on lines 129 to +138
phi::Place _PD_GetInner() const {
switch (type_) {
case DeviceType::CPU:
return phi::CPUPlace();
case DeviceType::CUDA:
return has_index() ? phi::GPUPlace(index_) : paddle::DefaultGPUPlace();
case DeviceType::XPU:
return phi::XPUPlace(has_index() ? index_ : 0);
return has_index() ? phi::XPUPlace(index_) : paddle::DefaultXPUPlace();
case DeviceType::IPU:
return phi::IPUPlace(has_index() ? index_ : 0);
return has_index() ? phi::IPUPlace(index_) : phi::IPUPlace();
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.

没问题,这里有同样的逻辑,统一封装了一下

@youge325
Copy link
Copy Markdown
Contributor Author

/re-run all-failed

Copy link
Copy Markdown
Member

@SigureMo SigureMo left a comment

Choose a reason for hiding this comment

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

LGTMeow 🐾

@SigureMo SigureMo merged commit 16a7d0a into PaddlePaddle:develop Apr 15, 2026
137 of 141 checks passed
@youge325 youge325 deleted the cXPU branch April 15, 2026 03:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor External developers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants