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

Executor need reasonable default value #5681

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions paddle/pybind/pybind.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ bool IsCompileGPU() {
#endif
}

int GetCUDADeviceCount() {
#ifndef PADDLE_WITH_CUDA
return 0;
Copy link
Contributor

@helinwang helinwang Nov 15, 2017

Choose a reason for hiding this comment

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

Maybe return -1 here to indicate error. Because the function name is GetCUDADeviceCount, if PADDLE_WITH_CUDA is OFF, the function can not do what its name suggests.

#else
return paddle::platform::GetCUDADeviceCount();
#endif
}

PYBIND11_PLUGIN(core) {
py::module m("core", "C++ core of PaddlePaddle");

Expand Down Expand Up @@ -497,6 +505,7 @@ All parameter, weight, gradient are variables in Paddle.
m.def("init_gflags", InitGflags);

m.def("is_compile_gpu", IsCompileGPU);
m.def("get_cuda_device_count", GetCUDADeviceCount());
Copy link
Contributor

Choose a reason for hiding this comment

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

Not familiar with Pybind, why it's a function invocation here? GetCUDADeviceCount(), rather than GetCUDADeviceCount?

Copy link
Author

Choose a reason for hiding this comment

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

It is a bug. Thanks for pointing it out.

m.def("set_feed_variable", framework::SetFeedVariable);
m.def("get_fetch_variable", framework::GetFetchVariable);

Expand Down
6 changes: 5 additions & 1 deletion python/paddle/v2/fluid/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ class Executor(object):
def __init__(self, places=None):
if places is None:
if core.is_compile_gpu():
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we need to detect at runtime whether a GPU is present. It's very likely a compiled GPU version runs on a CPU only machine.

places = [core.GPUPlace()]
if core.get_cude_device_count() > 0:
places = [core.GPUPlace()]
else:
# TODO(tonyyang-svail): print warning here
places = [core.CPUPlace()]
else:
places = [core.CPUPlace()]

Expand Down