提交 872c8166 authored 作者: Pascal Lamblin's avatar Pascal Lamblin

Add Python bitwidth in config.compile_dir.

Also move local_bitwidth to gof/compiledir, import it directly in theano.gof, and use the latter path.
上级 3b6922d3
...@@ -364,7 +364,7 @@ import theano and print the config variable, as in: ...@@ -364,7 +364,7 @@ import theano and print the config variable, as in:
.. attribute:: compiledir_format .. attribute:: compiledir_format
Default: "compiledir_%(platform)s-%(processor)s-%(python_version)s" Default: "compiledir_%(platform)s-%(processor)s-%(python_version)s-%(python_bitwidth)s"
This is a Python format string that specifies the subdirectory This is a Python format string that specifies the subdirectory
of ``config.base_compiledir`` in which to store platform-dependent of ``config.base_compiledir`` in which to store platform-dependent
......
...@@ -548,7 +548,7 @@ class Test_pfunc(unittest.TestCase): ...@@ -548,7 +548,7 @@ class Test_pfunc(unittest.TestCase):
def test_default_updates_input(self): def test_default_updates_input(self):
x = shared(0) x = shared(0)
y = shared(1) y = shared(1)
if theano.gof.cmodule.python_int_bitwidth() == 32: if theano.gof.python_int_bitwidth() == 32:
a = iscalar('a') a = iscalar('a')
else: else:
a = lscalar('a') a = lscalar('a')
......
...@@ -18,7 +18,7 @@ class Test_SharedVariable(unittest.TestCase): ...@@ -18,7 +18,7 @@ class Test_SharedVariable(unittest.TestCase):
assert shared(7, dtype='float64').type == Scalar('float64') assert shared(7, dtype='float64').type == Scalar('float64')
else: else:
if theano.gof.cmodule.python_int_bitwidth() == 32: if theano.gof.python_int_bitwidth() == 32:
assert shared(7).type == theano.tensor.iscalar, shared(7).type assert shared(7).type == theano.tensor.iscalar, shared(7).type
else: else:
assert shared(7).type == theano.tensor.lscalar, shared(7).type assert shared(7).type == theano.tensor.lscalar, shared(7).type
......
...@@ -38,7 +38,9 @@ e-mail thread "What is gof?" ...@@ -38,7 +38,9 @@ e-mail thread "What is gof?"
from theano.gof.cc import \ from theano.gof.cc import \
CLinker, OpWiseCLinker, DualLinker CLinker, OpWiseCLinker, DualLinker
import theano.gof.compiledir # adds config vars # Also adds config vars
from theano.gof.compiledir import \
local_bitwidth, python_int_bitwidth
from theano.gof.fg import \ from theano.gof.fg import \
InconsistencyError, MissingInputError, FunctionGraph InconsistencyError, MissingInputError, FunctionGraph
......
...@@ -27,7 +27,7 @@ from theano.misc.windows import call_subprocess_Popen ...@@ -27,7 +27,7 @@ from theano.misc.windows import call_subprocess_Popen
# we will abuse the lockfile mechanism when reading and writing the registry # we will abuse the lockfile mechanism when reading and writing the registry
from theano.gof import compilelock from theano.gof import compilelock
from theano.gof.compiledir import gcc_version_str from theano.gof.compiledir import gcc_version_str, local_bitwidth
from theano.configparser import AddConfigVar, BoolParam from theano.configparser import AddConfigVar, BoolParam
...@@ -55,29 +55,6 @@ AddConfigVar('cmodule.compilation_warning', ...@@ -55,29 +55,6 @@ AddConfigVar('cmodule.compilation_warning',
BoolParam(False)) BoolParam(False))
def local_bitwidth():
"""
Return 32 for 32bit arch, 64 for 64bit arch
By "architecture", we mean the size of memory pointers (size_t in C),
*not* the size of long int, as it can be different.
"""
# Note that according to Python documentation, `platform.architecture()` is
# not reliable on OS X with universal binaries.
# Also, sys.maxsize does not exist in Python < 2.6.
# 'P' denotes a void*, and the size is expressed in bytes.
return struct.calcsize('P') * 8
def python_int_bitwidth():
"""
Return the bit width of Python int (C long int).
Note that it can be different from the size of a memory pointer.
"""
# 'l' denotes a C long int, and the size is expressed in bytes.
return struct.calcsize('l') * 8
_logger = logging.getLogger("theano.gof.cmodule") _logger = logging.getLogger("theano.gof.cmodule")
_logger.setLevel(logging.WARNING) _logger.setLevel(logging.WARNING)
......
...@@ -4,6 +4,7 @@ import os ...@@ -4,6 +4,7 @@ import os
import platform import platform
import re import re
import shutil import shutil
import struct
import subprocess import subprocess
import sys import sys
import textwrap import textwrap
...@@ -32,16 +33,43 @@ except OSError: ...@@ -32,16 +33,43 @@ except OSError:
del p del p
del dummy_err del dummy_err
compiledir_format_dict = {"platform": platform.platform(),
def local_bitwidth():
"""
Return 32 for 32bit arch, 64 for 64bit arch
By "architecture", we mean the size of memory pointers (size_t in C),
*not* the size of long int, as it can be different.
"""
# Note that according to Python documentation, `platform.architecture()` is
# not reliable on OS X with universal binaries.
# Also, sys.maxsize does not exist in Python < 2.6.
# 'P' denotes a void*, and the size is expressed in bytes.
return struct.calcsize('P') * 8
def python_int_bitwidth():
"""
Return the bit width of Python int (C long int).
Note that it can be different from the size of a memory pointer.
"""
# 'l' denotes a C long int, and the size is expressed in bytes.
return struct.calcsize('l') * 8
compiledir_format_dict = {
"platform": platform.platform(),
"processor": platform.processor(), "processor": platform.processor(),
"python_version": platform.python_version(), "python_version": platform.python_version(),
"python_bitwidth": local_bitwidth(),
"theano_version": theano.__version__, "theano_version": theano.__version__,
"numpy_version": numpy.__version__, "numpy_version": numpy.__version__,
"gxx_version": gcc_version_str.replace(" ", "_"), "gxx_version": gcc_version_str.replace(" ", "_"),
} }
compiledir_format_keys = ", ".join(sorted(compiledir_format_dict.keys())) compiledir_format_keys = ", ".join(sorted(compiledir_format_dict.keys()))
default_compiledir_format =\ default_compiledir_format = ("compiledir_%(platform)s-%(processor)s-"
"compiledir_%(platform)s-%(processor)s-%(python_version)s" "%(python_version)s-%(python_bitwidth)s")
AddConfigVar("compiledir_format", AddConfigVar("compiledir_format",
textwrap.fill(textwrap.dedent("""\ textwrap.fill(textwrap.dedent("""\
......
...@@ -10,10 +10,11 @@ import warnings ...@@ -10,10 +10,11 @@ import warnings
import numpy import numpy
import theano import theano
from theano.gof import local_bitwidth
from theano.gof.cc import hash_from_file from theano.gof.cc import hash_from_file
from theano.gof.cmodule import (std_libs, std_lib_dirs, from theano.gof.cmodule import (std_libs, std_lib_dirs,
std_include_dirs, dlimport, std_include_dirs, dlimport,
get_lib_extension, local_bitwidth) get_lib_extension)
from theano.gof.python25 import any from theano.gof.python25 import any
from theano.misc.windows import call_subprocess_Popen from theano.misc.windows import call_subprocess_Popen
......
...@@ -114,12 +114,12 @@ class BinCountOp(theano.Op): ...@@ -114,12 +114,12 @@ class BinCountOp(theano.Op):
# Some dtypes are not supported by numpy's implementation of bincount. # Some dtypes are not supported by numpy's implementation of bincount.
# Until another one is available, we should fail at graph construction # Until another one is available, we should fail at graph construction
# time, not wait for execution. # time, not wait for execution.
int_bitwidth = theano.gof.cmodule.python_int_bitwidth() int_bitwidth = theano.gof.python_int_bitwidth()
if int_bitwidth == 64: if int_bitwidth == 64:
numpy_unsupported_dtypes = ('uint64',) numpy_unsupported_dtypes = ('uint64',)
if int_bitwidth == 32: if int_bitwidth == 32:
numpy_unsupported_dtypes = ('uint32', 'int64', 'uint64') numpy_unsupported_dtypes = ('uint32', 'int64', 'uint64')
intp_bitwidth = theano.gof.cmodule.local_bitwidth() intp_bitwidth = theano.gof.local_bitwidth()
if intp_bitwidth == 32: if intp_bitwidth == 32:
out_type = basic.ivector() out_type = basic.ivector()
elif intp_bitwidth == 64: elif intp_bitwidth == 64:
...@@ -246,7 +246,7 @@ class RepeatOp(theano.Op): ...@@ -246,7 +246,7 @@ class RepeatOp(theano.Op):
# Some dtypes are not supported by numpy's implementation of repeat. # Some dtypes are not supported by numpy's implementation of repeat.
# Until another one is available, we should fail at graph construction # Until another one is available, we should fail at graph construction
# time, not wait for execution. # time, not wait for execution.
int_bitwidth = theano.gof.cmodule.python_int_bitwidth() int_bitwidth = theano.gof.python_int_bitwidth()
if int_bitwidth == 64: if int_bitwidth == 64:
numpy_unsupported_dtypes = ('uint64',) numpy_unsupported_dtypes = ('uint64',)
if int_bitwidth == 32: if int_bitwidth == 32:
......
...@@ -25,7 +25,7 @@ class TestBinCountOp(utt.InferShapeTester): ...@@ -25,7 +25,7 @@ class TestBinCountOp(utt.InferShapeTester):
'uint8', 'uint16', 'uint32', 'uint64'): 'uint8', 'uint16', 'uint32', 'uint64'):
# uint64 always fails # uint64 always fails
# int64 and uint32 also fail if python int are 32-bit # int64 and uint32 also fail if python int are 32-bit
int_bitwidth = theano.gof.cmodule.python_int_bitwidth() int_bitwidth = theano.gof.python_int_bitwidth()
if int_bitwidth == 64: if int_bitwidth == 64:
numpy_unsupported_dtypes = ('uint64',) numpy_unsupported_dtypes = ('uint64',)
if int_bitwidth == 32: if int_bitwidth == 32:
...@@ -57,7 +57,7 @@ class TestBinCountOp(utt.InferShapeTester): ...@@ -57,7 +57,7 @@ class TestBinCountOp(utt.InferShapeTester):
for dtype in tensor.discrete_dtypes: for dtype in tensor.discrete_dtypes:
# uint64 always fails # uint64 always fails
# int64 and uint32 also fail if python int are 32-bit # int64 and uint32 also fail if python int are 32-bit
int_bitwidth = theano.gof.cmodule.python_int_bitwidth() int_bitwidth = theano.gof.python_int_bitwidth()
if int_bitwidth == 64: if int_bitwidth == 64:
numpy_unsupported_dtypes = ('uint64',) numpy_unsupported_dtypes = ('uint64',)
if int_bitwidth == 32: if int_bitwidth == 32:
...@@ -203,7 +203,7 @@ class TestRepeatOp(utt.InferShapeTester): ...@@ -203,7 +203,7 @@ class TestRepeatOp(utt.InferShapeTester):
self.op = RepeatOp() self.op = RepeatOp()
# uint64 always fails # uint64 always fails
# int64 and uint32 also fail if python int are 32-bit # int64 and uint32 also fail if python int are 32-bit
int_bitwidth = theano.gof.cmodule.python_int_bitwidth() int_bitwidth = theano.gof.python_int_bitwidth()
if int_bitwidth == 64: if int_bitwidth == 64:
self.numpy_unsupported_dtypes = ('uint64',) self.numpy_unsupported_dtypes = ('uint64',)
if int_bitwidth == 32: if int_bitwidth == 32:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论