[Cpp API Compatibility] Add XPU device tests#78647
[Cpp API Compatibility] Add XPU device tests#78647SigureMo merged 4 commits intoPaddlePaddle:developfrom
Conversation
|
你的PR提交成功,感谢你对开源项目的贡献! |
There was a problem hiding this comment.
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(...), andTensor::toBackend(...). - Change compat
c10::Device(DeviceType::XPU)(no index) to usepaddle::DefaultXPUPlace()instead of always using device 0. - Refactor compat
Tensor::to(...)device handling to usedev._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.
| 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: |
There was a problem hiding this comment.
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.
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
|
/re-run all-failed |
|
#78655 在修 fleet 流水线,需要等这个 PR 合入了 |
|
#78655 合入了,可以 merge 下 develop 了 |
|
/re-run all-failed |
| place = phi::CPUPlace(); | ||
| break; | ||
| case c10::DeviceType::CUDA: | ||
| place = dev.has_index() ? phi::GPUPlace(dev.index()) |
There was a problem hiding this comment.
没问题,都是调用同一个 Device 对象里的方法,成员变量是相同的,_PD_GetInner 方法里有同样的处理逻辑
| 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(); |
There was a problem hiding this comment.
没问题,这里有同样的逻辑,统一封装了一下
|
/re-run all-failed |
PR Category
Execute Infrastructure
PR Types
New features
Description
新增 XPU 相关测试,未显式指定 index 的 XPU device 现在会解析到当前 XPU device
是否引起精度变化
否