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

Simplify Tensor implementation #2964

Merged
merged 5 commits into from
Jul 21, 2017

Conversation

JiayiFeng
Copy link
Collaborator

@JiayiFeng JiayiFeng commented Jul 19, 2017

ATTENTION: some interfaces changed:

1.  void Tensor::set_dims(const DDim& dims) ==> void Tensor::Resize(const DDim& dims).
2. void Tensor::ShareDataFrom(const Tensor& src)  ==> void Tensor::ShareDataWith(const Tensor& src)
3. DDim Tensor::dims() const ==> const DDim& Tensor::dims() const

fix #2929

ATTENTION: some interfaces changed:
1. void Tensor::set_dims(const DDim& dims) ==> void Tensor::Resize(const DDim& dims).
2. void Tensor::ShareDataFrom(const Tensor& src)  ==> void Tensor::ShareDataWith(const Tensor& src)
3. DDim Tensor::dims() const ==> const DDim& Tensor::dims() const
holder_ = src.holder_;
set_dims(src.dims());
offset_ = src.offset_;
void ShareDataWith(const Tensor& src) {
Copy link
Contributor

@Superjomn Superjomn Jul 19, 2017

Choose a reason for hiding this comment

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

感觉 ShareDataWith 名字有待商榷,当前的share是有方向的(原来的好点)。

this->ShareDataWith(other) 意思是 share something with other,感觉是 something owned by this shared to others, 但事实上是反着的。

当前share是区分方向的,比如 empty_tensor.ShareDataWith(real_tensor) 是可以的,但反之不行。
@wangkuiyi

Copy link
Collaborator

Choose a reason for hiding this comment

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

也许下面的API,对于用户可能更容易理解?

Tensor a(...);
Tensor b = a.shared<T>();

Copy link
Collaborator

Choose a reason for hiding this comment

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

empty_tensor.ShareDataWith(nonempty) 是可以被调用的,只是调用过程中检查 empty_tensor 是否是emtpy的。

@@ -28,5 +28,15 @@ void Free(Place, void*);
template <class Place>
size_t Used(Place);

template <typename T, typename PlaceType>
Copy link
Member

Choose a reason for hiding this comment

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

PlaceType ==> Place ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

我的考虑是,Place可能会和boost::variant的那个Place类型混淆,用PlaceType来明确指出这个是CPUPlace或者GPUPlace

Copy link
Collaborator

Choose a reason for hiding this comment

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

不会混淆,因为这里有 typename 前缀。可以写

template <typename T, typename Place /* platform::GPUPlace or platform::CPUPlace */ >

Copy link
Collaborator

@wangkuiyi wangkuiyi left a comment

Choose a reason for hiding this comment

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

A minor suggestion about typename Place instead of typename PlaceType; Otherwise LGTM.

holder_ = src.holder_;
set_dims(src.dims());
offset_ = src.offset_;
void ShareDataWith(const Tensor& src) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

empty_tensor.ShareDataWith(nonempty) 是可以被调用的,只是调用过程中检查 empty_tensor 是否是emtpy的。

PlaceholderImpl(PlaceType place, size_t size)
: ptr_(static_cast<T*>(memory::Alloc(place, size)),
Deleter<PlaceType>(place)),
memory::PodDeleter<T, PlaceType>(place)),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Pod => POD. 英语缩写用大写

一个更合适的做法是用 class decorator 指定 PODDeleter 只能作用于 T 是 POD 的情况。具体做法可以问 @gangliao gang。

@@ -28,5 +28,15 @@ void Free(Place, void*);
template <class Place>
size_t Used(Place);

template <typename T, typename PlaceType>
Copy link
Collaborator

Choose a reason for hiding this comment

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

不会混淆,因为这里有 typename 前缀。可以写

template <typename T, typename Place /* platform::GPUPlace or platform::CPUPlace */ >

1. Change PODDeleter's template parameter 'PlaceType' to 'Place'.

2. Limit PODDeleter and Tensor::mutable_data()'s `T` to POD type.
Copy link
Collaborator

@wangkuiyi wangkuiyi left a comment

Choose a reason for hiding this comment

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

LGTM

@wangkuiyi wangkuiyi merged commit 6129ab4 into PaddlePaddle:develop Jul 21, 2017
@JiayiFeng JiayiFeng deleted the dev_refactor_tensor branch August 1, 2017 18:55
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.

paddle::framework::Tensor design issues
5 participants