Skip to content

Commit

Permalink
optimize syncToVar to avoid multiple call
Browse files Browse the repository at this point in the history
  • Loading branch information
JiabinYang committed Nov 1, 2021
1 parent e947e83 commit 3f5a7d3
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions paddle/fluid/eager/utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ std::vector<std::shared_ptr<egr::EagerTensor>> SyncToVars(
const egr::EagerTensor& tensor) {
// TODO(jiabin): No const cast here. We should call SyncToVar in Python_C
// wrapper
auto egr_tensor = std::make_shared<EagerTensor>(tensor);
egr_tensor->SyncToVar(paddle::framework::proto::VarType_Type_LOD_TENSOR);
return {egr_tensor};
const_cast<EagerTensor*>(&tensor)->SyncToVar(
paddle::framework::proto::VarType_Type_LOD_TENSOR);
return {std::make_shared<EagerTensor>(tensor)};
}

std::vector<std::shared_ptr<egr::EagerTensor>> SyncToVars(
Expand All @@ -38,8 +38,9 @@ std::vector<std::shared_ptr<egr::EagerTensor>> SyncToVars(
size_t num = tensors.size();
res.reserve(num);
for (size_t i = 0; i < num; i++) {
const_cast<EagerTensor*>(&(tensors[i]))
->SyncToVar(paddle::framework::proto::VarType_Type_LOD_TENSOR);
res.emplace_back(new EagerTensor(tensors[i]));
res.back()->SyncToVar(paddle::framework::proto::VarType_Type_LOD_TENSOR);
}
return res;
}
Expand All @@ -49,9 +50,8 @@ std::vector<std::shared_ptr<egr::EagerTensor>> SyncToTensors(
const egr::EagerTensor& tensor) {
// TODO(jiabin): No const cast here. We should call SyncToTensor in Python_C
// wrapper
auto egr_tensor = std::make_shared<EagerTensor>(tensor);
egr_tensor->SyncToTensor();
return {egr_tensor};
const_cast<EagerTensor*>(&tensor)->SyncToTensor();
return {std::make_shared<EagerTensor>(tensor)};
}

std::vector<std::shared_ptr<egr::EagerTensor>> SyncToTensors(
Expand All @@ -62,8 +62,8 @@ std::vector<std::shared_ptr<egr::EagerTensor>> SyncToTensors(
size_t num = tensors.size();
res.reserve(num);
for (size_t i = 0; i < num; i++) {
const_cast<EagerTensor*>(&(tensors[i]))->SyncToTensor();
res.emplace_back(new EagerTensor(tensors[i]));
res.back()->SyncToTensor();
}
return res;
}
Expand Down

1 comment on commit 3f5a7d3

@paddle-bot-old
Copy link

@paddle-bot-old paddle-bot-old bot commented on 3f5a7d3 Nov 1, 2021

Choose a reason for hiding this comment

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

🕵️ CI failures summary

🔍 PR: #36518 Commit ID: 3f5a7d3 contains failed CI.

🔹 Failed: PR-CI-iScan-Python

Unknown Failed
Unknown Failed

🔹 Failed: PR-CI-Static-Check

failed in build-docker-image job
failed in build-docker-image job

🔹 Failed: PR-CI-Windows

Unknown Failed
2021-11-01 21:04:48 Auto-merging paddle/fluid/framework/pten_utils.h
2021-11-01 21:04:48 CONFLICT (add/add): Merge conflict in paddle/fluid/framework/pten_utils.cc
2021-11-01 21:04:48 Auto-merging paddle/fluid/framework/pten_utils.cc
2021-11-01 21:04:48 Removing paddle/fluid/framework/paddle2cinn/cinn_runner_test.cc
2021-11-01 21:04:48 Removing paddle/fluid/framework/paddle2cinn/cinn_runner.h
2021-11-01 21:04:48 Removing paddle/fluid/framework/paddle2cinn/cinn_runner.cc
2021-11-01 21:04:48 Removing paddle/fluid/framework/paddle2cinn/cinn_compiled_object_test.cc
2021-11-01 21:04:48 Removing paddle/fluid/framework/paddle2cinn/cinn_compiled_object.h
2021-11-01 21:04:48 Removing paddle/fluid/framework/paddle2cinn/cinn_compiled_object.cc
2021-11-01 21:04:48 Auto-merging paddle/fluid/framework/operator.h
2021-11-01 21:04:48 CONFLICT (content): Merge conflict in paddle/fluid/framework/operator.h
2021-11-01 21:04:48 Auto-merging paddle/fluid/framework/operator.cc
2021-11-01 21:04:48 CONFLICT (content): Merge conflict in paddle/fluid/framework/operator.cc
2021-11-01 21:04:48 Auto-merging paddle/fluid/framework/details/nan_inf_utils.h
2021-11-01 21:04:48 Auto-merging paddle/fluid/framework/details/CMakeLists.txt
2021-11-01 21:04:48 Auto-merging paddle/fluid/framework/CMakeLists.txt
2021-11-01 21:04:48 CONFLICT (content): Merge conflict in paddle/fluid/framework/CMakeLists.txt
2021-11-01 21:04:48 Automatic merge failed; fix conflicts and then commit the result.
2021-11-01 21:04:48 C:\Users\Administrator\Downloads\workspace\97373a2e-8670-44b7-9581-1e49f6cb29b2\Paddle>if 1 NEQ 0 exit /b 1

🔹 Failed: PR-CI-ROCM-Compile

Unknown Failed
2021-11-01 21:08:13 Auto-merging paddle/fluid/framework/pten_utils.h
2021-11-01 21:08:13 CONFLICT (add/add): Merge conflict in paddle/fluid/framework/pten_utils.h
2021-11-01 21:08:13 Auto-merging paddle/fluid/framework/pten_utils.cc
2021-11-01 21:08:13 CONFLICT (add/add): Merge conflict in paddle/fluid/framework/pten_utils.cc
2021-11-01 21:08:13 Removing paddle/fluid/framework/paddle2cinn/cinn_runner_test.cc
2021-11-01 21:08:13 Removing paddle/fluid/framework/paddle2cinn/cinn_runner.h
2021-11-01 21:08:13 Removing paddle/fluid/framework/paddle2cinn/cinn_runner.cc
2021-11-01 21:08:13 Removing paddle/fluid/framework/paddle2cinn/cinn_compiled_object_test.cc
2021-11-01 21:08:13 Removing paddle/fluid/framework/paddle2cinn/cinn_compiled_object.h
2021-11-01 21:08:13 Removing paddle/fluid/framework/paddle2cinn/cinn_compiled_object.cc
2021-11-01 21:08:13 Auto-merging paddle/fluid/framework/operator.h
2021-11-01 21:08:13 CONFLICT (content): Merge conflict in paddle/fluid/framework/operator.h
2021-11-01 21:08:13 Auto-merging paddle/fluid/framework/operator.cc
2021-11-01 21:08:13 CONFLICT (content): Merge conflict in paddle/fluid/framework/operator.cc
2021-11-01 21:08:13 Auto-merging paddle/fluid/framework/details/nan_inf_utils.h
2021-11-01 21:08:13 Auto-merging paddle/fluid/framework/details/CMakeLists.txt
2021-11-01 21:08:13 Auto-merging paddle/fluid/framework/CMakeLists.txt
2021-11-01 21:08:13 CONFLICT (content): Merge conflict in paddle/fluid/framework/CMakeLists.txt
2021-11-01 21:08:13 Automatic merge failed; fix conflicts and then commit the result.

🔹 Failed: PR-CI-musl

Unknown Failed
2021-11-01 21:28:25 Auto-merging paddle/fluid/framework/pten_utils.h
2021-11-01 21:28:25 CONFLICT (add/add): Merge conflict in paddle/fluid/framework/pten_utils.h
2021-11-01 21:28:25 Auto-merging paddle/fluid/framework/pten_utils.cc
2021-11-01 21:28:25 CONFLICT (add/add): Merge conflict in paddle/fluid/framework/pten_utils.cc
2021-11-01 21:28:25 Removing paddle/fluid/framework/paddle2cinn/cinn_runner_test.cc
2021-11-01 21:28:25 Removing paddle/fluid/framework/paddle2cinn/cinn_runner.h
2021-11-01 21:28:25 Removing paddle/fluid/framework/paddle2cinn/cinn_runner.cc
2021-11-01 21:28:25 Removing paddle/fluid/framework/paddle2cinn/cinn_compiled_object_test.cc
2021-11-01 21:28:25 Removing paddle/fluid/framework/paddle2cinn/cinn_compiled_object.h
2021-11-01 21:28:25 Removing paddle/fluid/framework/paddle2cinn/cinn_compiled_object.cc
2021-11-01 21:28:25 Auto-merging paddle/fluid/framework/operator.h
2021-11-01 21:28:25 CONFLICT (content): Merge conflict in paddle/fluid/framework/operator.h
2021-11-01 21:28:25 Auto-merging paddle/fluid/framework/operator.cc
2021-11-01 21:28:25 CONFLICT (content): Merge conflict in paddle/fluid/framework/operator.cc
2021-11-01 21:28:25 Auto-merging paddle/fluid/framework/details/nan_inf_utils.h
2021-11-01 21:28:25 Auto-merging paddle/fluid/framework/details/CMakeLists.txt
2021-11-01 21:28:25 Auto-merging paddle/fluid/framework/CMakeLists.txt
2021-11-01 21:28:25 CONFLICT (content): Merge conflict in paddle/fluid/framework/CMakeLists.txt
2021-11-01 21:28:25 Automatic merge failed; fix conflicts and then commit the result.

🔹 Failed: PR-CI-Kunlun

Unknown Failed
2021-11-01 21:29:36 自动合并 paddle/fluid/framework/pten_utils.h
2021-11-01 21:29:36 冲突(添加/添加):合并冲突于 paddle/fluid/framework/pten_utils.h
2021-11-01 21:29:36 自动合并 paddle/fluid/framework/pten_utils.cc
2021-11-01 21:29:36 冲突(添加/添加):合并冲突于 paddle/fluid/framework/pten_utils.cc
2021-11-01 21:29:36 删除 paddle/fluid/framework/paddle2cinn/cinn_runner_test.cc
2021-11-01 21:29:36 删除 paddle/fluid/framework/paddle2cinn/cinn_runner.h
2021-11-01 21:29:36 删除 paddle/fluid/framework/paddle2cinn/cinn_runner.cc
2021-11-01 21:29:36 删除 paddle/fluid/framework/paddle2cinn/cinn_compiled_object_test.cc
2021-11-01 21:29:36 删除 paddle/fluid/framework/paddle2cinn/cinn_compiled_object.h
2021-11-01 21:29:36 删除 paddle/fluid/framework/paddle2cinn/cinn_compiled_object.cc
2021-11-01 21:29:36 自动合并 paddle/fluid/framework/operator.h
2021-11-01 21:29:36 冲突(内容):合并冲突于 paddle/fluid/framework/operator.h
2021-11-01 21:29:36 自动合并 paddle/fluid/framework/operator.cc
2021-11-01 21:29:36 冲突(内容):合并冲突于 paddle/fluid/framework/operator.cc
2021-11-01 21:29:36 自动合并 paddle/fluid/framework/details/nan_inf_utils.h
2021-11-01 21:29:36 自动合并 paddle/fluid/framework/details/CMakeLists.txt
2021-11-01 21:29:36 自动合并 paddle/fluid/framework/CMakeLists.txt
2021-11-01 21:29:36 冲突(内容):合并冲突于 paddle/fluid/framework/CMakeLists.txt
2021-11-01 21:29:36 自动合并失败,修正冲突然后提交修正的结果。

🔹 Failed: PR-CI-Mac-Python3

Unknown Failed
2021-11-01 21:38:33 自动合并 paddle/fluid/framework/pten_utils.h
2021-11-01 21:38:33 冲突(添加/添加):合并冲突于 paddle/fluid/framework/pten_utils.h
2021-11-01 21:38:33 自动合并 paddle/fluid/framework/pten_utils.cc
2021-11-01 21:38:33 冲突(添加/添加):合并冲突于 paddle/fluid/framework/pten_utils.cc
2021-11-01 21:38:33 删除 paddle/fluid/framework/paddle2cinn/cinn_runner_test.cc
2021-11-01 21:38:33 删除 paddle/fluid/framework/paddle2cinn/cinn_runner.h
2021-11-01 21:38:33 删除 paddle/fluid/framework/paddle2cinn/cinn_runner.cc
2021-11-01 21:38:33 删除 paddle/fluid/framework/paddle2cinn/cinn_compiled_object_test.cc
2021-11-01 21:38:33 删除 paddle/fluid/framework/paddle2cinn/cinn_compiled_object.h
2021-11-01 21:38:33 删除 paddle/fluid/framework/paddle2cinn/cinn_compiled_object.cc
2021-11-01 21:38:33 自动合并 paddle/fluid/framework/operator.h
2021-11-01 21:38:33 冲突(内容):合并冲突于 paddle/fluid/framework/operator.h
2021-11-01 21:38:33 自动合并 paddle/fluid/framework/operator.cc
2021-11-01 21:38:33 冲突(内容):合并冲突于 paddle/fluid/framework/operator.cc
2021-11-01 21:38:33 自动合并 paddle/fluid/framework/details/nan_inf_utils.h
2021-11-01 21:38:33 自动合并 paddle/fluid/framework/details/CMakeLists.txt
2021-11-01 21:38:33 自动合并 paddle/fluid/framework/CMakeLists.txt
2021-11-01 21:38:33 冲突(内容):合并冲突于 paddle/fluid/framework/CMakeLists.txt
2021-11-01 21:38:33 自动合并失败,修正冲突然后提交修正的结果。

🔹 Failed: PR-CI-NPU

Unknown Failed
2021-11-01 22:12:31 Auto-merging paddle/fluid/framework/pten_utils.h
2021-11-01 22:12:31 CONFLICT (add/add): Merge conflict in paddle/fluid/framework/pten_utils.h
2021-11-01 22:12:31 Auto-merging paddle/fluid/framework/pten_utils.cc
2021-11-01 22:12:31 CONFLICT (add/add): Merge conflict in paddle/fluid/framework/pten_utils.cc
2021-11-01 22:12:31 Removing paddle/fluid/framework/paddle2cinn/cinn_runner_test.cc
2021-11-01 22:12:31 Removing paddle/fluid/framework/paddle2cinn/cinn_runner.h
2021-11-01 22:12:31 Removing paddle/fluid/framework/paddle2cinn/cinn_runner.cc
2021-11-01 22:12:31 Removing paddle/fluid/framework/paddle2cinn/cinn_compiled_object_test.cc
2021-11-01 22:12:31 Removing paddle/fluid/framework/paddle2cinn/cinn_compiled_object.h
2021-11-01 22:12:31 Removing paddle/fluid/framework/paddle2cinn/cinn_compiled_object.cc
2021-11-01 22:12:31 Auto-merging paddle/fluid/framework/operator.h
2021-11-01 22:12:31 CONFLICT (content): Merge conflict in paddle/fluid/framework/operator.h
2021-11-01 22:12:31 Auto-merging paddle/fluid/framework/operator.cc
2021-11-01 22:12:31 CONFLICT (content): Merge conflict in paddle/fluid/framework/operator.cc
2021-11-01 22:12:31 Auto-merging paddle/fluid/framework/details/nan_inf_utils.h
2021-11-01 22:12:31 Auto-merging paddle/fluid/framework/details/CMakeLists.txt
2021-11-01 22:12:31 Auto-merging paddle/fluid/framework/CMakeLists.txt
2021-11-01 22:12:31 CONFLICT (content): Merge conflict in paddle/fluid/framework/CMakeLists.txt
2021-11-01 22:12:31 Automatic merge failed; fix conflicts and then commit the result.

Please sign in to comment.