-
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] Support while grad exe #59496
Merged
zhangbo9674
merged 40 commits into
PaddlePaddle:develop
from
zhangbo9674:dev/pir_while_exe
Dec 1, 2023
Merged
[PIR] Support while grad exe #59496
Changes from 34 commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
b5c82b4
support lower to kernel for if_grad op
chen2016013 8279d42
add PD_DECLARE_KERNEL
chen2016013 a395203
fix
chen2016013 2c9ad7c
fix
chen2016013 9c0c2ae
fix
chen2016013 62633df
merge
chen2016013 34ce4b1
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
chen2016013 44885af
resolve conflict
chen2016013 796c10f
resolve conflict
chen2016013 cc99d1f
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
chen2016013 d410461
update
chen2016013 e0e6bc7
update
chen2016013 f10592d
update
chen2016013 eb2db16
update
chen2016013 ca073ca
update
chen2016013 1955bd9
update
chen2016013 155ece7
fix
zhangbo9674 428fcf3
update
chen2016013 c4909ea
update
chen2016013 121077c
solve conflicts
chen2016013 3f48d26
update
chen2016013 98ca4ac
resolve conflicts
chen2016013 3783545
update
chen2016013 811ebd2
update
chen2016013 edf124d
update
chen2016013 f06de5c
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
chen2016013 7e19d9e
update
chen2016013 fa619bc
update
chen2016013 6d6647a
fix bugs and warnings
chen2016013 c264973
Merge commit 'refs/pull/59200/head' of https://github.com/PaddlePaddl…
zhangbo9674 2687fbb
fix
zhangbo9674 47c4d5e
fix
zhangbo9674 d9cbb35
fix
zhangbo9674 296ef3f
fix
zhangbo9674 ddc2516
fix
zhangbo9674 234482f
fix
zhangbo9674 645443a
fix conflict
zhangbo9674 066727e
fix
zhangbo9674 48be391
fix
zhangbo9674 7340d73
fix
zhangbo9674 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
10 changes: 8 additions & 2 deletions
10
paddle/fluid/framework/new_executor/instruction/CMakeLists.txt
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
63 changes: 63 additions & 0 deletions
63
paddle/fluid/framework/new_executor/instruction/has_elements_instruction.cc
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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "paddle/fluid/framework/new_executor/instruction/has_elements_instruction.h" | ||
#include "paddle/fluid/framework/new_executor/instruction/instruction_util.h" | ||
#include "paddle/fluid/framework/new_executor/pir_adaptor/pir_adaptor_util.h" | ||
#include "paddle/fluid/pir/dialect/operator/ir/control_flow_op.h" | ||
|
||
namespace paddle { | ||
namespace framework { | ||
HasElementsInstruction::HasElementsInstruction( | ||
size_t id, | ||
const platform::Place& place, | ||
::pir::Operation* op, | ||
ValueExecutionInfo* value_exe_info) | ||
: InstructionBase(id, place), op_(op), value_exe_info_(value_exe_info) { | ||
auto has_elements_op = op->dyn_cast<paddle::dialect::HasElementsOp>(); | ||
VLOG(6) << "construct has_elements instruction for: " | ||
<< has_elements_op->name(); | ||
|
||
std::unordered_map<pir::Value, std::vector<int>> outputs; | ||
outputs.emplace(has_elements_op.out(), | ||
GetValueIds(has_elements_op.out(), *value_exe_info_)); | ||
SetOutputs(outputs); | ||
|
||
std::unordered_map<pir::Value, std::vector<int>> inputs; | ||
std::vector<int> inputs_id = { | ||
value_exe_info_->GetVarId(has_elements_op.input())}; | ||
inputs.emplace(has_elements_op.input(), inputs_id); | ||
SetInputs(inputs); | ||
|
||
type_ = OpFuncType::kCpuSync; | ||
|
||
platform::DeviceContextPool& pool = platform::DeviceContextPool::Instance(); | ||
auto* bool_tensor = value_exe_info_->GetVarByValue(op_->result(0)) | ||
->GetMutable<phi::DenseTensor>(); | ||
bool_tensor->Resize(phi::make_ddim({1})); | ||
has_elements_ = pool.Get(platform::CPUPlace())->Alloc<bool>(bool_tensor); | ||
|
||
auto stack_value = | ||
op_->dyn_cast<paddle::dialect::HasElementsOp>().operand_source(0); | ||
auto var_array = value_exe_info_->GetVarByValue(stack_value); | ||
stack_element_var_array_ = var_array->GetMutable<VariableRefArray>(); | ||
} | ||
|
||
void HasElementsInstruction::Run() { | ||
VLOG(6) << "run has_elements instruction"; | ||
bool is_empty = stack_element_var_array_->size(); | ||
*has_elements_ = is_empty; | ||
} | ||
} // namespace framework | ||
} // namespace paddle |
57 changes: 57 additions & 0 deletions
57
paddle/fluid/framework/new_executor/instruction/has_elements_instruction.h
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#pragma once | ||
|
||
#include <string> | ||
#include "paddle/fluid/framework/new_executor/instruction/instruction_base.h" | ||
#include "paddle/fluid/framework/new_executor/new_executor_defs.h" | ||
#include "paddle/fluid/framework/tensor_ref_array.h" | ||
#include "paddle/pir/dialect/control_flow/ir/cf_op.h" | ||
|
||
namespace paddle { | ||
namespace framework { | ||
class ValueExecutionInfo; | ||
|
||
class HasElementsInstruction : public InstructionBase { | ||
public: | ||
HasElementsInstruction(size_t id, | ||
const platform::Place& place, | ||
::pir::Operation* op, | ||
ValueExecutionInfo* value_exe_info); | ||
|
||
void Run() override; | ||
|
||
const std::string& Name() const override { return name_; } | ||
|
||
::pir::Operation* Operation() const override { return op_; } | ||
|
||
private: | ||
::pir::Operation* op_; | ||
|
||
OpFuncType type_; | ||
|
||
std::string name_{"has_elelments_instruction"}; | ||
|
||
// const platform::DeviceContext* dev_ctx_; // not owned | ||
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. 之后可以删除 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. 已删除 |
||
|
||
ValueExecutionInfo* value_exe_info_; // not owned | ||
|
||
VariableRefArray* stack_element_var_array_; // not owned | ||
|
||
bool* has_elements_; // not owned | ||
}; | ||
|
||
} // namespace framework | ||
} // namespace paddle |
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
Oops, something went wrong.
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.
这个 stack_element_var_array_没有empty接口吗?调用size(),返回bool值感觉有点奇怪
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.
好建议,目前没有,后面我添加一下