-
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
"fix gpu init" #7528
"fix gpu init" #7528
Changes from 4 commits
7d8afc3
1edd1c0
5a8b530
d1a3ba9
c17051e
15ae79e
44c56cc
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 |
---|---|---|
|
@@ -20,7 +20,26 @@ TEST(InitDevices, CPU) { | |
using paddle::framework::InitDevices; | ||
using paddle::platform::DeviceContextPool; | ||
|
||
#ifndef PADDLE_WITH_CUDA | ||
InitDevices(); | ||
DeviceContextPool& pool = DeviceContextPool::Instance(); | ||
ASSERT_GE(pool.size(), 1U); | ||
ASSERT_EQ(pool.size(), 1U); | ||
#endif | ||
} | ||
|
||
TEST(InitDevices, CUDA) { | ||
using paddle::framework::InitDevices; | ||
using paddle::platform::DeviceContextPool; | ||
|
||
int count = 0; | ||
try { | ||
count = paddle::platform::GetCUDADeviceCount(); | ||
} catch (const std::exception& exp) { | ||
} | ||
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. If 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. done |
||
|
||
#ifdef PADDLE_WITH_CUDA | ||
InitDevices(); | ||
DeviceContextPool& pool = DeviceContextPool::Instance(); | ||
ASSERT_EQ(pool.size(), 1U + static_cast<unsigned>(count)); | ||
#endif | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,9 +91,23 @@ def __bootstrap__(): | |
] | ||
if core.is_compile_gpu(): | ||
read_env_flags += ['fraction_of_gpu_memory_to_use', 'op_sync'] | ||
|
||
core.init_gflags([sys.argv[0]] + | ||
["--tryfromenv=" + ",".join(read_env_flags)]) | ||
core.init_glog(sys.argv[0]) | ||
|
||
gpu_devices = os.getenv("CUDA_VISIBLE_DEVICES", '') | ||
if core.is_compile_gpu(): | ||
if len(gpu_devices.split(",")) >= 1: | ||
print( | ||
'WARNING: CUDA_VISIBLE_DEVICES set to {0}, not empty . The computation ' | ||
'speed will not be optimized if you use multi-gpu. It will ' | ||
'fail if this PaddlePaddle binary is compiled without GPU option' | ||
.format(gpu_devices), | ||
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.
|
||
file=sys.stderr) | ||
else: | ||
gpu_devices = "0" | ||
os.environ['CUDA_VISIBLE_DEVICES'] = gpu_devices | ||
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. The logic of line 99~110 maybe has some problem. |
||
core.init_devices() | ||
|
||
|
||
|
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.
#ifdef PADDLE_WITH_CUDA
should be placed in line31.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.
This test is compiled in nv_test.
So
#ifdef PADDLE_WITH_CUDA
is no needed.