-
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
Simplify Tensor implementation #2964
Simplify Tensor implementation #2964
Conversation
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) { |
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.
感觉 ShareDataWith
名字有待商榷,当前的share是有方向的(原来的好点)。
this->ShareDataWith(other)
意思是 share something with other,感觉是 something owned by this
shared to others, 但事实上是反着的。
当前share是区分方向的,比如 empty_tensor.ShareDataWith(real_tensor)
是可以的,但反之不行。
@wangkuiyi
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.
也许下面的API,对于用户可能更容易理解?
Tensor a(...);
Tensor b = a.shared<T>();
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.
empty_tensor.ShareDataWith(nonempty)
是可以被调用的,只是调用过程中检查 empty_tensor 是否是emtpy的。
paddle/memory/memory.h
Outdated
@@ -28,5 +28,15 @@ void Free(Place, void*); | |||
template <class Place> | |||
size_t Used(Place); | |||
|
|||
template <typename T, typename PlaceType> |
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.
PlaceType ==> Place ?
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.
我的考虑是,Place可能会和boost::variant的那个Place类型混淆,用PlaceType来明确指出这个是CPUPlace或者GPUPlace
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.
不会混淆,因为这里有 typename 前缀。可以写
template <typename T, typename Place /* platform::GPUPlace or platform::CPUPlace */ >
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.
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) { |
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.
empty_tensor.ShareDataWith(nonempty)
是可以被调用的,只是调用过程中检查 empty_tensor 是否是emtpy的。
paddle/framework/tensor.h
Outdated
PlaceholderImpl(PlaceType place, size_t size) | ||
: ptr_(static_cast<T*>(memory::Alloc(place, size)), | ||
Deleter<PlaceType>(place)), | ||
memory::PodDeleter<T, PlaceType>(place)), |
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.
Pod => POD. 英语缩写用大写
一个更合适的做法是用 class decorator 指定 PODDeleter 只能作用于 T 是 POD 的情况。具体做法可以问 @gangliao gang。
paddle/memory/memory.h
Outdated
@@ -28,5 +28,15 @@ void Free(Place, void*); | |||
template <class Place> | |||
size_t Used(Place); | |||
|
|||
template <typename T, typename PlaceType> |
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.
不会混淆,因为这里有 typename 前缀。可以写
template <typename T, typename Place /* platform::GPUPlace or platform::CPUPlace */ >
… dev_refactor_tensor
1. Change PODDeleter's template parameter 'PlaceType' to 'Place'. 2. Limit PODDeleter and Tensor::mutable_data()'s `T` to POD type.
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.
LGTM
ATTENTION: some interfaces changed:
fix #2929