提交 feff4f12 authored 作者: Frédéric Bastien's avatar Frédéric Bastien

Merge pull request #1934 from RoyXue/GSoC2014_part2

Compute minimum peak
...@@ -320,6 +320,15 @@ import theano and print the config variable, as in: ...@@ -320,6 +320,15 @@ import theano and print the config variable, as in:
For the memory profile, do not print Apply nodes if the size For the memory profile, do not print Apply nodes if the size
of their outputs (in bytes) is lower than this. of their outputs (in bytes) is lower than this.
.. attribute:: profiling.min_peak_memory
Bool value: either True or False
Default False
Do the memory profile print the min peak memory usage?
It only works when profile=True, profile_memory=True
.. attribute:: config.lib.amdlibm .. attribute:: config.lib.amdlibm
Bool value: either True or False Bool value: either True or False
......
...@@ -2,36 +2,57 @@ ...@@ -2,36 +2,57 @@
Test of memory profiling Test of memory profiling
""" """
import StringIO
import numpy
import theano import theano
import theano.tensor as T import theano.tensor as T
import StringIO
def test_profiling(): def test_profiling():
old1 = theano.config.profile config1 = theano.config.profile
old2 = theano.config.profile_memory config2 = theano.config.profile_memory
config3 = theano.config.profiling.min_peak_memory
try: try:
theano.config.profile = True theano.config.profile = True
theano.config.profile_memory = True theano.config.profile_memory = True
theano.config.profiling.min_peak_memory = True
x = [T.dvector("val%i" % i) for i in range(3)]
z = []
z += [T.outer(x[i], x[i+1]).sum(axis=1) for i in range(len(x)-1)]
z += [x[i] + x[i+1] for i in range(len(x)-1)]
x = T.dvector("x")
y = T.dvector("y")
z = x + y
p = theano.ProfileStats(False) p = theano.ProfileStats(False)
if theano.config.mode in ["DebugMode", "DEBUG_MODE"]: if theano.config.mode in ["DebugMode", "DEBUG_MODE"]:
m = "FAST_RUN" m = "FAST_RUN"
else: else:
m = None m = None
f = theano.function([x, y], z, profile=p, name="test_profiling",
f = theano.function(x, z, profile=p, name="test_profiling",
mode=m) mode=m)
output = f([1, 2, 3, 4], [1, 1, 1, 1])
inp = [numpy.arange(1024) + 1 for i in range(len(x))]
output = f(*inp)
buf = StringIO.StringIO() buf = StringIO.StringIO()
f.profile.summary(buf) f.profile.summary(buf)
# regression testing for future algo speed up
the_string = buf.getvalue()
lines1 = [l for l in the_string.split("\n") if "Max if linker" in l]
lines2 = [l for l in the_string.split("\n") if "Minimum peak" in l]
assert "Max if linker=cvm(default): 8224KB (16408KB)" in the_string, (lines1, lines2)
assert "Minimum peak from all valid apply node order is 8208KB" in the_string, (lines1, lines2)
finally: finally:
theano.config.profile = old1 theano.config.profile = config1
theano.config.profile_memory = old2 theano.config.profile_memory = config2
theano.config.profiling.min_peak_memory = config3
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -149,6 +149,9 @@ class VM(object): ...@@ -149,6 +149,9 @@ class VM(object):
if hasattr(self, 'node_cleared_order'): if hasattr(self, 'node_cleared_order'):
profile.node_cleared_order = self.node_cleared_order[:] profile.node_cleared_order = self.node_cleared_order[:]
if hasattr(self, 'dependencies'):
profile.dependencies = self.dependencies.copy()
# clear the timer info out of the buffers # clear the timer info out of the buffers
for i in xrange(len(self.call_times)): for i in xrange(len(self.call_times)):
self.call_times[i] = 0.0 self.call_times[i] = 0.0
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论