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

make theano-cache cleanup remove from the cache module with old version of c code.

上级 f2d653a8
...@@ -19,7 +19,7 @@ def print_help(exit_status): ...@@ -19,7 +19,7 @@ def print_help(exit_status):
print 'Type "theano-cache clear" to erase the cache' print 'Type "theano-cache clear" to erase the cache'
print 'Type "theano-cache list" to print the cache content' print 'Type "theano-cache list" to print the cache content'
print 'Type "theano-cache unlock" to unlock the cache directory' print 'Type "theano-cache unlock" to unlock the cache directory'
print 'Type "theano-cache cleanup" to delete keys in the old format' print 'Type "theano-cache cleanup" to delete keys in the old format/code version'
print 'Type "theano-cache purge" to force deletion of the cache directory' print 'Type "theano-cache purge" to force deletion of the cache directory'
print ('Type "theano-cache basecompiledir" ' print ('Type "theano-cache basecompiledir" '
'to print the parent of the cache directory') 'to print the parent of the cache directory')
......
...@@ -181,7 +181,7 @@ def cleanup(): ...@@ -181,7 +181,7 @@ def cleanup():
""" """
Delete keys in old format from the compiledir. Delete keys in old format from the compiledir.
Old clean up include key in old format: Old clean up include key in old format or with old version of the c_code:
1) keys that have an ndarray in them. 1) keys that have an ndarray in them.
Now we use a hash in the keys of the constant data. Now we use a hash in the keys of the constant data.
2) key that don't have the numpy ABI version in them 2) key that don't have the numpy ABI version in them
...@@ -204,16 +204,30 @@ def cleanup(): ...@@ -204,16 +204,30 @@ def cleanup():
have_c_compiler = False have_c_compiler = False
for obj in flatten(key): for obj in flatten(key):
if isinstance(obj, numpy.ndarray): if isinstance(obj, numpy.ndarray):
keydata.remove_key(key) have_npy_abi_version = False
break break
elif isinstance(obj, basestring): elif isinstance(obj, basestring):
if obj.startswith('NPY_ABI_VERSION=0x'): if obj.startswith('NPY_ABI_VERSION=0x'):
have_npy_abi_version = True have_npy_abi_version = True
elif obj.startswith('c_compiler_str='): elif obj.startswith('c_compiler_str='):
have_c_compiler = True have_c_compiler = True
elif (isinstance(obj, (theano.gof.Op, theano.gof.Type)) and
hasattr(obj, 'c_code_cache_version')):
v = obj.c_code_cache_version()
if v not in [(), None] and v not in key[0]:
have_npy_abi_version = False
break
if not have_npy_abi_version or not have_c_compiler: if not have_npy_abi_version or not have_c_compiler:
try:
#This can happen when we move the compiledir.
if keydata.key_pkl != filename:
keydata.key_pkl = filename
keydata.remove_key(key) keydata.remove_key(key)
except IOError, e:
print ("ERROR while removing a key entry"
" from file. '%s'."
" Delete its directory" % filename)
if len(keydata.keys) == 0: if len(keydata.keys) == 0:
shutil.rmtree(os.path.join(compiledir, directory)) shutil.rmtree(os.path.join(compiledir, directory))
...@@ -221,7 +235,8 @@ def cleanup(): ...@@ -221,7 +235,8 @@ def cleanup():
print ("ERROR while reading this key file '%s'." print ("ERROR while reading this key file '%s'."
" Delete its directory" % filename) " Delete its directory" % filename)
except IOError: except IOError:
pass print ("ERROR while cleaning up this directory '%s'."
" Delete it." % directory)
finally: finally:
if file is not None: if file is not None:
file.close() file.close()
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论