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

refine device_context #2814

Merged
merged 12 commits into from
Jul 12, 2017

Conversation

QiJune
Copy link
Member

@QiJune QiJune commented Jul 12, 2017

No description provided.

@QiJune QiJune changed the title split device_context into device_context and cuda_device_context refine device_context Jul 12, 2017
@QiJune QiJune force-pushed the feature/refine_device_context branch from a15eab4 to ca23d86 Compare July 12, 2017 07:10
GPUPlaceGuard guard(gpu_place_);
paddle::platform::throw_on_error(cudaStreamCreate(&stream_),
"cudaStreamCreate failed");
eigen_stream_ = new Eigen::CudaStreamDevice(&stream_);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe std::unique_ptr is a better idea?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done


cudaStream_t stream() { return stream_; }

Eigen::GpuDevice eigen_device() { return *eigen_device_; }
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe return a reference or pointer is better? because Eigen::GpuDevice's copy ctor is invoked when eigen_device is invoked.

Copy link
Member Author

Choose a reason for hiding this comment

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

Eigen::GpuDevice only contains a pointer and int, so return by value is acceptable


template <>
Eigen::GpuDevice DeviceContext::get_eigen_device<Eigen::GpuDevice>() {
return dynamic_cast<CUDADeviceContext*>(this)->eigen_device();
Copy link
Collaborator

Choose a reason for hiding this comment

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

dynamic_cast --> reinterpret_cast.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done


cudnnHandle_t dnn_handle_{nullptr};

int random_seed_;
Copy link
Collaborator

Choose a reason for hiding this comment

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

random_seed_ cannot be set or not properly initialized?

Copy link
Member Author

@QiJune QiJune Jul 12, 2017

Choose a reason for hiding this comment

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

I check the cuRand doc.

Set the seed value of the pseudorandom number generator. All values of seed are valid. Different seeds will produce different sequences. Different seeds will often not be statistically correlated with each other, but some pairs of seed values may generate sequences which are statistically correlated.

So, the random_seed_ can be any value. And caffe2 does so.

paddle::platform::SetDeviceId(new_place.device);
Eigen::DefaultDevice eigen_device() {
if (!eigen_device_) {
eigen_device_ = new Eigen::DefaultDevice();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, unique_ptr is better.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

explicit GPUPlaceGuard(GPUPlace new_place) : previous_(GetCurrentDeviceId()) {
if (previous_ != new_place) {
paddle::platform::SetDeviceId(new_place.device);
Eigen::DefaultDevice eigen_device() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

return a reference.

Copy link
Member Author

Choose a reason for hiding this comment

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

Eigen::DefaultDevice have no data member. So it's fine to return by value


cc_library(device_context SRCS device_context.cc DEPS place eigen3 ${GPU_CTX_DEPS})
Copy link
Collaborator

Choose a reason for hiding this comment

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

Make device_context a library is a better idea, otherwise, each library which deps on device_context should handle complex GPU libraries.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

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.

LGTM, except bad commit message. Please make the merge commit a better commit message.

@reyoung reyoung merged commit 555b0a7 into PaddlePaddle:develop Jul 12, 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.

None yet

2 participants