19
19
import unittest
20
20
21
21
22
- def train_simulator (use_cuda , test_batch_size = 10 ):
22
+ def train_simulator (test_batch_size = 10 ):
23
23
if test_batch_size <= 0 :
24
24
raise ValueError ("batch_size should be a positive integeral value, "
25
25
"but got batch_size={}" .format (test_batch_size ))
@@ -34,14 +34,7 @@ def train_simulator(use_cuda, test_batch_size=10):
34
34
sgd_optimizer = fluid .optimizer .SGD (learning_rate = 0.001 )
35
35
sgd_optimizer .minimize (avg_cost )
36
36
37
- train_reader = paddle .batch (
38
- paddle .reader .shuffle (
39
- paddle .dataset .uci_housing .train (), buf_size = 500 ),
40
- batch_size = test_batch_size )
41
-
42
- place = fluid .CUDAPlace (0 ) if use_cuda else fluid .CPUPlace ()
43
- exe = fluid .Executor (place )
44
-
37
+ # Calculate memory usage in current network config
45
38
lower_usage , upper_usage , unit = fluid .contrib .memory_usage (
46
39
fluid .default_main_program (), batch_size = test_batch_size )
47
40
@@ -50,21 +43,17 @@ def train_simulator(use_cuda, test_batch_size=10):
50
43
51
44
52
45
class TestMemoryUsage (unittest .TestCase ):
53
- def test_cpu (self ):
54
- with self .program_scope_guard ():
55
- train_simulator (use_cuda = False )
56
-
57
- def test_cpu_with_unit_KB (self ):
46
+ def test_with_unit_B (self ):
58
47
with self .program_scope_guard ():
59
- train_simulator (use_cuda = False , test_batch_size = 1000 )
48
+ train_simulator ()
60
49
61
- def test_cpu_with_unit_MB (self ):
50
+ def test_with_unit_KB (self ):
62
51
with self .program_scope_guard ():
63
- train_simulator (use_cuda = False , test_batch_size = 100000 )
52
+ train_simulator (test_batch_size = 1000 )
64
53
65
- def test_cuda (self ):
54
+ def test_with_unit_MB (self ):
66
55
with self .program_scope_guard ():
67
- train_simulator (use_cuda = True )
56
+ train_simulator (test_batch_size = 100000 )
68
57
69
58
@contextlib .contextmanager
70
59
def program_scope_guard (self ):
0 commit comments