提交 94ab25ad authored 作者: Frederic Bastien's avatar Frederic Bastien

Fix GpuToGpu

上级 ba4aefff
......@@ -529,15 +529,22 @@ class GpuToGpu(Op):
def c_code(self, node, name, inputs, outputs, sub):
return """
Py_XDECREF(%(out)s);
%(out)s = pygpu_transfer(%(inp)s, %(ctx)s, 0);
%(out)s = pygpu_empty(%(inp)s->ga.nd,
%(inp)s->ga.dimensions,
%(inp)s->ga.typecode,
GpuArray_IS_C_CONTIGUOUS(&(%(inp)s->ga)) ? GA_C_ORDER:GA_F_ORDER,
%(ctx)s, Py_None);
if (%(out)s == NULL) {
%(fail)s
}
if (pygpu_transfer(%(out)s, %(inp)s)) {
%(fail)s
}
""" % {'inp': inputs[0], 'ctx': sub['params'],
'out': outputs[0], 'fail': sub['fail']}
def c_code_cache_version(self):
return (0,)
return (1,)
class GpuAlloc(HideC, Alloc):
......
......@@ -15,10 +15,10 @@ from theano.tensor.tests import test_basic
from theano.tensor.tests.test_basic import rand, safe_make_node
from theano.tests import unittest_tools as utt
from ..type import (GpuArrayType, get_context,
from ..type import (GpuArrayType, get_context, list_contexts,
gpuarray_shared_constructor)
from ..basic_ops import (
host_from_gpu, HostFromGpu, GpuFromHost, GpuReshape,
host_from_gpu, HostFromGpu, GpuFromHost, GpuReshape, GpuToGpu,
GpuAlloc, GpuAllocEmpty, GpuContiguous,
gpu_join, GpuJoin, GpuSplit, GpuEye, gpu_contiguous)
from ..subtensor import GpuSubtensor
......@@ -182,6 +182,24 @@ def test_transfer_cpu_gpu():
assert numpy.all(fv == av)
def test_transfer_gpu_gpu():
ctxs = list_contexts()
if len(ctxs) <= 1:
raise SkipError("Need more then 1 context to test multi-gpu transfer")
g = GpuArrayType(dtype='float32', broadcastable=(False, False),
context_name=ctxs[0])()
av = numpy.asarray(rng.rand(5, 4), dtype='float32')
gv = gpuarray.array(av, context=get_context(ctxs[0]))
gv2 = gpuarray.array(av, context=get_context(ctxs[1]))
f = theano.function([g], GpuToGpu(ctxs[1])(g))
theano.printing.debugprint(f)
fv = f(gv)
assert GpuArrayType.values_eq(fv, gv2)
def test_transfer_strided():
# This is just to ensure that it works in theano
# libgpuarray has a much more comprehensive suit of tests to
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论