提交 a64ace01 authored 作者: Frederic's avatar Frederic

Added theano-cache list. It list the content of the theano cache.

上级 d309a022
#!/usr/bin/env python #!/usr/bin/env python
import logging, os, sys import logging, os, sys
import theano
from theano import config from theano import config
from theano.gof.cc import get_module_cache from theano.gof.cc import get_module_cache
...@@ -25,7 +26,8 @@ elif sys.argv[1] in ('clear'): ...@@ -25,7 +26,8 @@ elif sys.argv[1] in ('clear'):
config.compiledir) config.compiledir)
_logger.debug('Remaining elements (%s): %s' % _logger.debug('Remaining elements (%s): %s' %
(len(items), ', '.join(items))) (len(items), ', '.join(items)))
elif sys.argv[1] in ('list'):
theano.gof.compiledir.print_compiledir_content()
else: else:
print 'command "%s" not recognized' % sys.argv[1] print 'command "%s" not recognized' % sys.argv[1]
print 'Type "theano-cache" to print the cache location' print 'Type "theano-cache" to print the cache location'
......
import errno import errno
import os, sys import os
import platform import platform
import re import re
import theano
from theano.configparser import config, AddConfigVar, ConfigParam, StrParam from theano.configparser import config, AddConfigVar, ConfigParam, StrParam
def default_compiledirname(): def default_compiledirname():
platform_id = '-'.join([ platform_id = '-'.join([
platform.platform(), platform.platform(),
...@@ -25,7 +27,7 @@ def filter_compiledir(path): ...@@ -25,7 +27,7 @@ def filter_compiledir(path):
valid = True valid = True
if not os.access(path, os.R_OK | os.W_OK): if not os.access(path, os.R_OK | os.W_OK):
try: try:
os.makedirs(path, 0770) #read-write-execute for user and group os.makedirs(path, 0770) # read-write-execute for user and group
except OSError, e: except OSError, e:
# Maybe another parallel execution of theano was trying to create # Maybe another parallel execution of theano was trying to create
# the same directory at the same time. # the same directory at the same time.
...@@ -59,3 +61,34 @@ AddConfigVar('compiledir', ...@@ -59,3 +61,34 @@ AddConfigVar('compiledir',
default_compiledirname()), default_compiledirname()),
filter=filter_compiledir, filter=filter_compiledir,
allow_override=False)) allow_override=False))
def print_compiledir_content():
import cPickle
def flatten(a):
if isinstance(a, (tuple, list, set)):
l = []
for item in a:
l.extend(flatten(item))
return l
return [flatten(item) for item in a]
else:
return [a]
compiledir = theano.config.compiledir
print "List compiled op in theano this cache", compiledir
for dir in os.listdir(compiledir):
file = None
try:
file = open(os.path.join(compiledir, dir, "key.pkl"))
keydata = cPickle.load(file)
ops = list(set([x for x in flatten(keydata.keys)
if isinstance(x, theano.gof.Op)]))
assert len(ops) == 1
print dir, ops[0]
except IOError:
pass
finally:
if file is not None:
file.close()
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论