-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
[PHI decoupling]decouple tensor_utils of TensorCopy #50264
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
5b09efd
to
0906f6e
Compare
b791a5f
to
8235d06
Compare
部分是降低耦合程度
Approval需要豁免 |
61cf74c
to
88d0fae
Compare
paddle/phi/common/scalar.cc
Outdated
@@ -14,9 +14,12 @@ limitations under the License. */ | |||
|
|||
#include "paddle/phi/common/scalar.h" | |||
|
|||
#include "paddle/fluid/framework/tensor_util.h" | |||
#include "paddle/fluid/platform/place.h" |
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.
*out_size, paddle::platform::CPUPlace(), &sizes); | ||
phi::DeviceContextPool& pool = phi::DeviceContextPool::Instance(); | ||
auto dev_ctx = pool.Get(out_size->place()); | ||
phi::Copy(*dev_ctx, *out_size, phi::CPUPlace(), true, &sizes); |
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.
这里看起来函数参数有传入dev_ctx,还需要再从pool中拿吗
*out_size, paddle::platform::CPUPlace(), &sizes); | ||
phi::DeviceContextPool& pool = phi::DeviceContextPool::Instance(); | ||
auto dev_ctx = pool.Get(out_size->place()); | ||
phi::Copy(*dev_ctx, *out_size, phi::CPUPlace(), true, &sizes); |
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.
同上
*out_size, paddle::platform::CPUPlace(), &sizes); | ||
phi::DeviceContextPool& pool = phi::DeviceContextPool::Instance(); | ||
auto dev_ctx = pool.Get(out_size->place()); | ||
phi::Copy(*dev_ctx, *out_size, phi::CPUPlace(), true, &sizes); |
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.
同上
@@ -96,15 +95,16 @@ inline std::vector<int> get_new_shape( | |||
#ifdef PADDLE_WITH_XPU | |||
if (tensor->place().GetType() == phi::AllocationType::XPU) { | |||
DenseTensor temp; | |||
paddle::framework::TensorCopySync(*tensor, phi::CPUPlace(), &temp); | |||
phi::Copy<phi::CPUContext>( | |||
phi::CPUContext(), *tensor, phi::CPUPlace(), true, &temp); |
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.
这里应该有Bug,创建了CPUContext临时对象
91e864f
to
701888a
Compare
修改超20个文件 PR-CI-APPROVAL 需要豁免 |
@@ -188,7 +186,13 @@ inline phi::DenseTensor TransDataPlace(const phi::DenseTensor& tensor, | |||
// But the embarrassment is that this solution this solution makes training | |||
// slower. | |||
phi::DenseTensor out; | |||
paddle::framework::TensorCopySync(tensor, dst_place, &out); | |||
phi::DeviceContext* dev_ctx; | |||
if (dst_place.GetType() != AllocationType::CPU) { |
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.
这里为何要进行判断区分,直接通过dst_place拿到dev_ctx会有什么问题吗
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.
之前windows有个test_yolo_loss的fluid测试,直接dst_place获取dev_ctx,会出错。
dst_place可能是CPU,src_place可能是CUDA,这会导致ctx_place是CPU。
最终会导致https://github.com/PaddlePaddle/Paddle/blob/701888a09cb6a89f136c92f96b85f440cad2e198/paddle/phi/core/tensor_utils.cc
120行throw异常
Context place error, excepted GPUPlace, but actually CPUPlace
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.
修改超20个文件 PR-CI-APPROVAL 需要豁免
PR-CI-Coverage 覆盖率C++ 需要豁免
PR-CI-OP-benchmark 算子过多 一直超时,可能需要豁免
@engineer1109 op-benchmark是测试性能的,copy的修改可能会造成性能问题,多rerun几次看是否能跑过
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.
看起来没啥问题,下周我让相关同学再看一下
701888a
to
6e398fa
Compare
Resolve conflict |
6e398fa
to
861b9aa
Compare
custom_device_test.cc有人在更新,改动放弃 |
paddle/phi/common/scalar.cc
Outdated
framework::TensorCopySync(tensor_in, cpu_place, &tensor); | ||
phi::DeviceContextPool& pool = phi::DeviceContextPool::Instance(); | ||
auto dev_ctx = pool.Get(tensor_in.place()); | ||
phi::Copy(*dev_ctx, tensor_in, cpu_place, false, &tensor); |
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.
fix X remove TensorCopy codestyle add fluid memory header fix symbol fix cmake fix cmake fix context fix header fix place fix context fix context fix context fix code fix custom context fix custom context fix copy fix data_transform fix style remove changes of custom fix scalar
861b9aa
to
2e45dda
Compare
@zyfncg @YuanRisheng 还有什么问题吗? |
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.
LGTM for CI-OP-Benchmark
@luotao1 这个PR现在如何? |
Coverage流水线已豁免 |
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.
LGTM
#47615 refer |
PR types
Others
PR changes
Others
Describe
decouple tensor_utils of TensorCopy, and other functions