提交 674f8d51 authored 作者: Frédéric Bastien's avatar Frédéric Bastien 提交者: GitHub

Merge pull request #5636 from abergeron/fix_pool

Fix overflow in pooling
...@@ -208,10 +208,11 @@ KERNEL void ave_pool3d_kernel(const ga_size nthreads, ...@@ -208,10 +208,11 @@ KERNEL void ave_pool3d_kernel(const ga_size nthreads,
#section support_code #section support_code
// output shape for a given input padded shape, window shape and stride // output shape for a given input padded shape, window shape and stride
// We use ssize_t in the max since this is done to avoid negative results.
#define OUTPUT_DIMS(in_dim, ws, st) \ #define OUTPUT_DIMS(in_dim, ws, st) \
(IGNORE_BORDER ? (in_dim - ws)/st + 1 : \ (IGNORE_BORDER ? (in_dim - ws)/st + 1 : \
(st > ws ? (in_dim - 1)/st + 1 : \ (st > ws ? (in_dim - 1)/st + 1 : \
std::max<size_t>(0, (in_dim - 1 - ws + st)/st) + 1)) std::max<ssize_t>(0, (in_dim - 1 - ws + st)/st) + 1))
#section support_code_struct #section support_code_struct
......
...@@ -106,7 +106,7 @@ KERNEL void max_pool3d_rop_kernel(const ga_size nthreads, ...@@ -106,7 +106,7 @@ KERNEL void max_pool3d_rop_kernel(const ga_size nthreads,
#define OUTPUT_DIMS(in_dim, ws, st) \ #define OUTPUT_DIMS(in_dim, ws, st) \
(IGNORE_BORDER ? (in_dim - ws)/st + 1 : \ (IGNORE_BORDER ? (in_dim - ws)/st + 1 : \
(st > ws ? (in_dim - 1)/st + 1 : \ (st > ws ? (in_dim - 1)/st + 1 : \
std::max<size_t>(0, (in_dim - 1 - ws + st)/st) + 1)) std::max<ssize_t>(0, (in_dim - 1 - ws + st)/st) + 1))
#section support_code_struct #section support_code_struct
......
...@@ -34,7 +34,7 @@ class TestPool(unittest.TestCase): ...@@ -34,7 +34,7 @@ class TestPool(unittest.TestCase):
ds_op(inp, [2, 2], pad=[1, 1]) ds_op(inp, [2, 2], pad=[1, 1])
def test_pool_c_interface(self): def test_pool_c_interface(self):
gpu_mode = copy.copy(mode_with_gpu).excluding("cudnn") gpu_mode = mode_with_gpu.excluding("cudnn")
gpu_mode.check_py_code = False gpu_mode.check_py_code = False
shp = (2, 2, 2, 2) shp = (2, 2, 2, 2)
...@@ -47,6 +47,19 @@ class TestPool(unittest.TestCase): ...@@ -47,6 +47,19 @@ class TestPool(unittest.TestCase):
f = theano.function([], ds_op(inp, [2, 2], pad=pad), mode=gpu_mode) f = theano.function([], ds_op(inp, [2, 2], pad=pad), mode=gpu_mode)
f() f()
def test_pool_big_ws(self):
gpu_mode = mode_with_gpu.excluding("cudnn")
gpu_mode.check_py_code = False
shp = (2, 2, 2, 2)
inp = theano.shared(rand(*shp), 'a')
inp = tensor.as_tensor_variable(inp)
ds_op = GpuPool(ignore_border=False, mode='average_exc_pad', ndim=2)
pad = tensor.as_tensor_variable([0, 0])
f = theano.function([], ds_op(inp, [5, 5], stride=[1, 1], pad=pad),
mode=gpu_mode)
f()
def test_pool2d(): def test_pool2d():
shps = [(1, 12), shps = [(1, 12),
...@@ -88,7 +101,7 @@ def test_pool2d(): ...@@ -88,7 +101,7 @@ def test_pool2d():
ref_mode = copy.copy(mode_without_gpu) ref_mode = copy.copy(mode_without_gpu)
ref_mode.check_py_code = False ref_mode.check_py_code = False
gpu_mode = copy.copy(mode_with_gpu).excluding("cudnn") gpu_mode = mode_with_gpu.excluding("cudnn")
gpu_mode.check_py_code = False gpu_mode.check_py_code = False
for shp in shps: for shp in shps:
...@@ -198,7 +211,7 @@ def test_pool3d(): ...@@ -198,7 +211,7 @@ def test_pool3d():
ref_mode = copy.copy(mode_without_gpu) ref_mode = copy.copy(mode_without_gpu)
ref_mode.check_py_code = False ref_mode.check_py_code = False
gpu_mode = copy.copy(mode_with_gpu).excluding("cudnn") gpu_mode = mode_with_gpu.excluding("cudnn")
gpu_mode.check_py_code = False gpu_mode.check_py_code = False
for shp in shps: for shp in shps:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论