|
|
|
@ -38,7 +38,15 @@ def Lenet(data, class_dim):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestFetchAndFeed(unittest.TestCase):
|
|
|
|
|
def parallel_exe(self, use_cuda, run_parallel_exe, seed=1):
|
|
|
|
|
@classmethod
|
|
|
|
|
def setUpClass(cls):
|
|
|
|
|
os.environ['CPU_NUM'] = str(4)
|
|
|
|
|
|
|
|
|
|
def parallel_exe(self,
|
|
|
|
|
use_cuda,
|
|
|
|
|
run_parallel_exe,
|
|
|
|
|
use_experimental_executor=False,
|
|
|
|
|
seed=1):
|
|
|
|
|
main_program = fluid.Program()
|
|
|
|
|
startup = fluid.Program()
|
|
|
|
|
startup.random_seed = seed
|
|
|
|
@ -63,8 +71,12 @@ class TestFetchAndFeed(unittest.TestCase):
|
|
|
|
|
build_strategy = fluid.BuildStrategy()
|
|
|
|
|
build_strategy.enable_inplace = False
|
|
|
|
|
build_strategy.memory_optimize = False
|
|
|
|
|
exec_strategy = fluid.ExecutionStrategy()
|
|
|
|
|
exec_strategy.use_experimental_executor = use_experimental_executor
|
|
|
|
|
train_cp = compiler.CompiledProgram(main_program).with_data_parallel(
|
|
|
|
|
loss_name=loss.name, build_strategy=build_strategy)
|
|
|
|
|
loss_name=loss.name,
|
|
|
|
|
build_strategy=build_strategy,
|
|
|
|
|
exec_strategy=exec_strategy)
|
|
|
|
|
|
|
|
|
|
run_parallel_exe(train_cp, exe, use_cuda, data, label, loss)
|
|
|
|
|
|
|
|
|
@ -131,8 +143,7 @@ class TestFetchAndFeed(unittest.TestCase):
|
|
|
|
|
if batch_id == 2:
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
def test_fetch(self):
|
|
|
|
|
os.environ['CPU_NUM'] = str(4)
|
|
|
|
|
def test_fetch_with_threaded_executor(self):
|
|
|
|
|
if core.is_compiled_with_cuda():
|
|
|
|
|
self.parallel_exe(
|
|
|
|
|
use_cuda=True,
|
|
|
|
@ -140,8 +151,18 @@ class TestFetchAndFeed(unittest.TestCase):
|
|
|
|
|
self.parallel_exe(
|
|
|
|
|
use_cuda=False, run_parallel_exe=self.run_parallel_exe_with_fetch)
|
|
|
|
|
|
|
|
|
|
def test_fetch_with_fast_threaded_executor(self):
|
|
|
|
|
if core.is_compiled_with_cuda():
|
|
|
|
|
self.parallel_exe(
|
|
|
|
|
use_cuda=True,
|
|
|
|
|
run_parallel_exe=self.run_parallel_exe_with_fetch,
|
|
|
|
|
use_experimental_executor=True)
|
|
|
|
|
self.parallel_exe(
|
|
|
|
|
use_cuda=False,
|
|
|
|
|
run_parallel_exe=self.run_parallel_exe_with_fetch,
|
|
|
|
|
use_experimental_executor=True)
|
|
|
|
|
|
|
|
|
|
def test_feed(self):
|
|
|
|
|
os.environ['CPU_NUM'] = str(4)
|
|
|
|
|
if core.is_compiled_with_cuda():
|
|
|
|
|
self.parallel_exe(
|
|
|
|
|
use_cuda=True, run_parallel_exe=self.run_parallel_exe_with_feed)
|
|
|
|
|