提交 2513a444 authored 作者: carriepl's avatar carriepl

Merge pull request #3803 from nouiz/gpu

Enable cudnn by default when avaialable in the new back-end
...@@ -1943,29 +1943,20 @@ def local_gpu_join(node): ...@@ -1943,29 +1943,20 @@ def local_gpu_join(node):
# optimizing this case: # optimizing this case:
# join(host_from_gpu) -> host_from_gpu(gpu_join) # join(host_from_gpu) -> host_from_gpu(gpu_join)
# print "OPT: we've got a Join instance"
axis_and_tensors = node.inputs axis_and_tensors = node.inputs
# print "OPT: axis_and_tensors=", axis_and_tensors matches = [t.dtype == 'float32' and
((t.owner is not None and
matches = [(t.owner is not None and
isinstance(t.owner.op, HostFromGpu)) or isinstance(t.owner.op, HostFromGpu)) or
isinstance(t, gof.Constant) for t in axis_and_tensors[1:]] isinstance(t, gof.Constant)) for t in axis_and_tensors[1:]]
# print "OPT: matches =", matches
# if all input tensors are host_from_gpu'ified
if all(matches): if all(matches):
# the extra gpu_from_host introduced here will
# be removed by further optimizations
new_tensors = [as_cuda_ndarray_variable(t) new_tensors = [as_cuda_ndarray_variable(t)
for t in axis_and_tensors[1:]] for t in axis_and_tensors[1:]]
new_a_and_t = [axis_and_tensors[0]] + new_tensors new_a_and_t = [axis_and_tensors[0]] + new_tensors
replacement_node = host_from_gpu(gpu_join(*new_a_and_t)) replacement_node = host_from_gpu(gpu_join(*new_a_and_t))
# print "OPT: replacement_node", replacement_node
return [replacement_node] return [replacement_node]
# This is a copy of the same opt in tensor to make the tests happy, # This is a copy of the same opt in tensor to make the tests happy,
......
...@@ -300,6 +300,21 @@ def test_opt_gpujoin_onlyajoin(): ...@@ -300,6 +300,21 @@ def test_opt_gpujoin_onlyajoin():
assert numpy.all(f() == numpy.concatenate([_a, _b], axis=1)) assert numpy.all(f() == numpy.concatenate([_a, _b], axis=1))
# test mixed dtype
_b = numpy.asarray([[5, 6, 7], [8, 9, 10]], dtype='float64')
b = theano.tensor.constant(_b)
c = tensor.join(1, a, b)
f = theano.function([], c, mode=mode_with_gpu)
f()
graph_nodes = f.maker.fgraph.toposort()
assert isinstance(graph_nodes[-1].op, theano.tensor.Join)
assert numpy.all(f() == numpy.concatenate([_a, _b], axis=1))
def test_opt_gpujoin_joinvectors_elemwise_then_minusone(): def test_opt_gpujoin_joinvectors_elemwise_then_minusone():
# from a bug in gpu normal sampling # from a bug in gpu normal sampling
......
...@@ -26,7 +26,7 @@ from .type import (GpuArrayType, GpuArrayVariable, GpuArrayConstant, ...@@ -26,7 +26,7 @@ from .type import (GpuArrayType, GpuArrayVariable, GpuArrayConstant,
GpuArraySharedVariable, gpuarray_shared_constructor, GpuArraySharedVariable, gpuarray_shared_constructor,
reg_context, get_context, ContextNotDefined) reg_context, get_context, ContextNotDefined)
from .basic_ops import as_gpuarray_variable from .basic_ops import as_gpuarray_variable
from . import opt, nerv from . import dnn, opt, nerv
def transfer(x, target): def transfer(x, target):
try: try:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论