|
|
|
@ -33,6 +33,14 @@ def execute(main_program, startup_program):
|
|
|
|
|
exe.run(main_program)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_vaild_warning_num(warning, w):
|
|
|
|
|
num = 0
|
|
|
|
|
for i in range(len(w)):
|
|
|
|
|
if warning in str(w[i].message):
|
|
|
|
|
num += 1
|
|
|
|
|
return num
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestDeviceGuard(unittest.TestCase):
|
|
|
|
|
def test_device_guard(self):
|
|
|
|
|
main_program = fluid.Program()
|
|
|
|
@ -133,7 +141,10 @@ class TestDeviceGuard(unittest.TestCase):
|
|
|
|
|
i = fluid.layers.increment(x=i, value=1, in_place=True)
|
|
|
|
|
fluid.layers.less_than(x=i, y=loop_len, cond=cond)
|
|
|
|
|
|
|
|
|
|
assert len(w) == 1
|
|
|
|
|
warning = "The Op(while) is not support to set device."
|
|
|
|
|
warning_num = get_vaild_warning_num(warning, w)
|
|
|
|
|
assert warning_num == 1
|
|
|
|
|
|
|
|
|
|
all_ops = main_program.global_block().ops
|
|
|
|
|
device_attr_name = core.op_proto_and_checker_maker.kOpDeviceAttrName()
|
|
|
|
|
for op in all_ops:
|
|
|
|
@ -169,7 +180,10 @@ class TestDeviceGuard(unittest.TestCase):
|
|
|
|
|
shape=[1], value=4.0, dtype='float32')
|
|
|
|
|
result = fluid.layers.less_than(x=x, y=y, force_cpu=False)
|
|
|
|
|
|
|
|
|
|
assert len(w) == 2
|
|
|
|
|
warning = "\'device_guard\' has higher priority when they are used at the same time."
|
|
|
|
|
warning_num = get_vaild_warning_num(warning, w)
|
|
|
|
|
assert warning_num == 2
|
|
|
|
|
|
|
|
|
|
all_ops = main_program.global_block().ops
|
|
|
|
|
device_attr_name = core.op_proto_and_checker_maker.kOpDeviceAttrName()
|
|
|
|
|
for op in all_ops:
|
|
|
|
|