-
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
[PIR] add python api for if #60895
Merged
Merged
[PIR] add python api for if #60895
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -215,8 +215,36 @@ void IfInstruction::CopyBranchOutput(const std::vector<std::string>& var_names, | |
} | ||
|
||
void IfInstruction::Run() { | ||
DeviceContext().Wait(); | ||
if (cond_var_->Get<phi::DenseTensor>().data<bool>()[0]) { | ||
bool cond = true; | ||
if (cond_var_->IsType<phi::DenseTensor>()) { | ||
auto& cond_tensor = cond_var_->Get<phi::DenseTensor>(); | ||
if (paddle::platform::is_cpu_place(cond_tensor.place())) { | ||
cond = cond_tensor.data<bool>()[0]; | ||
} else { | ||
// when platform::is_gpu_place(cond.place()) or | ||
// platform::is_xpu_place(cond.place()) is true | ||
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || \ | ||
defined(PADDLE_WITH_XPU) || defined(PADDLE_WITH_CUSTOM_DEVICE) | ||
DeviceContext().Wait(); | ||
phi::DenseTensor cpu_cond; | ||
paddle::framework::TensorCopySync( | ||
cond_tensor, platform::CPUPlace(), &cpu_cond); | ||
cond = cpu_cond.data<bool>()[0]; | ||
#else | ||
PADDLE_THROW(paddle::platform::errors::PreconditionNotMet( | ||
"This version of PaddlePaddle does NOT support GPU/XPU but got " | ||
"GPU/XPU tensor Cond in WhileOp. Please compile WITH_GPU or " | ||
"WITH_XPU option.")); | ||
#endif | ||
} | ||
} else if (cond_var_->IsType<VariableRefArray>()) { | ||
auto& cond_array = cond_var_->Get<VariableRefArray>(); | ||
cond = std::all_of( | ||
cond_array.begin(), cond_array.end(), [](const Variable* t) { | ||
return t->Get<phi::DenseTensor>().numel() != 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. t 一定是 DenseTensor么,最好加一个检查?另外这里的判断逻辑就是要用tensor 的 numel 来判断么? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
}); | ||
} | ||
if (cond) { | ||
true_branch_inter_->Run({}, false); | ||
CopyBranchOutput(true_branch_outputs_, true_branch_inter_); | ||
} else { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
does NOT support GPU/XPU ?
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.
这个目前是跟while的判定逻辑对齐的。