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

Refactorize Scope #3116

Merged
merged 8 commits into from
Aug 1, 2017
Merged

Refactorize Scope #3116

merged 8 commits into from
Aug 1, 2017

Conversation

wangkuiyi
Copy link
Collaborator

@wangkuiyi wangkuiyi commented Jul 30, 2017

Fixes #3113
Fixes #3114
Fixes #3115
Fixes #3117

@wangkuiyi
Copy link
Collaborator Author

recurrent_network_op.{h,cc} is using the shared_ptr syntax of the current Scope implementation. I need to change this part to use Scope::NewScope before this PR could pass CI.

}

Variable* Scope::NewVar() {
return NewVar(string::Sprintf("%p.%d", this, vars_.size()));
Copy link
Member

Choose a reason for hiding this comment

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

It seems use vars_.size() as the unique key is not so good? why not atmoic or timestamp?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think scope address + the offset of the variable in this scope would be enough to uniquely identify the variable, isn't it?

@@ -107,11 +107,11 @@ class Scope {
```
## Only scope can create a variable

To ensure `only scope can create a variable`, we should mark `Variable`'s constructor as a private member function, and Scope is a friend class of Variable. And then only `CreateVariable` can construct `Variable`.
To ensure `only scope can create a variable`, we should mark `Variable`'s constructor as a private member function, and Scope is a friend class of Variable. And then only `NewVar` can construct `Variable`.
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

@Superjomn Superjomn Jul 31, 2017

Choose a reason for hiding this comment

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

not only Variable, but alsoOperator, Tensor andScope should all be DISALLOW_COPY_AND_ASSIGN, this macro will make default and copy constructor = delete.

explicit Scope(Scope* parent) : parent_(parent) {}

std::map<std::string, Variable*> vars_;
std::list<Scope*> kids_;
Copy link
Member

Choose a reason for hiding this comment

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

why should we store kid scope and how can we use them?
In this PR, it seems that we will have a global default scope and all other scopes will be stored and deleted by this Scope if itself is deleted.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You are right. The purpose of addingkids_ is to manage the lifecycle of Scopes.

@reyoung reyoung merged commit db3fd34 into PaddlePaddle:develop Aug 1, 2017
heavengate pushed a commit to heavengate/Paddle that referenced this pull request Aug 16, 2021
* Automatically set use_dynamic_shape
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.

4 participants