[Cpp API Compatibility] Align event api#78553
Conversation
|
你的PR提交成功,感谢你对开源项目的贡献! |
There was a problem hiding this comment.
Pull request overview
This PR updates the C++ compat layer to better match PyTorch’s stream/event APIs, including stream-pool signature parity and a more feature-complete c10::Event surface.
Changes:
- Update
c10::cuda::getStreamFromPoolto support the(int priority, DeviceIndex)overload and map negative priorities to the high-priority pool. - Expand
c10::Eventto track device metadata, add PyTorch-like methods (e.g.,recordOnce,query,eventId,synchronize), and tighten stream/device-type checks. - Remove deprecated/raw stream record_stream overloads and legacy
raw_stream()exposure.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| paddle/phi/api/include/compat/c10/cuda/CUDAStream.h | Adds PyTorch-shaped getStreamFromPool(int priority, ...) and updates priority selection logic. |
| paddle/phi/api/include/compat/c10/core/Stream.h | Exposes c10::Stream into namespace at for API compatibility. |
| paddle/phi/api/include/compat/c10/core/Event.h | Refactors/extends c10::Event interface and behavior to resemble PyTorch. |
| paddle/phi/api/include/compat/ATen/ops/record_stream.h | Removes deprecated record_stream overloads (CUDAStream / cudaStream_t) in favor of at::Stream. |
| paddle/phi/api/include/compat/ATen/core/TensorBody.h | Removes the corresponding record_stream overload declarations. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| #include <c10/core/Stream.h> | ||
|
|
||
| #ifdef PADDLE_WITH_CUDA | ||
| #include <c10/cuda/CUDAStream.h> |
There was a problem hiding this comment.
This header uses std::mutex/std::unique_lock in EventPool, but doesn't include <mutex> directly (it currently relies on transitive includes from other headers). Adding an explicit #include <mutex> under the PADDLE_WITH_CUDA guard would make this file self-contained and less fragile to include-order changes.
| #include <c10/cuda/CUDAStream.h> | |
| #include <c10/cuda/CUDAStream.h> | |
| #include <mutex> |
| } | ||
|
|
||
| void record_stream(at::Stream s) const; |
There was a problem hiding this comment.
Now that the record_stream(at::cuda::CUDAStream) overload was removed, the forward-declaration block for at::cuda::CUDAStream near the top of this file (and its comment) appears unused and misleading (the file no longer declares any overload needing it). Consider removing that forward declaration/comment to avoid stale documentation and unnecessary namespace pollution.
|
/re-run all-failed |
Codecov Report❌ Patch coverage is
❌ Your patch status has failed because the patch coverage (89.28%) is below the target coverage (90.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## develop #78553 +/- ##
==========================================
Coverage ? 89.28%
==========================================
Files ? 1
Lines ? 84
Branches ? 0
==========================================
Hits ? 75
Misses ? 9
Partials ? 0 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
/skip-reason: 未覆盖分支均为正常逻辑不可达分支,为确保与 PyTorch 逻辑对齐而添加的完善逻辑 |
PR Category
Execute Infrastructure
PR Types
Improvements
Description
拆分自 #78484
Align Event related APIs,将
c10::Event实现为完整的跨平台兼容类。变更详情
问题背景
历史上
c10::Event存在以下问题:#ifdef PADDLE_WITH_CUDA包裹,非 CUDA 构建时不可用EventFlag枚举和对应构造函数变更内容 (
c10/core/Event.h)重构
c10::Event为完整的跨平台兼容类:跨平台支持
c10::Event移出#ifdef PADDLE_WITH_CUDA条件编译Backend doesn't support events异常对齐效果
EventCompatTest.EventDefault/EventWithFlag/EventRecordThrows/EventRecordOnceThrows/EventMove/EventDevice相关文档
是否引起精度变化
否