未验证 提交 9cb799be 编写于 作者: J Jiabin Yang 提交者: GitHub

test=develop, Revert "Add multi gpu install check" (#18313)

* Revert "Add multi gpu install check (#18229)"

This reverts commit 61ed06b2.

* test=develop, start ci
上级 0e08e91c
...@@ -12,40 +12,7 @@ ...@@ -12,40 +12,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import os from .framework import Program, program_guard, unique_name, default_startup_program
from . import core
def process_env():
env = os.environ
device_list = []
if env.get('CUDA_VISIBLE_DEVICES') is not None:
cuda_devices = env['CUDA_VISIBLE_DEVICES']
if cuda_devices == "" or len(cuda_devices) == 0:
os.environ['CUDA_VISIBLE_DEVICES'] = "0,1"
device_list = [0, 1]
elif len(cuda_devices) == 1:
device_list.append(0)
elif len(cuda_devices) > 1:
for i in range(len(cuda_devices.split(","))):
device_list.append(i)
return device_list
else:
if core.get_cuda_device_count() > 1:
os.environ['CUDA_VISIBLE_DEVICES'] = "0,1"
return [0, 1]
else:
os.environ['CUDA_VISIBLE_DEVICES'] = "0"
return [0]
device_list = []
if core.is_compiled_with_cuda():
device_list = process_env()
else:
device_list = [0, 1] # for CPU 0,1
from .framework import Program, program_guard, unique_name
from .param_attr import ParamAttr from .param_attr import ParamAttr
from .initializer import Constant from .initializer import Constant
from . import layers from . import layers
...@@ -57,6 +24,7 @@ from . import core ...@@ -57,6 +24,7 @@ from . import core
from . import compiler from . import compiler
import logging import logging
import numpy as np import numpy as np
import os
__all__ = ['run_check'] __all__ = ['run_check']
...@@ -83,12 +51,13 @@ def run_check(): ...@@ -83,12 +51,13 @@ def run_check():
use_cuda = False if not core.is_compiled_with_cuda() else True use_cuda = False if not core.is_compiled_with_cuda() else True
place = core.CPUPlace() if not core.is_compiled_with_cuda( place = core.CPUPlace() if not core.is_compiled_with_cuda(
) else core.CUDAPlace(0) ) else core.CUDAPlace(0)
np_inp_single = np.array([[1.0, 2.0], [3.0, 4.0]], dtype=np.float32) np_inp = np.array([[1.0, 2.0], [3.0, 4.0]], dtype=np.float32)
inp = []
for i in range(len(device_list)): if use_cuda:
inp.append(np_inp_single) if core.get_cuda_device_count() > 1:
np_inp_muti = np.array(inp) os.environ['CUDA_VISIBLE_DEVICES'] = "0,1"
np_inp_muti = np_inp_muti.reshape(len(device_list), 2, 2) else:
os.environ['CUDA_VISIBLE_DEVICES'] = "0"
def test_parallerl_exe(): def test_parallerl_exe():
train_prog = Program() train_prog = Program()
...@@ -103,13 +72,13 @@ def run_check(): ...@@ -103,13 +72,13 @@ def run_check():
build_strategy = compiler.BuildStrategy() build_strategy = compiler.BuildStrategy()
build_strategy.enable_inplace = True build_strategy.enable_inplace = True
build_strategy.memory_optimize = True build_strategy.memory_optimize = True
inp = layers.data(name="inp", shape=[2, 2]) inp = layers.data(
name="inp", shape=[2, 2], append_batch_size=False)
simple_layer = SimpleLayer("simple_layer") simple_layer = SimpleLayer("simple_layer")
out = simple_layer(inp) out = simple_layer(inp)
exe = executor.Executor(place) exe = executor.Executor(place)
if use_cuda: if use_cuda:
for i in device_list: places = [core.CUDAPlace(0), core.CUDAPlace(1)]
places.append(core.CUDAPlace(i))
else: else:
places = [core.CPUPlace(), core.CPUPlace()] places = [core.CPUPlace(), core.CPUPlace()]
loss = layers.mean(out) loss = layers.mean(out)
...@@ -124,7 +93,7 @@ def run_check(): ...@@ -124,7 +93,7 @@ def run_check():
exe.run(startup_prog) exe.run(startup_prog)
exe.run(compiled_prog, exe.run(compiled_prog,
feed={inp.name: np_inp_muti}, feed={inp.name: np_inp},
fetch_list=[loss.name]) fetch_list=[loss.name])
def test_simple_exe(): def test_simple_exe():
...@@ -146,7 +115,7 @@ def run_check(): ...@@ -146,7 +115,7 @@ def run_check():
if not core.is_compiled_with_cuda() if not core.is_compiled_with_cuda()
else core.CUDAPlace(0)) else core.CUDAPlace(0))
exe0.run(startup_prog) exe0.run(startup_prog)
exe0.run(feed={inp0.name: np_inp_single}, exe0.run(feed={inp0.name: np_inp},
fetch_list=[out0.name, param_grads[1].name]) fetch_list=[out0.name, param_grads[1].name])
test_simple_exe() test_simple_exe()
...@@ -170,4 +139,4 @@ def run_check(): ...@@ -170,4 +139,4 @@ def run_check():
print("\n Original Error is: {}".format(e)) print("\n Original Error is: {}".format(e))
print( print(
"Your Paddle Fluid is installed successfully ONLY for SINGLE GPU or CPU! " "Your Paddle Fluid is installed successfully ONLY for SINGLE GPU or CPU! "
"\n Let's start deep Learning with Paddle Fluid now") "\n Let's start deep Learning with Paddle Fluid now!")
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册