-
Notifications
You must be signed in to change notification settings - Fork 6k
[Cpp API Compatibility] add Compat API #78026
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from 1 commit
1962a9a
74f284f
21d33fc
1629589
7d264c0
0c79448
948edb7
7679832
4ba11d2
f0d5ab1
867baff
a82e739
27068e2
ba924ad
bf84ee3
dbe28a6
ec0e598
ea804dd
13a3bf7
51f60e2
fb366ca
4dddbf7
b5def57
675e095
81d1eba
75c049f
af2f91f
92151c3
7a0665f
834ef07
fedd418
3bfcd87
4a7ed29
1713cf3
eec6fc2
6af70c7
f93f1c5
7d30522
f6f463e
e7de3b0
1a3217c
0f33719
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -31,10 +31,32 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #endif | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <c10/core/Device.h> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <c10/core/List.h> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <c10/core/ScalarType.h> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <c10/core/SymIntArrayRef.h> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <limits> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <optional> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <utility> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <vector> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include "paddle/common/ddim.h" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include "paddle/phi/common/place.h" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #ifdef PADDLE_WITH_CUDA | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include "paddle/phi/backends/gpu/forwards.h" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #endif | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| namespace at { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class Tensor; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Type aliases for ATen compatibility | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| using Scalar = c10::Scalar; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| using TensorOptions = c10::TensorOptions; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| using MemoryFormat = c10::MemoryFormat; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| using IntArrayRef = c10::IntArrayRef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| using OptionalIntArrayRef = c10::OptionalIntArrayRef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| using ScalarType = c10::ScalarType; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } // namespace at | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| namespace at { // NOLINT(build/namespaces) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| using PaddleTensor = paddle::Tensor; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| using PaddlePlace = phi::Place; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -236,6 +258,163 @@ class Tensor : public TensorBase { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return *(cpu_tensor.data<T>()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Clamp functions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| at::Tensor clamp( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const ::std::optional<at::Scalar>& min, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const ::std::optional<at::Scalar>& max = ::std::nullopt) const; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| at::Tensor clamp(const ::std::optional<at::Tensor>& min = {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const ::std::optional<at::Tensor>& max = {}) const; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| at::Tensor& clamp_( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const ::std::optional<at::Scalar>& min, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const ::std::optional<at::Scalar>& max = ::std::nullopt) const; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| at::Tensor& clamp_(const ::std::optional<at::Tensor>& min = {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const ::std::optional<at::Tensor>& max = {}) const; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| at::Tensor clamp_max(const at::Scalar& max) const; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| at::Tensor clamp_max(const at::Tensor& max) const; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| at::Tensor& clamp_max_(const at::Scalar& max) const; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| at::Tensor& clamp_max_(const at::Tensor& max) const; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| at::Tensor clamp_min(const at::Scalar& min) const; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| at::Tensor clamp_min(const at::Tensor& min) const; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| at::Tensor& clamp_min_(const at::Scalar& min) const; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| at::Tensor& clamp_min_(const at::Tensor& min) const; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+240
to
+253
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const ::std::optional<at::Scalar>& max = ::std::nullopt) const; | |
| at::Tensor& clamp_(const ::std::optional<at::Tensor>& min = {}, | |
| const ::std::optional<at::Tensor>& max = {}) const; | |
| at::Tensor clamp_max(const at::Scalar& max) const; | |
| at::Tensor clamp_max(const at::Tensor& max) const; | |
| at::Tensor& clamp_max_(const at::Scalar& max) const; | |
| at::Tensor& clamp_max_(const at::Tensor& max) const; | |
| at::Tensor clamp_min(const at::Scalar& min) const; | |
| at::Tensor clamp_min(const at::Tensor& min) const; | |
| at::Tensor& clamp_min_(const at::Scalar& min) const; | |
| at::Tensor& clamp_min_(const at::Tensor& min) const; | |
| const ::std::optional<at::Scalar>& max = ::std::nullopt); | |
| at::Tensor& clamp_(const ::std::optional<at::Tensor>& min = {}, | |
| const ::std::optional<at::Tensor>& max = {}); | |
| at::Tensor clamp_max(const at::Scalar& max) const; | |
| at::Tensor clamp_max(const at::Tensor& max) const; | |
| at::Tensor& clamp_max_(const at::Scalar& max); | |
| at::Tensor& clamp_max_(const at::Tensor& max); | |
| at::Tensor clamp_min(const at::Scalar& min) const; | |
| at::Tensor clamp_min(const at::Tensor& min) const; | |
| at::Tensor& clamp_min_(const at::Scalar& min); | |
| at::Tensor& clamp_min_(const at::Tensor& min); |
Outdated
Copilot
AI
Feb 27, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The as_strided method doesn't validate that the provided size and stride parameters are valid for the tensor's underlying storage. Invalid stride/size combinations could lead to out-of-bounds memory access. Add validation to ensure the strided view doesn't exceed the available storage bounds.
Outdated
Copilot
AI
Feb 27, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The as_strided and as_strided_ methods use PD_THROW for error handling without checking if the tensor is initialized first. If an uninitialized tensor is passed, calling tensor_.impl() could lead to undefined behavior before the check. Add an initialization check before accessing the impl.
Outdated
Copilot
AI
Feb 27, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The as_strided_ method is declared as const but modifies the tensor's internal state (size, stride, and metadata). This violates const correctness. The method should either be non-const or should not modify the internal state.
Outdated
Copilot
AI
Feb 27, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The as_strided_scatter method calls copy_ on a view, but the result is the view itself, not the original tensor. This means the changes are only reflected in the strided view and won't affect the original tensor that the method was called on. The return value should be a modified copy of the original tensor with the scattered values, not just the view.
| return strided_view; | |
| // Return the original tensor (now containing the scattered values), | |
| // rather than the strided view. | |
| return *this; |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这几个 as_strided 是不是也应该将实现放在 ops 目录?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已修改
Copilot
AI
Feb 27, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The index_put_ methods are declared as const but modify the tensor state in-place. These methods should not be const since they perform in-place modifications. The const_cast pattern used throughout indicates a fundamental const-correctness issue.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里应该是other.dtype
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个具体是用哪个函数的?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个函数里面用到了
cudaStream_t&forwards.h第27行:using cudaStream_t = struct CUstream_st *;There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
可是这个
record_stream应该不是这个 PR 加的吧?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是的,不是这次加的
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
那这个 PR 为什么要加这个 include?如果有问题的话,之前加的时候就应该挂掉?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
嗯这个接口不是我加的,我先把
forwards.h删掉吧。确实,不加也没有挂那应该没问题