提交 3cc0686e authored 作者: Gijs van Tulder's avatar Gijs van Tulder

Add comments to pooling opts.

上级 a16e91f7
......@@ -1877,6 +1877,7 @@ def local_gpua_pool_dnn_alternative(op, ctx_name, inputs, outputs):
return
img = gpu_contiguous(as_gpuarray_variable(img, ctx_name))
mode = op.mode
# dnn_pool expects exactly 2 non-pooling dimensions
if img.ndim == nd + 2:
return dnn_pool(img, ws, stride=stride, pad=pad, mode=mode)
else:
......@@ -1903,6 +1904,7 @@ def local_gpua_pool_dnn_grad_stride(op, ctx_name, inputs, outputs):
out_grad = gpu_contiguous(as_gpuarray_variable(out_grad, ctx_name))
mode = op.mode
# the GPU ops expect exactly 2 non-pooling dimensions
if inp.ndim == nd + 2:
return GpuDnnPoolGrad(mode=mode)(inp,
out,
......@@ -1940,12 +1942,14 @@ def local_gpua_avg_pool_dnn_grad_stride(op, ctx_name, inputs, outputs):
out_grad = gpu_contiguous(as_gpuarray_variable(out_grad, ctx_name))
mode = op.mode
# the GPU ops expect exactly 2 non-pooling dimensions
if inp.ndim == nd + 2:
# We reuse out_grad because cuDNN does not use the value of the `out`
# argument but still checks its shape for average pooling. This
# has been observed in v2 and v3 as far as I know.
return GpuDnnPoolGrad(mode=mode)(inp, out_grad, out_grad, ws, stride, pad)
else:
# reshape to 4D or 5D with 2 non-pooling dimensions
inp_padded = pad_dims(inp, 2, nd)
out_grad_padded = pad_dims(out_grad, 2, nd)
ret_padded = GpuDnnPoolGrad(mode=mode)(inp_padded,
......
......@@ -2981,6 +2981,7 @@ if True:
if nd not in (2, 3):
return
if (img.owner and isinstance(img.owner.op, HostFromGpu)):
# dnn_pool expects exactly 2 non-pooling dimensions
if img.ndim == nd + 2:
ret = dnn_pool(gpu_contiguous(img.owner.inputs[0]),
ws, stride=stride, pad=pad, mode=mode)
......@@ -3027,6 +3028,7 @@ if True:
(out.owner and isinstance(out.owner.op, HostFromGpu)) or
(inp_grad.owner and isinstance(inp_grad.owner.op,
HostFromGpu))):
# the GPU ops expect exactly 2 non-pooling dimensions
if inp.ndim == nd + 2:
ret = GpuDnnPoolGrad(mode=mode)(gpu_contiguous(inp),
gpu_contiguous(out),
......@@ -3061,6 +3063,7 @@ if True:
if ((inp.owner and isinstance(inp.owner.op, HostFromGpu)) or
(inp_grad.owner and isinstance(inp_grad.owner.op,
HostFromGpu))):
# the GPU ops expect exactly 2 non-pooling dimensions
if inp.ndim == nd + 2:
contiguous_inp_grad = gpu_contiguous(inp_grad)
ret = GpuDnnPoolGrad(mode=mode)(gpu_contiguous(inp),
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论