Skip to content
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
merged 40 commits into from
Dec 1, 2023

Conversation

zhangbo9674
Copy link
Contributor

PR types

New features

PR changes

Others

Description

支持 while grad 执行
Pcard-67164

@@ -44,11 +44,13 @@ class HasElementsInstruction : public InstructionBase {

std::string name_{"has_elelments_instruction"};

const platform::DeviceContext* dev_ctx_; // not owned
// const platform::DeviceContext* dev_ctx_; // not owned
Copy link
Contributor

Choose a reason for hiding this comment

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

之后可以删除

Copy link
Contributor Author

Choose a reason for hiding this comment

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

已删除

uint64_t num) {
std::stack<const Variable*> rtn;
for (uint64_t i = 0; i < num; i++) {
rtn.push(var_array->at(var_array->size() - 1));
Copy link
Contributor

Choose a reason for hiding this comment

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

这里每次都要压栈一遍,后续可以优化一下

Copy link
Contributor

Choose a reason for hiding this comment

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

push var_array的最后一个元素,是不是可以给var_array提供一个back()接口?

/// ...
/// }
///
class IR_API HasElementsOp : public pir::Op<HasElementsOp> {
Copy link
Contributor

Choose a reason for hiding this comment

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

都移到上面了,这个IR_API是不是可以删了?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

是的,单独提 PR 完善~

/// in the While usage scenario. Example:
/// (%stack_0, %inlet_0, %outlet_0) = "cf.create_stack" ()
/// ...
/// (%0) = "cf.has_elements" (%stack_0)
Copy link
Contributor

Choose a reason for hiding this comment

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

pd_op.has_elements

Copy link
Contributor Author

Choose a reason for hiding this comment

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

好的,单独提 PR 完善~

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();
Copy link
Contributor

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值感觉有点奇怪

Copy link
Contributor Author

Choose a reason for hiding this comment

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

好建议,目前没有,后面我添加一下

winter-wang
winter-wang previously approved these changes Nov 30, 2023
Copy link
Contributor

@winter-wang winter-wang left a comment

Choose a reason for hiding this comment

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

LGTM

@zhangbo9674 zhangbo9674 requested a review from From00 November 30, 2023 11:07
IR_ENFORCE(num_results() == 1u, "The size of outputs must be equal to 1.");
IR_ENFORCE((*this)->result_type(0).isa<DenseTensorType>() ||
(*this)->result_type(0).isa<AllocatedDenseTensorType>(),
"The type of cf.has_elements' output is not correct.");
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"The type of cf.has_elements' output is not correct.");
"The type of pd_op.has_elements' output is not correct.");

Copy link
Contributor Author

Choose a reason for hiding this comment

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

好的,下一个pr fix

@zhangbo9674 zhangbo9674 merged commit 640802b into PaddlePaddle:develop Dec 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants