提交 5afc4fb4 authored 作者: Frederic's avatar Frederic

Added the numpy ABI version in the key and update "theano-cache cleanup" to…

Added the numpy ABI version in the key and update "theano-cache cleanup" to delete key that don't have it.
上级 ce589649
...@@ -11,6 +11,9 @@ import sys ...@@ -11,6 +11,9 @@ import sys
from itertools import izip from itertools import izip
import numpy
if sys.version_info[:2] >= (2, 5): if sys.version_info[:2] >= (2, 5):
import hashlib import hashlib
...@@ -918,7 +921,7 @@ class CLinker(link.Linker): ...@@ -918,7 +921,7 @@ class CLinker(link.Linker):
The signature has the following form: The signature has the following form:
{{{ {{{
'CLinker.cmodule_key', compilation args, libraries, 'CLinker.cmodule_key', compilation args, libraries,
header_dirs, config md5, header_dirs, numpy ABI version, config md5,
(op0, input_signature0, output_signature0), (op0, input_signature0, output_signature0),
(op1, input_signature1, output_signature1), (op1, input_signature1, output_signature1),
... ...
...@@ -1032,6 +1035,11 @@ class CLinker(link.Linker): ...@@ -1032,6 +1035,11 @@ class CLinker(link.Linker):
args = tuple(args) args = tuple(args)
sig.append(args) sig.append(args)
#We must always add the numpy ABI version here as
# DynamicModule always add the include <numpy/arrayobject.h>
sig.append('NPY_ABI_VERSION=0x%X' %
numpy.core.multiarray._get_ndarray_c_version())
# IMPORTANT: The 'md5' prefix is used to isolate the compilation # IMPORTANT: The 'md5' prefix is used to isolate the compilation
# parameters from the rest of the key. If you want to add more key # parameters from the rest of the key. If you want to add more key
# elements, they should be before this md5 hash if and only if they # elements, they should be before this md5 hash if and only if they
......
...@@ -314,6 +314,7 @@ def get_module_hash(src_code, key): ...@@ -314,6 +314,7 @@ def get_module_hash(src_code, key):
2. The version part of the key. 2. The version part of the key.
3. The compiler options defined in `key` (command line parameters and 3. The compiler options defined in `key` (command line parameters and
libraries to link against). libraries to link against).
4. The NumPy ABI version.
""" """
# `to_hash` will contain any element such that we know for sure that if # `to_hash` will contain any element such that we know for sure that if
# it changes, then the module hash should be different. # it changes, then the module hash should be different.
...@@ -347,6 +348,8 @@ def get_module_hash(src_code, key): ...@@ -347,6 +348,8 @@ def get_module_hash(src_code, key):
# This is the md5 hash of the config options. We can stop # This is the md5 hash of the config options. We can stop
# here. # here.
break break
elif key_element.startswith('NPY_ABI_VERSION=0x'):
to_hash.append(key_element)
else: else:
raise AssertionError(error_msg) raise AssertionError(error_msg)
else: else:
......
...@@ -115,8 +115,10 @@ def cleanup(): ...@@ -115,8 +115,10 @@ def cleanup():
""" """
Delete keys in old format from the compiledir. Delete keys in old format from the compiledir.
We define keys in old format as keys that have an ndarray in them. Old clean up include key in old format:
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
If there is no key left for a compiled module, we delete the module. If there is no key left for a compiled module, we delete the module.
""" """
...@@ -131,10 +133,17 @@ def cleanup(): ...@@ -131,10 +133,17 @@ def cleanup():
try: try:
keydata = cPickle.load(file) keydata = cPickle.load(file)
for key in list(keydata.keys): for key in list(keydata.keys):
have_npy_abi_version = 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) keydata.remove_key(key)
break break
if (isinstance(obj, basestring) and
obj.startswith('NPY_ABI_VERSION=0x')):
have_npy_abi_version = True
if not have_npy_abi_version:
keydata.remove_key(key)
if len(keydata.keys) == 0: if len(keydata.keys) == 0:
shutil.rmtree(os.path.join(compiledir, directory)) shutil.rmtree(os.path.join(compiledir, directory))
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论