提交 b7f0c300 authored 作者: Frederic Bastien's avatar Frederic Bastien

Only raise error if convolution or pooling are used in the new back-end.

上级 733adf01
...@@ -77,7 +77,7 @@ def init_dev(dev, name=None): ...@@ -77,7 +77,7 @@ def init_dev(dev, name=None):
" downgrading CuDNN to version 4.") " downgrading CuDNN to version 4.")
cudnn_version = " (CuDNN version %s)" % cudnn_version cudnn_version = " (CuDNN version %s)" % cudnn_version
except Exception: except Exception:
raise RuntimeError("CuDNN is mandatory with the GpuArray back-end.") pass
print("Mapped name %s to device %s: %s%s" % ( print("Mapped name %s to device %s: %s%s" % (
name, dev, context.devname, cudnn_version), name, dev, context.devname, cudnn_version),
file=sys.stderr) file=sys.stderr)
......
...@@ -32,6 +32,10 @@ from .opt import gpu_seqopt, register_opt, conv_groupopt, op_lifter ...@@ -32,6 +32,10 @@ from .opt import gpu_seqopt, register_opt, conv_groupopt, op_lifter
from .opt_util import alpha_merge, output_merge, inplace_allocempty from .opt_util import alpha_merge, output_merge, inplace_allocempty
def raise_no_cudnn(msg="CuDNN is required for convolution and pooling"):
raise RuntimeError(msg)
def _dnn_check_compile(): def _dnn_check_compile():
preambule = """ preambule = """
#include <stdio.h> #include <stdio.h>
...@@ -1302,10 +1306,12 @@ def local_abstractconv_cudnn(node): ...@@ -1302,10 +1306,12 @@ def local_abstractconv_cudnn(node):
inp1 = node.inputs[0] inp1 = node.inputs[0]
inp2 = node.inputs[1] inp2 = node.inputs[1]
if (not isinstance(inp1.type, GpuArrayType) or if not isinstance(inp1.type, GpuArrayType):
not dnn_available(inp1.type.context_name)):
return None return None
if not dnn_available(inp1.type.context_name):
raise_no_cudnn()
if node.op.filter_flip: if node.op.filter_flip:
conv_mode = 'conv' conv_mode = 'conv'
else: else:
...@@ -1404,7 +1410,7 @@ def local_dnn_convi_output_merge(node, *inputs): ...@@ -1404,7 +1410,7 @@ def local_dnn_convi_output_merge(node, *inputs):
@op_lifter([Pool]) @op_lifter([Pool])
def local_pool_dnn_alternative(node, ctx_name): def local_pool_dnn_alternative(node, ctx_name):
if not dnn_available(ctx_name): if not dnn_available(ctx_name):
return raise_no_cudnn()
if not node.op.ignore_border: if not node.op.ignore_border:
return return
img, = node.inputs img, = node.inputs
...@@ -1420,7 +1426,7 @@ def local_pool_dnn_alternative(node, ctx_name): ...@@ -1420,7 +1426,7 @@ def local_pool_dnn_alternative(node, ctx_name):
@op_lifter([MaxPoolGrad]) @op_lifter([MaxPoolGrad])
def local_pool_dnn_grad_stride(node, ctx_name): def local_pool_dnn_grad_stride(node, ctx_name):
if not dnn_available(ctx_name): if not dnn_available(ctx_name):
return raise_no_cudnn()
if not node.op.ignore_border: if not node.op.ignore_border:
return return
inp, out, out_grad = node.inputs inp, out, out_grad = node.inputs
...@@ -1443,7 +1449,7 @@ def local_pool_dnn_grad_stride(node, ctx_name): ...@@ -1443,7 +1449,7 @@ def local_pool_dnn_grad_stride(node, ctx_name):
@op_lifter([AveragePoolGrad]) @op_lifter([AveragePoolGrad])
def local_avg_pool_dnn_grad_stride(node, ctx_name): def local_avg_pool_dnn_grad_stride(node, ctx_name):
if not dnn_available(ctx_name): if not dnn_available(ctx_name):
return raise_no_cudnn()
if not node.op.ignore_border: if not node.op.ignore_border:
return return
inp, out_grad = node.inputs inp, out_grad = node.inputs
...@@ -1468,7 +1474,7 @@ def local_avg_pool_dnn_grad_stride(node, ctx_name): ...@@ -1468,7 +1474,7 @@ def local_avg_pool_dnn_grad_stride(node, ctx_name):
def local_softmax_dnn(node): def local_softmax_dnn(node):
if isinstance(node.op, GpuSoftmax): if isinstance(node.op, GpuSoftmax):
if not dnn_available(node.outputs[0].type.context_name): if not dnn_available(node.outputs[0].type.context_name):
return raise_no_cudnn()
ins = node.inputs[0].dimshuffle(0, 1, 'x', 'x') ins = node.inputs[0].dimshuffle(0, 1, 'x', 'x')
ins = gpu_contiguous(ins) ins = gpu_contiguous(ins)
out = GpuDnnSoftmax('accurate', 'channel')(ins) out = GpuDnnSoftmax('accurate', 'channel')(ins)
...@@ -1498,7 +1504,7 @@ def local_log_softmax_dnn(node): ...@@ -1498,7 +1504,7 @@ def local_log_softmax_dnn(node):
def local_logsoftmax_to_dnn(node, ctx_name): def local_logsoftmax_to_dnn(node, ctx_name):
if not dnn_available(ctx_name) or version() < 3000: if not dnn_available(ctx_name) or version() < 3000:
# No log-softmax before cudnn v3 # No log-softmax before cudnn v3
return raise_no_cudnn("Need CuDNN v3 for LogSoftmax")
# Transform the input in the format expected by GpuDnnSoftmax # Transform the input in the format expected by GpuDnnSoftmax
inp = node.inputs[0] inp = node.inputs[0]
...@@ -1534,7 +1540,7 @@ gpu_seqopt.register("NoCuDNNRaise", NoCuDNNRaise(), 0, 'cudnn') ...@@ -1534,7 +1540,7 @@ gpu_seqopt.register("NoCuDNNRaise", NoCuDNNRaise(), 0, 'cudnn')
@op_lifter([SoftmaxGrad]) @op_lifter([SoftmaxGrad])
def local_softmax_dnn_grad(node, ctx_name): def local_softmax_dnn_grad(node, ctx_name):
if not dnn_available(ctx_name): if not dnn_available(ctx_name):
return raise_no_cudnn("CuDNN needed for SoftmaxGrad")
ins = [] ins = []
for n in node.inputs: for n in node.inputs:
n = as_gpuarray_variable(n, ctx_name) n = as_gpuarray_variable(n, ctx_name)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论