提交 135b6cc6 authored 作者: Pascal Lamblin's avatar Pascal Lamblin

Merge pull request #2663 from nouiz/conv2d_test

Conv2d test
......@@ -3342,13 +3342,15 @@ class GpuAlloc(GpuOp):
}
if (%(memset_0)s && CudaNdarray_is_c_contiguous(%(out)s))
{
if (cudaSuccess != cudaMemset(%(out)s->devdata, 0,
CudaNdarray_SIZE(%(out)s) * 4))
cudaError_t err = cudaMemset(%(out)s->devdata, 0,
CudaNdarray_SIZEt(%(out)s) * 4);
if (cudaSuccess != err)
{
PyErr_Format(PyExc_MemoryError,
"GpuAlloc: Error memsetting %%d"
" bytes of device memory.",
CudaNdarray_SIZE(%(out)s) * 4);
"GpuAlloc: Error memsetting %%ld"
" bytes of device memory. %%s",
(long)(CudaNdarray_SIZEt(%(out)s) * 4),
cudaGetErrorString(err));
Py_XDECREF(%(out)s);
%(out)s = NULL;
%(fail)s;
......@@ -3372,7 +3374,7 @@ class GpuAlloc(GpuOp):
return [None for i in inputs]
def c_code_cache_version(self):
return (7,)
return (9,)
def do_constant_folding(self, node):
for client in node.outputs[0].clients:
......
......@@ -5117,6 +5117,17 @@ CudaNdarray_SIZE(const CudaNdarray *self)
}
return size;
}
size_t
CudaNdarray_SIZEt(const CudaNdarray *self)
{
if (self->nd == -1) return 0;
size_t size = 1;
for (int i = 0; i < self->nd; ++i)
{
size *= CudaNdarray_HOST_DIMS(self)[i];
}
return size;
}
PyObject *
CudaNdarray_SIZE_Object(const CudaNdarray *self, void *closure)
......
......@@ -286,6 +286,9 @@ DllExport float *CudaNdarray_DEV_DATA(const CudaNdarray * self);
* Return the number of elements in the ndarray (product of the dimensions)
*/
DllExport int CudaNdarray_SIZE(const CudaNdarray *self);
// Useful as many cuda function use size_t as input. This make sure we use the
// most precission and not int.
DllExport size_t CudaNdarray_SIZEt(const CudaNdarray *self);
static PyObject *CudaNdarray_SIZE_Object(const CudaNdarray *self, void *closure);
......
差异被折叠。
......@@ -449,6 +449,29 @@ class TestConv2D(utt.InferShapeTester):
print t2 - t1,
print
def test_fail(self):
k = theano.shared(numpy.ones((1, 1, 3, 3), dtype='float32'))
im = T.ftensor4()
out = theano.function([im],
T.nnet.conv2d(im, k, image_shape=(1, 1, 10, 10)))
self.assertRaises(ValueError, out, numpy.ones((1, 1, 20, 10),
dtype='float32'))
out = theano.function([im],
T.nnet.conv2d(im, k, filter_shape=(1, 1, 3, 2)))
self.assertRaises(ValueError, out, numpy.ones((1, 1, 10, 10),
dtype='float32'))
out = theano.function([im],
T.nnet.conv2d(im, k, filter_shape=(2, None,
None, None)))
self.assertRaises(ValueError, out, numpy.ones((1, 1, 10, 10),
dtype='float32'))
out = theano.function([im],
T.nnet.conv2d(im, k, image_shape=(1, None,
None, None)))
self.assertRaises(ValueError, out, numpy.ones((2, 1, 10, 10),
dtype='float32'))
def test_infer_shape(self):
# Note: infer_shape is incomplete and thus input and filter shapes
# must be provided explicitly
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论