Skip to content

Conversation

@JiayiFeng
Copy link
Collaborator

@JiayiFeng JiayiFeng commented Jul 15, 2017

paddle::memory is merged, so I enable tenor's tests.
Because of some interface changes, tensor's current code might be a little rough. I will keep polishing it.

paddle::platform::Place place_; // record the place of ptr_.
size_t size_; // size of the memory block.
std::unique_ptr<T, Deleter<PlaceType>> ptr_;
platform::Place place_; // record the place of ptr_.
Copy link
Member

@QiJune QiJune Jul 17, 2017

Choose a reason for hiding this comment

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

Since PlaceholderImpl has a template parameter PlaceType, why we need platform::Place here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

GPUPlace(0), GPUPlace(1), they are different.

Copy link
Member

Choose a reason for hiding this comment

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

GPUPlace and CPUPlace are two different class types. But GPUPlace(0) and GPUPlace(1) are the same class type.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Correct. So if we remove platform::Place place_ and only retain template parameter PlaceType, PlaceholderImpl is not able to distinguish GPUPlace(0) and GPUPlace(1).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

With platform::Place here we can easily use == to check two place in mutable_data() and data().

cc_test(ddim_test SRCS ddim_test.cc DEPS ddim)
nv_test(dim_test SRCS dim_test.cu DEPS ddim)
cc_test(tensor_test SRCS tensor_test.cc DEPS ddim)
cc_test(tensor_test SRCS tensor_test.cc DEPS ddim place paddle_memory)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please update develop, because this lines are changed.

template <typename T, typename PlaceType>
struct PlaceholderImpl : public Placeholder {
private:
template <typename PType>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is that PType useful? Maybe in Deleter, we can also use PlaceType

size_t numel_; // cache of `product(dims_)`
size_t offset_; // marks the begin of tensor data area.
};
}; // namespace framework
Copy link
Collaborator

Choose a reason for hiding this comment

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

above line seems to be a typo.

place) /* some versions of boost::variant don't have operator!= */
|| holder_->size() < numel_ * sizeof(T) + offset_) {
holder_.reset(new PlaceholderImpl<T>(place, numel_ * sizeof(T)));
#ifdef __CUDACC__
Copy link
Collaborator

Choose a reason for hiding this comment

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

#ifdef PADDLE_ONLY_GPU, use that macro.

boost::get<platform::CPUPlace>(place), numel_ * sizeof(T)));
break;
}
#else
Copy link
Collaborator

Choose a reason for hiding this comment

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

if (is_cpu_place(place)) {
  holder_.reset(...)
} else if (is_gpu_place(place)) {
#ifdef PADDLE_ONLY_CPU
  PADDLE_THROW("GPU is not enabled");
#else
  holder_.reset(...)
#endif
} else {
  PADDLE_THROW("not supported device.")
}

Copy link
Collaborator

@reyoung reyoung left a comment

Choose a reason for hiding this comment

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

Please complete this PR asap, because expose Tensor to Python needs this PR.

Copy link
Collaborator

@reyoung reyoung left a comment

Choose a reason for hiding this comment

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

Because it blocks other development, just LGTM now, but need modify later.

@JiayiFeng JiayiFeng merged commit 1480720 into PaddlePaddle:develop Jul 17, 2017
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.

3 participants