提交 e9ea0187 authored 作者: Frederic's avatar Frederic

Use macro (numpy and cuda backend)

上级 df512c7f
...@@ -50,33 +50,33 @@ class GpuConv3D(GpuOp): ...@@ -50,33 +50,33 @@ class GpuConv3D(GpuOp):
//printf("\t\t\t\tConv3DGPU c code\\n"); //printf("\t\t\t\tConv3DGPU c code\\n");
//Check dimensionality of inputs //Check dimensionality of inputs
if (%(W)s->nd != 5) if (CudaNdarray_NDIM(%(W)s) != 5)
{ {
PyErr_Format(PyExc_ValueError, "GpuConv3D: W must be a 5 dimensional CudaNdarray"); PyErr_Format(PyExc_ValueError, "GpuConv3D: W must be a 5 dimensional CudaNdarray");
%(fail)s %(fail)s
} }
if (%(V)s->nd != 5) if (CudaNdarray_NDIM(%(V)s) != 5)
{ {
PyErr_Format(PyExc_ValueError, "GpuConv3D: V must be a 5 dimensional CudaNdarray"); PyErr_Format(PyExc_ValueError, "GpuConv3D: V must be a 5 dimensional CudaNdarray");
%(fail)s %(fail)s
} }
if (%(b)s->nd != 1) if (CudaNdarray_NDIM(%(b)s) != 1)
{ {
PyErr_Format(PyExc_ValueError, "GpuConv3D: b must be a vector CudaNdarray"); PyErr_Format(PyExc_ValueError, "GpuConv3D: b must be a vector CudaNdarray");
%(fail)s %(fail)s
} }
if (%(d)s->nd != 1) if (CudaNdarray_NDIM(%(d)s) != 1)
{ {
PyErr_Format(PyExc_ValueError, "GpuConv3D: d must be a vector CudaNdarray"); PyErr_Format(PyExc_ValueError, "GpuConv3D: d must be a vector CudaNdarray");
%(fail)s %(fail)s
} }
if (%(d)s->dimensions[0] != 3) if (PyArray_DIMS(%(d)s)[0] != 3)
{ {
PyErr_Format(PyExc_ValueError, "GpuConv3D: 3 stride length arguments expected (row, col, time) but %%li were given", %(d)s->dimensions[0]); PyErr_Format(PyExc_ValueError, "GpuConv3D: 3 stride length arguments expected (row, col, time) but %%li were given", PyArray_DIMS(%(d)s)[0]);
%(fail)s %(fail)s
} }
......
...@@ -79,33 +79,33 @@ class GpuConvGrad3D(GpuOp): ...@@ -79,33 +79,33 @@ class GpuConvGrad3D(GpuOp):
//printf("\t\t\t\tGpuConvGrad3DW c code\\n"); //printf("\t\t\t\tGpuConvGrad3DW c code\\n");
//Check dimensionality of inputs //Check dimensionality of inputs
if (%(dCdH)s->nd != 5) if (CudaNdarray_NDIM(%(dCdH)s) != 5)
{ {
PyErr_Format(PyExc_ValueError, "GpuConvGrad3D: dCdH must be a 5-d CudaNdArray"); PyErr_Format(PyExc_ValueError, "GpuConvGrad3D: dCdH must be a 5-d CudaNdArray");
%(fail)s %(fail)s
} }
if (%(V)s->nd != 5) if (CudaNdarray_NDIM(%(V)s) != 5)
{ {
PyErr_Format(PyExc_ValueError, "GpuConvGrad3D: V must be a 5-d CudaNdArray"); PyErr_Format(PyExc_ValueError, "GpuConvGrad3D: V must be a 5-d CudaNdArray");
%(fail)s %(fail)s
} }
if (%(WShape)s->nd != 1) if (CudaNdarray_NDIM(%(WShape)s) != 1)
{ {
PyErr_Format(PyExc_ValueError, "GpuConvGrad3D: WShape must be a 1-d CudaNdArray"); PyErr_Format(PyExc_ValueError, "GpuConvGrad3D: WShape must be a 1-d CudaNdArray");
%(fail)s %(fail)s
} }
if (%(d)s->nd != 1) if (PyArray_NDIM(%(d)s) != 1)
{ {
PyErr_Format(PyExc_ValueError, "GpuConvGrad3D: d must be a 1-d CudaNdArray"); PyErr_Format(PyExc_ValueError, "GpuConvGrad3D: d must be a 1-d CudaNdArray");
%(fail)s %(fail)s
} }
if (%(d)s->dimensions[0] != 3) if (PyArray_DIMS(%(d)s)[0] != 3)
{ {
PyErr_Format(PyExc_ValueError, "GpuConvGrad3D: 3 stride lengths arguments expected(for row, col, and time) but %%li were given", %(d)s->dimensions[0]); PyErr_Format(PyExc_ValueError, "GpuConvGrad3D: 3 stride lengths arguments expected(for row, col, and time) but %%li were given", PyArray_DIMS(%(d)s)[0]);
%(fail)s %(fail)s
} }
...@@ -113,7 +113,7 @@ class GpuConvGrad3D(GpuOp): ...@@ -113,7 +113,7 @@ class GpuConvGrad3D(GpuOp):
//Read and check sizes of inputs //Read and check sizes of inputs
const int batchSize = CudaNdarray_HOST_DIMS(%(V)s)[0]; const int batchSize = CudaNdarray_HOST_DIMS(%(V)s)[0];
if (%(WShape)s->dimensions[0] != 5) if (PyArray_DIMS(%(WShape)s)[0] != 5)
{ {
PyErr_Format(PyExc_ValueError, "GpuConvGrad3D: WShape must specify a 5-d shape"); PyErr_Format(PyExc_ValueError, "GpuConvGrad3D: WShape must specify a 5-d shape");
%(fail)s %(fail)s
......
...@@ -61,34 +61,34 @@ class GpuConvTransp3D(GpuOp): ...@@ -61,34 +61,34 @@ class GpuConvTransp3D(GpuOp):
//printf("\t\t\t\tGpuConvTransp c code\\n"); //printf("\t\t\t\tGpuConvTransp c code\\n");
//Check dimensionality of inputs //Check dimensionality of inputs
if (%(H)s->nd != 5) if (CudaNdarray_NDIM(%(H)s) != 5)
{ {
PyErr_Format(PyExc_ValueError, "GpuConvTransp3D: H must be a 5-D tensor but it is %%i-D",%(H)s->nd); PyErr_Format(PyExc_ValueError, "GpuConvTransp3D: H must be a 5-D tensor but it is %%i-D", CudaNdarray_NDIM(%(H)s));
%(fail)s %(fail)s
} }
if (%(W)s->nd != 5) if (CudaNdarray_NDIM(%(W)s) != 5)
{ {
PyErr_Format(PyExc_ValueError, "GpuConvTransp3D: W must be a 5-D tensor"); PyErr_Format(PyExc_ValueError, "GpuConvTransp3D: W must be a 5-D tensor");
%(fail)s %(fail)s
} }
if (%(b)s->nd != 1) if (CudaNdarray_NDIM(%(b)s) != 1)
{ {
PyErr_Format(PyExc_ValueError, "GpuConvTransp3D: b must be a vector"); PyErr_Format(PyExc_ValueError, "GpuConvTransp3D: b must be a vector");
%(fail)s %(fail)s
} }
if (%(d)s->nd != 1) if (PyArray_NDIM(%(d)s) != 1)
{ {
PyErr_Format(PyExc_ValueError, "GpuConvTransp3D: d must be a vector"); PyErr_Format(PyExc_ValueError, "GpuConvTransp3D: d must be a vector");
%(fail)s %(fail)s
} }
//Read and check stride arguments //Read and check stride arguments
if (%(d)s->dimensions[0] != 3) if (PyArray_DIMS(%(d)s)[0] != 3)
{ {
PyErr_Format(PyExc_ValueError,"GpuConvTransp3D: 3 stride length arguments expected (for row, col, and time) but %%li were given", %(d)s->dimensions[0]); PyErr_Format(PyExc_ValueError,"GpuConvTransp3D: 3 stride length arguments expected (for row, col, and time) but %%li were given", PyArray_DIMS(%(d)s)[0]);
%(fail)s %(fail)s
} }
{ // for fail { // for fail
...@@ -138,13 +138,13 @@ class GpuConvTransp3D(GpuOp): ...@@ -138,13 +138,13 @@ class GpuConvTransp3D(GpuOp):
if (%(RShape)s) if (%(RShape)s)
{ {
if (%(RShape)s->nd != 1) if (PyArray_NDIM(%(RShape)s) != 1)
{ {
PyErr_Format(PyExc_ValueError, "RShape must be a vector"); PyErr_Format(PyExc_ValueError, "RShape must be a vector");
%(fail)s %(fail)s
} }
if (%(RShape)s->dimensions[0] != 3) if (PyArray_DIMS(%(RShape)s)[0] != 3)
{ {
PyErr_Format(PyExc_ValueError, "RShape must specify a 3D shape ( [height,width,duration] )"); PyErr_Format(PyExc_ValueError, "RShape must specify a 3D shape ( [height,width,duration] )");
%(fail)s %(fail)s
...@@ -189,7 +189,7 @@ class GpuConvTransp3D(GpuOp): ...@@ -189,7 +189,7 @@ class GpuConvTransp3D(GpuOp):
%(fail)s; %(fail)s;
} }
} }
cudaMemset(%(R)s->devdata, 0, 4 * batchSize * inputChannels * videoHeight * videoWidth * videoDur); cudaMemset(CudaNdarray_DEV_DATA(%(R)s), 0, 4 * batchSize * inputChannels * videoHeight * videoWidth * videoDur);
{ // for fail { // for fail
......
...@@ -95,17 +95,17 @@ class GpuCrossentropySoftmaxArgmax1HotWithBias(GpuOp): ...@@ -95,17 +95,17 @@ class GpuCrossentropySoftmaxArgmax1HotWithBias(GpuOp):
fail = sub['fail'] fail = sub['fail']
sio = StringIO() sio = StringIO()
print >> sio, """ print >> sio, """
if (%(y_idx)s->nd != 1) if (CudaNdarray_NDIM(%(y_idx)s) != 1)
{ {
PyErr_SetString(PyExc_ValueError, "y_idx not 1d tensor"); PyErr_SetString(PyExc_ValueError, "y_idx not 1d tensor");
%(fail)s; %(fail)s;
} }
if (%(x)s->nd != 2) if (CudaNdarray_NDIM(%(x)s) != 2)
{ {
PyErr_SetString(PyExc_ValueError, "x not 2d tensor"); PyErr_SetString(PyExc_ValueError, "x not 2d tensor");
%(fail)s; %(fail)s;
} }
if (%(b)s->nd != 1) if (CudaNdarray_NDIM(%(b)s) != 1)
{ {
PyErr_SetString(PyExc_ValueError, "b not 1d tensor"); PyErr_SetString(PyExc_ValueError, "b not 1d tensor");
%(fail)s; %(fail)s;
...@@ -247,9 +247,9 @@ class GpuCrossentropySoftmax1HotWithBiasDx(GpuOp): ...@@ -247,9 +247,9 @@ class GpuCrossentropySoftmax1HotWithBiasDx(GpuOp):
dx, = out dx, = out
fail = sub['fail'] fail = sub['fail']
return """ return """
if ((%(dnll)s->nd != 1) if ((CudaNdarray_NDIM(%(dnll)s) != 1)
|| (%(sm)s->nd != 2) || (CudaNdarray_NDIM(%(sm)s) != 2)
|| (%(y_idx)s->nd != 1)) || (CudaNdarray_NDIM(%(y_idx)s) != 1))
{ {
PyErr_SetString(PyExc_ValueError, "rank error"); PyErr_SetString(PyExc_ValueError, "rank error");
%(fail)s; %(fail)s;
...@@ -391,7 +391,7 @@ class GpuSoftmax(GpuOp): ...@@ -391,7 +391,7 @@ class GpuSoftmax(GpuOp):
z, = out z, = out
fail = sub['fail'] fail = sub['fail']
return """ return """
if (%(x)s->nd != 2) if (CudaNdarray_NDIM(%(x)s) != 2)
{ {
PyErr_SetString(PyExc_ValueError, "rank error"); PyErr_SetString(PyExc_ValueError, "rank error");
%(fail)s; %(fail)s;
...@@ -556,12 +556,12 @@ class GpuSoftmaxWithBias(GpuOp): ...@@ -556,12 +556,12 @@ class GpuSoftmaxWithBias(GpuOp):
z, = out z, = out
fail = sub['fail'] fail = sub['fail']
return """ return """
if (%(x)s->nd != 2) if (CudaNdarray_NDIM(%(x)s) != 2)
{ {
PyErr_SetString(PyExc_ValueError, "rank error input"); PyErr_SetString(PyExc_ValueError, "rank error input");
%(fail)s; %(fail)s;
} }
if (%(b)s->nd != 1) if (CudaNdarray_NDIM(%(b)s) != 1)
{ {
PyErr_SetString(PyExc_ValueError, "rank error for the bias"); PyErr_SetString(PyExc_ValueError, "rank error for the bias");
%(fail)s; %(fail)s;
......
...@@ -148,20 +148,20 @@ class CURAND_Base(GpuOp): ...@@ -148,20 +148,20 @@ class CURAND_Base(GpuOp):
int n_elements = 1; int n_elements = 1;
int must_alloc_sample = ((NULL == %(o_sample)s) int must_alloc_sample = ((NULL == %(o_sample)s)
|| !CudaNdarray_Check(py_%(o_sample)s) || !CudaNdarray_Check(py_%(o_sample)s)
|| (%(o_sample)s->nd != %(ndim)s)); || (CudaNdarray_NDIM(%(o_sample)s) != %(ndim)s));
if (%(size)s->nd != 1) if (PyArray_NDIM(%(size)s) != 1)
{ {
PyErr_SetString(PyExc_ValueError, "size must be vector"); PyErr_SetString(PyExc_ValueError, "size must be vector");
%(fail)s %(fail)s
} }
if (%(size)s->dimensions[0] != %(ndim)s) if (PyArray_DIMS(%(size)s)[0] != %(ndim)s)
{ {
PyErr_Format(PyExc_ValueError, "size must have length %%i (not %%i)", PyErr_Format(PyExc_ValueError, "size must have length %%i (not %%i)",
%(ndim)s, %(size)s->dimensions[0]); %(ndim)s, PyArray_DIMS(%(size)s)[0]);
%(fail)s %(fail)s
} }
if (PyArray_DESCR(%(size)s)->type_num != NPY_INT32) if (PyArray_TYPE(%(size)s) != NPY_INT32)
{ {
PyErr_SetString(PyExc_ValueError, "size must be int32"); PyErr_SetString(PyExc_ValueError, "size must be int32");
%(fail)s %(fail)s
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论