-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,6 +78,14 @@ bool IsCompileGPU() { | |
#endif | ||
} | ||
|
||
int GetCUDADeviceCount() { | ||
#ifndef PADDLE_WITH_CUDA | ||
return 0; | ||
#else | ||
return paddle::platform::GetCUDADeviceCount(); | ||
#endif | ||
} | ||
|
||
PYBIND11_PLUGIN(core) { | ||
py::module m("core", "C++ core of PaddlePaddle"); | ||
|
||
|
@@ -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()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not familiar with Pybind, why it's a function invocation here? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,17 @@ | |
|
||
|
||
class Executor(object): | ||
def __init__(self, places): | ||
def __init__(self, places=None): | ||
if places is None: | ||
if core.is_compile_gpu(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
if core.get_cude_device_count() > 0: | ||
places = [core.GPUPlace()] | ||
else: | ||
# TODO(tonyyang-svail): print warning here | ||
places = [core.CPUPlace()] | ||
else: | ||
places = [core.CPUPlace()] | ||
|
||
if not isinstance(places, list) and not isinstance(places, tuple): | ||
places = [places] | ||
|
||
|
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.
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.