Skip to content

Conversation

@reyoung
Copy link
Collaborator

@reyoung reyoung commented Jan 5, 2018

It will be used for LoD information in LoDTensor since LoD is a copy
on write field.

It is pretty slow for copying LoD information between operators. For
resnet it will cost roughly 10% time of whole time, including reading
data.

Related issue #7239

@reyoung reyoung requested a review from qingqing01 January 5, 2018 07:38
@reyoung reyoung force-pushed the feature/make_lod_a_share_ptr branch 2 times, most recently from aa4a6aa to d2a521e Compare January 5, 2018 07:50
It will be used for LoD information in LoDTensor since LoD is a copy
on write field.

It is pretty slow for copying LoD information between operators. For
resnet it will cost roughly 10% time of whole time, including reading
data.
@reyoung reyoung force-pushed the feature/make_lod_a_share_ptr branch from d2a521e to 0cfb546 Compare January 5, 2018 08:41
ThreadUnsafeOwnershipFlags(const ThreadUnsafeOwnershipFlags& o) = delete;
ThreadUnsafeOwnershipFlags& operator=(const ThreadUnsafeOwnershipFlags& o) =
delete;
ThreadUnsafeOwnershipFlags(ThreadUnsafeOwnershipFlags&& o) = default;
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
Collaborator Author

Choose a reason for hiding this comment

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

They are not exactly same. OwnershipFlag just disable copy constructor, but enable move constructor.

bool flag_;
};

// Copy On Write pointer.
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy On Write -> Copy-On-Write https://en.wikipedia.org/wiki/Copy-on-write

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

explicit COWPtr(T* ptr) : payload_(ptr), ownership_{true} {}

// Move methods. Steal ownership from origin
COWPtr(COWPtr&& o)
Copy link
Contributor

Choose a reason for hiding this comment

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

What does the o mean? owner? a more meaningful name is needed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

o means other


private:
std::shared_ptr<T> payload_;
OwnershipFlags ownership_;
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add comments for payload_ and ownership_.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

void Reset() {
ownership_.AcquireOwnershipOnce([this] { payload_.reset(); });
payload_.reset(new T());
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I can understand the AcquireOwnershipOnce, MutableData, Reset functions from the unit test. Maybe better to add comments for these function.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

Also, remove the Reset method. Reset is not necessary because we can create a new COWPtr, and assign it to origin COWPtr. The effect is same as Reset.

Copy link
Contributor

@qingqing01 qingqing01 left a comment

Choose a reason for hiding this comment

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

LGTM.

@reyoung reyoung merged commit 6e3cc0c into PaddlePaddle:develop Jan 8, 2018
@reyoung reyoung deleted the feature/make_lod_a_share_ptr branch January 22, 2018 04:11
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.

2 participants