提交 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):
four = f(o)
assert numpy.all(four==4)
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):
a = T.scalar('a')
......
import os
import logging
import subprocess
import theano
from theano.configparser import (AddConfigVar, BoolParam, ConfigParam, EnumStr,
IntParam, StrParam, TheanoConfigParser)
from theano.misc.cpucount import cpuCount
......@@ -156,16 +156,23 @@ if rc == 0 and config.cxx != "":
'vm', 'vm_nogc', 'cvm_nogc'),
in_c_key=False)
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',
("Default linker used if the theano flags mode is Mode "
"or ProfileMode(deprecated)"),
EnumStr('py', 'vm', 'vm_nogc'),
EnumStr('vm', 'py', 'vm_nogc'),
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 '
'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
......
import errno
import os, logging, sys
import logging
import os
import sys
import warnings
import theano
from theano import config
......@@ -74,9 +78,28 @@ except ImportError:
if version != getattr(lazylinker_ext, '_version', None):
raise 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")
dirname = 'lazylinker_ext'
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()
loc = os.path.join(config.compiledir, dirname)
if not os.path.exists(loc):
......
import unittest
from nose.plugins.skip import SkipTest
import numpy
import theano
import theano.gof.op as op
from theano.gof.type import Type, Generic
from theano.gof.graph import Apply, Variable
......@@ -130,6 +130,8 @@ class TestOp:
assert rval == 'test Op no input'
def test_op_struct(self):
if not theano.config.cxx:
raise SkipTest("G++ not available, so we need to skip this test.")
sop = StructOp()
c = sop(theano.tensor.constant(0))
mode = None
......
import numpy
import theano
import theano
from theano import Op, Apply
from theano.tensor import TensorType
from theano.gof.type import CDataType
from nose.plugins.skip import SkipTest
# todo: test generic
class ProdOp(Op):
__props__ = ()
......@@ -57,6 +59,8 @@ Py_INCREF(%(out)s);
def test_cdata():
if not theano.config.cxx:
raise SkipTest("G++ not available, so we need to skip this test.")
i = TensorType('float32', (False,))()
c = ProdOp()(i)
i2 = GetOp()(c)
......
......@@ -577,8 +577,9 @@ def test_gemm_valid():
yield t
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")):
yield t
......@@ -658,6 +659,8 @@ def test_gemm_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")):
yield t
......@@ -708,6 +711,8 @@ def test_gemm_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')):
yield t
......
......@@ -54,11 +54,27 @@ except ImportError:
if version != getattr(scan_perform, '_version', None):
raise 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")
dirname = 'scan_perform'
cfile = os.path.join(theano.__path__[0], 'scan_module',
'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()
loc = os.path.join(config.compiledir, dirname)
if not os.path.exists(loc):
......
......@@ -5057,7 +5057,17 @@ your code will run correctly, but may be slower.""")
return n.outputs
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):
......
......@@ -1211,6 +1211,8 @@ class test_fusion(unittest.TestCase):
generate C code in that case.
"""
if not theano.config.cxx:
raise SkipTest("no c compiler, so can't use big elemwise!")
factors = []
sd = tensor.dscalar()
means = tensor.dvector()
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论