提交 dbf9df19 authored 作者: Pascal Lamblin's avatar Pascal Lamblin

Fix offset in GpuIncSubtensor

上级 99e32f41
......@@ -300,8 +300,9 @@ class GpuIncSubtensor(IncSubtensor):
size_t dims[%(view_ndim)s];
for(int i=0; i<%(view_ndim)s; i++)
dims[i] = xview_dims[i];
zview = pygpu_fromgpudata(%(x)s->ga.data,
xview_offset,
%(x)s->ga.offset + xview_offset,
%(x)s->ga.typecode,
%(view_ndim)s,
dims,
......@@ -396,7 +397,7 @@ int sub_setarray(GpuArray *dst, GpuArray *src) {
parent_version = super(GpuIncSubtensor, self).c_code_cache_version()
if not parent_version:
return
return parent_version + (8,)
return parent_version + (9,)
class GpuAdvancedSubtensor1(HideC, tensor.AdvancedSubtensor1):
......
......@@ -6,6 +6,7 @@ import theano
from theano import tensor
from theano.compile import DeepCopyOp
from theano.tensor.tests import test_subtensor
from theano.tests import unittest_tools as utt
from ..basic_ops import HostFromGpu, GpuFromHost, GpuContiguous
from ..elemwise import GpuDimShuffle
......@@ -136,6 +137,22 @@ def test_incsub_f16():
assert np.allclose(rval, rep)
def test_incsub_offset():
# Test for https://github.com/Theano/Theano/issues/5670
# Build a GPU variable which value will have an offset (x1)
x = gpuarray_shared_constructor(np.zeros(5, dtype=theano.config.floatX))
x1 = x[1:]
# Use inc_subtensor on it
y = tensor.vector()
z = tensor.inc_subtensor(x1[2:], y)
# Use updates so that inc_subtensor can happen inplace
f = theano.function([y], z, updates={x: z}, mode=mode_with_gpu)
utt.assert_allclose(
f([1, 2]),
np.array([0, 0, 1, 2], dtype=theano.config.floatX))
class G_advancedsubtensor(test_subtensor.TestAdvancedSubtensor):
def shortDescription(self):
return None
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论