提交 77c4f4d1 authored 作者: abergeron's avatar abergeron

Merge pull request #2128 from nouiz/nogcc

[MRG, ENH]Some crash/warning fix and skip some tests when g++ isn't available.
...@@ -371,7 +371,12 @@ class T_function(unittest.TestCase): ...@@ -371,7 +371,12 @@ class T_function(unittest.TestCase):
four = f(o) four = f(o)
assert numpy.all(four==4) assert numpy.all(four==4)
f(o+.1) #should clobber the memory used to store four f(o+.1) #should clobber the memory used to store four
assert not numpy.all(four==4) if theano.config.cxx:
assert not numpy.all(four==4)
else:
# The Elemwise.perform method don't reuse memory
# as some numpy version don't support that correctly.
assert numpy.all(four==4)
def test_disconnected_input(self): def test_disconnected_input(self):
a = T.scalar('a') a = T.scalar('a')
......
import os import os
import logging import logging
import subprocess
import theano
from theano.configparser import (AddConfigVar, BoolParam, ConfigParam, EnumStr, from theano.configparser import (AddConfigVar, BoolParam, ConfigParam, EnumStr,
IntParam, StrParam, TheanoConfigParser) IntParam, StrParam, TheanoConfigParser)
from theano.misc.cpucount import cpuCount from theano.misc.cpucount import cpuCount
...@@ -156,16 +156,23 @@ if rc == 0 and config.cxx != "": ...@@ -156,16 +156,23 @@ if rc == 0 and config.cxx != "":
'vm', 'vm_nogc', 'cvm_nogc'), 'vm', 'vm_nogc', 'cvm_nogc'),
in_c_key=False) in_c_key=False)
else: else:
# g++ is not present, linker should default to python only # g++ is not present or the user disabled it,
# linker should default to python only.
AddConfigVar('linker', AddConfigVar('linker',
("Default linker used if the theano flags mode is Mode " ("Default linker used if the theano flags mode is Mode "
"or ProfileMode(deprecated)"), "or ProfileMode(deprecated)"),
EnumStr('py', 'vm', 'vm_nogc'), EnumStr('vm', 'py', 'vm_nogc'),
in_c_key=False) in_c_key=False)
_logger.warning('g++ not detected ! Theano will be unable to execute ' try:
# If the user provided an empty value for cxx, do not warn.
theano.configparser.fetch_val_for_key('cxx')
except KeyError:
_logger.warning(
'g++ not detected ! Theano will be unable to execute '
'optimized C-implementations (for both CPU and GPU) and will ' 'optimized C-implementations (for both CPU and GPU) and will '
'default to Python implementations. Performance will be severely ' 'default to Python implementations. Performance will be severely '
'degraded.') 'degraded. To remove this warning, set Theano flags cxx to an '
'empty string.')
#Keep the default value the same as the one for the mode FAST_RUN #Keep the default value the same as the one for the mode FAST_RUN
......
import errno import errno
import os, logging, sys import logging
import os
import sys
import warnings
import theano import theano
from theano import config from theano import config
...@@ -74,9 +78,28 @@ except ImportError: ...@@ -74,9 +78,28 @@ except ImportError:
if version != getattr(lazylinker_ext, '_version', None): if version != getattr(lazylinker_ext, '_version', None):
raise ImportError() raise ImportError()
except ImportError: except ImportError:
# It is useless to try to compile if there isn't any
# compiler! But we still want to try to load it, in case
# the cache was copied from another computer.
if not theano.config.cxx:
raise
_logger.info("Compiling new CVM") _logger.info("Compiling new CVM")
dirname = 'lazylinker_ext' dirname = 'lazylinker_ext'
cfile = os.path.join(theano.__path__[0], 'gof', 'lazylinker_c.c') cfile = os.path.join(theano.__path__[0], 'gof', 'lazylinker_c.c')
if not os.path.exists(cfile):
# This can happen in not normal case. We just
# disable the c clinker. If we are here the user
# didn't disable the compiler, so print a warning.
warnings.warn(
"The file lazylinker_c.c is not available. This do"
"not happen normally. You are probably in a strange"
"setup. This mean Theano can not use the cvm:"
"our c execution engine for Theano function. If you"
"want to remove this warning, use the Theano flag"
"'cxx=' (set to an empty string) to disable all c"
"code generation."
)
raise ImportError("The file lazylinker_c.c is not available.")
code = open(cfile).read() code = open(cfile).read()
loc = os.path.join(config.compiledir, dirname) loc = os.path.join(config.compiledir, dirname)
if not os.path.exists(loc): if not os.path.exists(loc):
......
import unittest import unittest
from nose.plugins.skip import SkipTest
import numpy import numpy
import theano import theano
import theano.gof.op as op import theano.gof.op as op
from theano.gof.type import Type, Generic from theano.gof.type import Type, Generic
from theano.gof.graph import Apply, Variable from theano.gof.graph import Apply, Variable
...@@ -130,6 +130,8 @@ class TestOp: ...@@ -130,6 +130,8 @@ class TestOp:
assert rval == 'test Op no input' assert rval == 'test Op no input'
def test_op_struct(self): def test_op_struct(self):
if not theano.config.cxx:
raise SkipTest("G++ not available, so we need to skip this test.")
sop = StructOp() sop = StructOp()
c = sop(theano.tensor.constant(0)) c = sop(theano.tensor.constant(0))
mode = None mode = None
......
import numpy import numpy
import theano
import theano
from theano import Op, Apply from theano import Op, Apply
from theano.tensor import TensorType from theano.tensor import TensorType
from theano.gof.type import CDataType from theano.gof.type import CDataType
from nose.plugins.skip import SkipTest
# todo: test generic # todo: test generic
class ProdOp(Op): class ProdOp(Op):
__props__ = () __props__ = ()
...@@ -57,6 +59,8 @@ Py_INCREF(%(out)s); ...@@ -57,6 +59,8 @@ Py_INCREF(%(out)s);
def test_cdata(): def test_cdata():
if not theano.config.cxx:
raise SkipTest("G++ not available, so we need to skip this test.")
i = TensorType('float32', (False,))() i = TensorType('float32', (False,))()
c = ProdOp()(i) c = ProdOp()(i)
i2 = GetOp()(c) i2 = GetOp()(c)
......
...@@ -577,8 +577,9 @@ def test_gemm_valid(): ...@@ -577,8 +577,9 @@ def test_gemm_valid():
yield t yield t
def test_dnn_valid(): def test_dnn_valid():
if cuda.device_properties(cuda.active_device_number())['major'] < 3:
raise SkipTest('Current GPU too old')
for t in _test_valid(GpuDnnConv, mode=theano_mode.including("cudnn")): for t in _test_valid(GpuDnnConv, mode=theano_mode.including("cudnn")):
yield t yield t
...@@ -658,6 +659,8 @@ def test_gemm_full(): ...@@ -658,6 +659,8 @@ def test_gemm_full():
def test_dnn_full(): def test_dnn_full():
if cuda.device_properties(cuda.active_device_number())['major'] < 3:
raise SkipTest('Current GPU too old')
for t in _test_full(GpuDnnConv, mode=theano_mode.including("cudnn")): for t in _test_full(GpuDnnConv, mode=theano_mode.including("cudnn")):
yield t yield t
...@@ -708,6 +711,8 @@ def test_gemm_subsample(): ...@@ -708,6 +711,8 @@ def test_gemm_subsample():
def test_dnn_subsample(): def test_dnn_subsample():
if cuda.device_properties(cuda.active_device_number())['major'] < 3:
raise SkipTest('Current GPU too old')
for t in _test_subsample(GpuDnnConv, theano_mode.including('cudnn')): for t in _test_subsample(GpuDnnConv, theano_mode.including('cudnn')):
yield t yield t
......
...@@ -54,11 +54,27 @@ except ImportError: ...@@ -54,11 +54,27 @@ except ImportError:
if version != getattr(scan_perform, '_version', None): if version != getattr(scan_perform, '_version', None):
raise ImportError() raise ImportError()
except ImportError: except ImportError:
if not theano.config.cxx:
raise ImportError("no c compiler, can't compile cython code")
_logger.info("Compiling C code for scan") _logger.info("Compiling C code for scan")
dirname = 'scan_perform' dirname = 'scan_perform'
cfile = os.path.join(theano.__path__[0], 'scan_module', cfile = os.path.join(theano.__path__[0], 'scan_module',
'scan_perform.c') 'scan_perform.c')
if not os.path.exists(cfile):
# This can happen in not normal case. We just
# disable the cython code. If we are here the user
# didn't disable the compiler, so print a warning.
warnings.warn(
"The file scan_perform.c is not available. This do"
"not happen normally. You are probably in a strange"
"setup. This mean Theano can not use the cython code for "
"scan. If you"
"want to remove this warning, use the Theano flag"
"'cxx=' (set to an empty string) to disable all c"
"code generation."
)
raise ImportError("The file lazylinker_c.c is not available.")
code = open(cfile).read() code = open(cfile).read()
loc = os.path.join(config.compiledir, dirname) loc = os.path.join(config.compiledir, dirname)
if not os.path.exists(loc): if not os.path.exists(loc):
......
...@@ -5057,7 +5057,17 @@ your code will run correctly, but may be slower.""") ...@@ -5057,7 +5057,17 @@ your code will run correctly, but may be slower.""")
return n.outputs return n.outputs
return local_fuse return local_fuse
local_elemwise_fusion = local_elemwise_fusion_op(T.Elemwise)
def elemwise_max_input_fct(node):
# The Elemwise.perform use numpy ufunc and they are limited to 31
# inputs.
if not theano.config.cxx:
return 31
return 1024
local_elemwise_fusion = local_elemwise_fusion_op(T.Elemwise,
elemwise_max_input_fct)
class FusionOptimizer(Optimizer): class FusionOptimizer(Optimizer):
......
...@@ -1211,6 +1211,8 @@ class test_fusion(unittest.TestCase): ...@@ -1211,6 +1211,8 @@ class test_fusion(unittest.TestCase):
generate C code in that case. generate C code in that case.
""" """
if not theano.config.cxx:
raise SkipTest("no c compiler, so can't use big elemwise!")
factors = [] factors = []
sd = tensor.dscalar() sd = tensor.dscalar()
means = tensor.dvector() means = tensor.dvector()
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论