提交 4d6df670 authored 作者: Pascal Lamblin's avatar Pascal Lamblin

Small fixes after the release

- make CudaNdarray_SIZE return a size_t - more informative error messages for shape mismatches in Conv2D
上级 63b7b834
...@@ -1176,7 +1176,7 @@ class GpuCAReduce(GpuOp): ...@@ -1176,7 +1176,7 @@ class GpuCAReduce(GpuOp):
int verbose = 0; int verbose = 0;
dim3 n_threads( dim3 n_threads(
std::min(CudaNdarray_SIZE(%(x)s), std::min(CudaNdarray_SIZE(%(x)s),
NUM_VECTOR_OP_THREADS_PER_BLOCK)); (size_t) NUM_VECTOR_OP_THREADS_PER_BLOCK));
dim3 n_blocks(1); dim3 n_blocks(1);
if (verbose) printf("running kernel_reduce_ccontig_%(name)s" if (verbose) printf("running kernel_reduce_ccontig_%(name)s"
" n_threads.x=%%d, size=%%d, ndim=%%d\\n", " n_threads.x=%%d, size=%%d, ndim=%%d\\n",
...@@ -1739,7 +1739,7 @@ class GpuCAReduce(GpuOp): ...@@ -1739,7 +1739,7 @@ class GpuCAReduce(GpuOp):
""" % locals() """ % locals()
def c_code_cache_version_apply(self, node): def c_code_cache_version_apply(self, node):
version = [11] # the version corresponding to the c code in this Op version = [12] # the version corresponding to the c code in this Op
# now we insert versions for the ops on which we depend... # now we insert versions for the ops on which we depend...
scalar_node = Apply(self.scalar_op, scalar_node = Apply(self.scalar_op,
...@@ -3343,13 +3343,13 @@ class GpuAlloc(GpuOp): ...@@ -3343,13 +3343,13 @@ class GpuAlloc(GpuOp):
if (%(memset_0)s && CudaNdarray_is_c_contiguous(%(out)s)) if (%(memset_0)s && CudaNdarray_is_c_contiguous(%(out)s))
{ {
cudaError_t err = cudaMemset(%(out)s->devdata, 0, cudaError_t err = cudaMemset(%(out)s->devdata, 0,
CudaNdarray_SIZEt(%(out)s) * 4); CudaNdarray_SIZE(%(out)s) * 4);
if (cudaSuccess != err) if (cudaSuccess != err)
{ {
PyErr_Format(PyExc_MemoryError, PyErr_Format(PyExc_MemoryError,
"GpuAlloc: Error memsetting %%ld" "GpuAlloc: Error memsetting %%ld"
" bytes of device memory. %%s", " bytes of device memory. %%s",
(long)(CudaNdarray_SIZEt(%(out)s) * 4), (long)(CudaNdarray_SIZE(%(out)s) * 4),
cudaGetErrorString(err)); cudaGetErrorString(err));
Py_XDECREF(%(out)s); Py_XDECREF(%(out)s);
%(out)s = NULL; %(out)s = NULL;
...@@ -3374,7 +3374,7 @@ class GpuAlloc(GpuOp): ...@@ -3374,7 +3374,7 @@ class GpuAlloc(GpuOp):
return [None for i in inputs] return [None for i in inputs]
def c_code_cache_version(self): def c_code_cache_version(self):
return (9,) return (10,)
def do_constant_folding(self, node): def do_constant_folding(self, node):
for client in node.outputs[0].clients: for client in node.outputs[0].clients:
......
...@@ -848,7 +848,7 @@ PyObject * CudaNdarray_Reshape(CudaNdarray * self, PyObject * shape) ...@@ -848,7 +848,7 @@ PyObject * CudaNdarray_Reshape(CudaNdarray * self, PyObject * shape)
// check shape tuple // check shape tuple
unsigned int rval_nd; unsigned int rval_nd;
unsigned int * rval_dims; unsigned int * rval_dims;
unsigned int rval_size = 1; size_t rval_size = 1;
if (PyTuple_Check(shape)){ if (PyTuple_Check(shape)){
// copy shape to integer array // copy shape to integer array
...@@ -884,7 +884,7 @@ PyObject * CudaNdarray_Reshape(CudaNdarray * self, PyObject * shape) ...@@ -884,7 +884,7 @@ PyObject * CudaNdarray_Reshape(CudaNdarray * self, PyObject * shape)
// calculate new size, assert same as old size // calculate new size, assert same as old size
if (rval_size != CudaNdarray_SIZE(self)) if (rval_size != CudaNdarray_SIZE(self))
{ {
PyErr_Format(PyExc_ValueError, "size must remain unchanged, changed from %i to %i", CudaNdarray_SIZE(self), rval_size); PyErr_Format(PyExc_ValueError, "size must remain unchanged, changed from %lld to %lld", CudaNdarray_SIZE(self), rval_size);
free(rval_dims); free(rval_dims);
return NULL; return NULL;
} }
...@@ -1309,7 +1309,7 @@ CudaNdarray_TakeFrom(CudaNdarray * self, PyObject *args){ ...@@ -1309,7 +1309,7 @@ CudaNdarray_TakeFrom(CudaNdarray * self, PyObject *args){
if (cpu_err_var != 0) { if (cpu_err_var != 0) {
PyErr_Format( PyErr_Format(
PyExc_IndexError, PyExc_IndexError,
"CudaNdarray_TakeFrom: One of the index value is out of bound.\n", "CudaNdarray_TakeFrom: One of the index value is out of bound. Error code: %i.\n",
cpu_err_var); cpu_err_var);
// Must reset it to 0 to don't reset it before each use. // Must reset it to 0 to don't reset it before each use.
err = cudaMemset((void*)err_var, 0, sizeof(int)); err = cudaMemset((void*)err_var, 0, sizeof(int));
...@@ -5106,7 +5106,7 @@ CudaNdarray_DEV_DATA(const CudaNdarray * self) ...@@ -5106,7 +5106,7 @@ CudaNdarray_DEV_DATA(const CudaNdarray * self)
/** /**
* Return the number of elements in the ndarray (product of the dimensions) * Return the number of elements in the ndarray (product of the dimensions)
*/ */
int size_t
CudaNdarray_SIZE(const CudaNdarray *self) CudaNdarray_SIZE(const CudaNdarray *self)
{ {
if (self->nd == -1) return 0; if (self->nd == -1) return 0;
...@@ -5117,17 +5117,6 @@ CudaNdarray_SIZE(const CudaNdarray *self) ...@@ -5117,17 +5117,6 @@ CudaNdarray_SIZE(const CudaNdarray *self)
} }
return size; 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 * PyObject *
CudaNdarray_SIZE_Object(const CudaNdarray *self, void *closure) CudaNdarray_SIZE_Object(const CudaNdarray *self, void *closure)
......
...@@ -285,10 +285,7 @@ DllExport float *CudaNdarray_DEV_DATA(const CudaNdarray * self); ...@@ -285,10 +285,7 @@ DllExport float *CudaNdarray_DEV_DATA(const CudaNdarray * self);
/** /**
* Return the number of elements in the ndarray (product of the dimensions) * Return the number of elements in the ndarray (product of the dimensions)
*/ */
DllExport int CudaNdarray_SIZE(const CudaNdarray *self); DllExport size_t 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); static PyObject *CudaNdarray_SIZE_Object(const CudaNdarray *self, void *closure);
......
...@@ -674,22 +674,30 @@ class ConvOp(OpenMPOp): ...@@ -674,22 +674,30 @@ class ConvOp(OpenMPOp):
if any(x is None for x in imshp): if any(x is None for x in imshp):
imshp = tuple(img2d.shape[1:]) imshp = tuple(img2d.shape[1:])
if imshp != img2d.shape[1:]: if imshp != img2d.shape[1:]:
raise ValueError("bad shape", imshp, img2d.shape[1:]) raise ValueError("The image shape provided at build time "
"is different from the one passed at run time",
imshp, img2d.shape[1:])
kshp = self.kshp kshp = self.kshp
if any(x is None for x in kshp): if any(x is None for x in kshp):
kshp = tuple(filtersflipped.shape[2:]) kshp = tuple(filtersflipped.shape[2:])
if kshp != filtersflipped.shape[2:]: if kshp != filtersflipped.shape[2:]:
raise ValueError("bad shape", kshp, filtersflipped.shape[2:]) raise ValueError("The filter shape provided at build time "
"is different from the one passed at run time",
kshp, filtersflipped.shape[2:])
bsize = self.bsize bsize = self.bsize
if bsize is None: if bsize is None:
bsize = img2d.shape[0] bsize = img2d.shape[0]
elif bsize != img2d.shape[0]: elif bsize != img2d.shape[0]:
raise ValueError("bad shape", bsize, img2d.shape[0]) raise ValueError("The batch size provided at build time "
"is different from the one passed at run time",
bsize, img2d.shape[0])
nkern = self.nkern nkern = self.nkern
if nkern is None: if nkern is None:
nkern = filtersflipped.shape[0] nkern = filtersflipped.shape[0]
elif nkern != filtersflipped.shape[0]: elif nkern != filtersflipped.shape[0]:
raise ValueError("bad shape", nkern, filtersflipped.shape[0]) raise ValueError("The number of filters provided at build time "
"is different from the one passed at run time",
nkern, filtersflipped.shape[0])
imshp_logical = self.imshp_logical imshp_logical = self.imshp_logical
if imshp_logical[0] is None: if imshp_logical[0] is None:
...@@ -984,7 +992,7 @@ class ConvOp(OpenMPOp): ...@@ -984,7 +992,7 @@ class ConvOp(OpenMPOp):
return ['<numpy/noprefix.h>', '<iostream>', '<sstream>'] return ['<numpy/noprefix.h>', '<iostream>', '<sstream>']
def c_code_cache_version(self): def c_code_cache_version(self):
return (14, self.openmp, blas.blas_header_version()) return (15, self.openmp, blas.blas_header_version())
def c_support_code(self): def c_support_code(self):
return """ return """
...@@ -1088,7 +1096,8 @@ using namespace std; ...@@ -1088,7 +1096,8 @@ using namespace std;
d["assert_size"] += """ d["assert_size"] += """
if(%(value)s != %(expected)s){ if(%(value)s != %(expected)s){
PyErr_Format(PyExc_ValueError, PyErr_Format(PyExc_ValueError,
"the hard coded shape (%%ld) isn't the run time shape (%%ld).", "The hardcoded shape for the number of rows in the filter "
"(%%ld) isn't the run time shape (%%ld).",
(long)%(value)s, (long)%(expected)s); (long)%(value)s, (long)%(expected)s);
%(fail)s; %(fail)s;
} }
...@@ -1100,7 +1109,8 @@ if(%(value)s != %(expected)s){ ...@@ -1100,7 +1109,8 @@ if(%(value)s != %(expected)s){
d["assert_size"] += """ d["assert_size"] += """
if(%(value)s != %(expected)s){ if(%(value)s != %(expected)s){
PyErr_Format(PyExc_ValueError, PyErr_Format(PyExc_ValueError,
"the hard coded shape (%%ld) isn't the run time shape (%%ld).", "The hardcoded shape for the number of columns in the filter "
"(%%ld) isn't the run time shape (%%ld).",
(long)%(value)s, (long)%(expected)s); (long)%(value)s, (long)%(expected)s);
%(fail)s; %(fail)s;
} }
...@@ -1112,7 +1122,8 @@ if(%(value)s != %(expected)s){ ...@@ -1112,7 +1122,8 @@ if(%(value)s != %(expected)s){
d["assert_size"] += """ d["assert_size"] += """
if(%(value)s != %(expected)s){ if(%(value)s != %(expected)s){
PyErr_Format(PyExc_ValueError, PyErr_Format(PyExc_ValueError,
"the hard coded shape (%%ld) isn't the run time shape (%%ld).", "The hardcoded shape for the number of rows in the output "
"(%%ld) isn't the run time shape (%%ld).",
(long)%(value)s, (long)%(expected)s); (long)%(value)s, (long)%(expected)s);
%(fail)s; %(fail)s;
} }
...@@ -1124,7 +1135,8 @@ if(%(value)s != %(expected)s){ ...@@ -1124,7 +1135,8 @@ if(%(value)s != %(expected)s){
d["assert_size"] += """ d["assert_size"] += """
if(%(value)s != %(expected)s){ if(%(value)s != %(expected)s){
PyErr_Format(PyExc_ValueError, PyErr_Format(PyExc_ValueError,
"the hard coded shape (%%ld) isn't the run time shape (%%ld).", "The hardcoded shape for the number of columns in the output "
"(%%ld) isn't the run time shape (%%ld).",
(long)%(value)s, (long)%(expected)s); (long)%(value)s, (long)%(expected)s);
%(fail)s; %(fail)s;
} }
...@@ -1136,7 +1148,8 @@ if(%(value)s != %(expected)s){ ...@@ -1136,7 +1148,8 @@ if(%(value)s != %(expected)s){
d["assert_size"] += """ d["assert_size"] += """
if(%(value)s != %(expected)s){ if(%(value)s != %(expected)s){
PyErr_Format(PyExc_ValueError, PyErr_Format(PyExc_ValueError,
"the hard coded shape (%%ld) isn't the run time shape (%%ld).", "The hardcoded shape for the image stack size (%%ld) "
"isn't the run time shape (%%ld).",
(long)%(value)s, (long)%(expected)s); (long)%(value)s, (long)%(expected)s);
%(fail)s; %(fail)s;
} }
...@@ -1146,7 +1159,8 @@ if(%(value)s != %(expected)s){ ...@@ -1146,7 +1159,8 @@ if(%(value)s != %(expected)s){
d["assert_size"] += """ d["assert_size"] += """
if(%(value)s != %(expected)s){ if(%(value)s != %(expected)s){
PyErr_Format(PyExc_ValueError, PyErr_Format(PyExc_ValueError,
"the hard coded shape (%%ld) isn't the run time shape (%%ld).", "The hardcoded shape for the kernel stack size (%%ld) "
"isn't the run time shape (%%ld).",
(long)%(value)s, (long)%(expected)s); (long)%(value)s, (long)%(expected)s);
%(fail)s; %(fail)s;
} }
...@@ -1158,7 +1172,8 @@ if(%(value)s != %(expected)s){ ...@@ -1158,7 +1172,8 @@ if(%(value)s != %(expected)s){
d["assert_size"] += """ d["assert_size"] += """
if(%(value)s != %(expected)s){ if(%(value)s != %(expected)s){
PyErr_Format(PyExc_ValueError, PyErr_Format(PyExc_ValueError,
"the hard coded shape (%%ld) isn't the run time shape (%%ld).", "The hardcoded shape for the number of rows in the image "
"(%%ld) isn't the run time shape (%%ld).",
(long)%(value)s, (long)%(expected)s); (long)%(value)s, (long)%(expected)s);
%(fail)s; %(fail)s;
} }
...@@ -1170,7 +1185,8 @@ if(%(value)s != %(expected)s){ ...@@ -1170,7 +1185,8 @@ if(%(value)s != %(expected)s){
d["assert_size"] += """ d["assert_size"] += """
if(%(value)s != %(expected)s){ if(%(value)s != %(expected)s){
PyErr_Format(PyExc_ValueError, PyErr_Format(PyExc_ValueError,
"the hard coded shape (%%ld) isn't the run time shape (%%ld).", "The hardcoded shape for the number of columns in the image "
"(%%ld) isn't the run time shape (%%ld).",
(long)%(value)s, (long)%(expected)s); (long)%(value)s, (long)%(expected)s);
%(fail)s; %(fail)s;
} }
...@@ -1182,7 +1198,8 @@ if(%(value)s != %(expected)s){ ...@@ -1182,7 +1198,8 @@ if(%(value)s != %(expected)s){
d["assert_size"] += """ d["assert_size"] += """
if(%(value)s != %(expected)s){ if(%(value)s != %(expected)s){
PyErr_Format(PyExc_ValueError, PyErr_Format(PyExc_ValueError,
"the hard coded shape (%%ld) isn't the run time shape (%%ld).", "The hardcoded shape for the batch size (%%ld) "
"isn't the run time shape (%%ld).",
(long)%(value)s, (long)%(expected)s); (long)%(value)s, (long)%(expected)s);
%(fail)s; %(fail)s;
} }
...@@ -1194,7 +1211,8 @@ if(%(value)s != %(expected)s){ ...@@ -1194,7 +1211,8 @@ if(%(value)s != %(expected)s){
d["assert_size"] += """ d["assert_size"] += """
if(%(value)s != %(expected)s){ if(%(value)s != %(expected)s){
PyErr_Format(PyExc_ValueError, PyErr_Format(PyExc_ValueError,
"the hard coded shape (%%ld) isn't the run time shape (%%ld).", "The hardcoded shape for the number of kernels in the filter "
"(%%ld) isn't the run time shape (%%ld).",
(long)%(value)s, (long)%(expected)s); (long)%(value)s, (long)%(expected)s);
%(fail)s; %(fail)s;
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论