提交 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
from itertools import izip
import numpy
if sys.version_info[:2] >= (2, 5):
import hashlib
......@@ -918,7 +921,7 @@ class CLinker(link.Linker):
The signature has the following form:
{{{
'CLinker.cmodule_key', compilation args, libraries,
header_dirs, config md5,
header_dirs, numpy ABI version, config md5,
(op0, input_signature0, output_signature0),
(op1, input_signature1, output_signature1),
...
......@@ -1032,6 +1035,11 @@ class CLinker(link.Linker):
args = tuple(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
# 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
......
......@@ -314,6 +314,7 @@ def get_module_hash(src_code, key):
2. The version part of the key.
3. The compiler options defined in `key` (command line parameters and
libraries to link against).
4. The NumPy ABI version.
"""
# `to_hash` will contain any element such that we know for sure that if
# it changes, then the module hash should be different.
......@@ -347,6 +348,8 @@ def get_module_hash(src_code, key):
# This is the md5 hash of the config options. We can stop
# here.
break
elif key_element.startswith('NPY_ABI_VERSION=0x'):
to_hash.append(key_element)
else:
raise AssertionError(error_msg)
else:
......
......@@ -115,8 +115,10 @@ def cleanup():
"""
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.
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.
"""
......@@ -131,10 +133,17 @@ def cleanup():
try:
keydata = cPickle.load(file)
for key in list(keydata.keys):
have_npy_abi_version = False
for obj in flatten(key):
if isinstance(obj, numpy.ndarray):
keydata.remove_key(key)
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:
shutil.rmtree(os.path.join(compiledir, directory))
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论