|
|
@ -80,6 +80,7 @@ class TestPool2d_Op(OpTest):
|
|
|
|
def setUp(self):
|
|
|
|
def setUp(self):
|
|
|
|
self.use_cudnn = False
|
|
|
|
self.use_cudnn = False
|
|
|
|
self.use_mkldnn = False
|
|
|
|
self.use_mkldnn = False
|
|
|
|
|
|
|
|
self.dtype = np.float32
|
|
|
|
self.init_test_case()
|
|
|
|
self.init_test_case()
|
|
|
|
self.init_global_pool()
|
|
|
|
self.init_global_pool()
|
|
|
|
self.init_op_type()
|
|
|
|
self.init_op_type()
|
|
|
@ -87,11 +88,11 @@ class TestPool2d_Op(OpTest):
|
|
|
|
self.init_ceil_mode()
|
|
|
|
self.init_ceil_mode()
|
|
|
|
if self.global_pool:
|
|
|
|
if self.global_pool:
|
|
|
|
self.paddings = [0 for _ in range(len(self.paddings))]
|
|
|
|
self.paddings = [0 for _ in range(len(self.paddings))]
|
|
|
|
input = np.random.random(self.shape).astype("float32")
|
|
|
|
input = np.random.random(self.shape).astype(self.dtype)
|
|
|
|
output = self.pool2D_forward_naive(input, self.ksize, self.strides,
|
|
|
|
output = self.pool2D_forward_naive(input, self.ksize, self.strides,
|
|
|
|
self.paddings, self.global_pool,
|
|
|
|
self.paddings, self.global_pool,
|
|
|
|
self.ceil_mode).astype("float32")
|
|
|
|
self.ceil_mode).astype(self.dtype)
|
|
|
|
self.inputs = {'X': input}
|
|
|
|
self.inputs = {'X': OpTest.np_dtype_to_fluid_dtype(input)}
|
|
|
|
|
|
|
|
|
|
|
|
self.attrs = {
|
|
|
|
self.attrs = {
|
|
|
|
'strides': self.strides,
|
|
|
|
'strides': self.strides,
|
|
|
@ -105,7 +106,7 @@ class TestPool2d_Op(OpTest):
|
|
|
|
'data_format': 'AnyLayout' # TODO(dzhwinter) : should be fix latter
|
|
|
|
'data_format': 'AnyLayout' # TODO(dzhwinter) : should be fix latter
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
self.outputs = {'Out': output.astype('float32')}
|
|
|
|
self.outputs = {'Out': output}
|
|
|
|
|
|
|
|
|
|
|
|
def test_check_output(self):
|
|
|
|
def test_check_output(self):
|
|
|
|
if self.use_cudnn:
|
|
|
|
if self.use_cudnn:
|
|
|
@ -115,6 +116,8 @@ class TestPool2d_Op(OpTest):
|
|
|
|
self.check_output()
|
|
|
|
self.check_output()
|
|
|
|
|
|
|
|
|
|
|
|
def test_check_grad(self):
|
|
|
|
def test_check_grad(self):
|
|
|
|
|
|
|
|
if self.dtype == np.float16:
|
|
|
|
|
|
|
|
return
|
|
|
|
if self.use_cudnn and self.pool_type != "max":
|
|
|
|
if self.use_cudnn and self.pool_type != "max":
|
|
|
|
place = core.CUDAPlace(0)
|
|
|
|
place = core.CUDAPlace(0)
|
|
|
|
self.check_grad_with_place(
|
|
|
|
self.check_grad_with_place(
|
|
|
@ -212,36 +215,114 @@ class TestCUDNNCase1(TestPool2d_Op):
|
|
|
|
self.op_type = "pool2d"
|
|
|
|
self.op_type = "pool2d"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestFP16CUDNNCase1(TestPool2d_Op):
|
|
|
|
|
|
|
|
def init_op_type(self):
|
|
|
|
|
|
|
|
self.use_cudnn = True
|
|
|
|
|
|
|
|
self.op_type = "pool2d"
|
|
|
|
|
|
|
|
self.dtype = np.float16
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_check_output(self):
|
|
|
|
|
|
|
|
if core.is_compiled_with_cuda():
|
|
|
|
|
|
|
|
place = core.CUDAPlace(0)
|
|
|
|
|
|
|
|
if core.is_float16_supported(place):
|
|
|
|
|
|
|
|
self.check_output_with_place(place, atol=1e-3)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestCUDNNCase2(TestCase1):
|
|
|
|
class TestCUDNNCase2(TestCase1):
|
|
|
|
def init_op_type(self):
|
|
|
|
def init_op_type(self):
|
|
|
|
self.use_cudnn = True
|
|
|
|
self.use_cudnn = True
|
|
|
|
self.op_type = "pool2d"
|
|
|
|
self.op_type = "pool2d"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestFP16CUDNNCase2(TestCase1):
|
|
|
|
|
|
|
|
def init_op_type(self):
|
|
|
|
|
|
|
|
self.use_cudnn = True
|
|
|
|
|
|
|
|
self.op_type = "pool2d"
|
|
|
|
|
|
|
|
self.dtype = np.float16
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_check_output(self):
|
|
|
|
|
|
|
|
if core.is_compiled_with_cuda():
|
|
|
|
|
|
|
|
place = core.CUDAPlace(0)
|
|
|
|
|
|
|
|
if core.is_float16_supported(place):
|
|
|
|
|
|
|
|
self.check_output_with_place(place, atol=1e-3)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestCUDNNCase3(TestCase2):
|
|
|
|
class TestCUDNNCase3(TestCase2):
|
|
|
|
def init_op_type(self):
|
|
|
|
def init_op_type(self):
|
|
|
|
self.use_cudnn = True
|
|
|
|
self.use_cudnn = True
|
|
|
|
self.op_type = "pool2d"
|
|
|
|
self.op_type = "pool2d"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestFP16CUDNNCase3(TestCase2):
|
|
|
|
|
|
|
|
def init_op_type(self):
|
|
|
|
|
|
|
|
self.use_cudnn = True
|
|
|
|
|
|
|
|
self.op_type = "pool2d"
|
|
|
|
|
|
|
|
self.dtype = np.float16
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_check_output(self):
|
|
|
|
|
|
|
|
if core.is_compiled_with_cuda():
|
|
|
|
|
|
|
|
place = core.CUDAPlace(0)
|
|
|
|
|
|
|
|
if core.is_float16_supported(place):
|
|
|
|
|
|
|
|
self.check_output_with_place(place, atol=1e-3)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestCUDNNCase4(TestCase3):
|
|
|
|
class TestCUDNNCase4(TestCase3):
|
|
|
|
def init_op_type(self):
|
|
|
|
def init_op_type(self):
|
|
|
|
self.use_cudnn = True
|
|
|
|
self.use_cudnn = True
|
|
|
|
self.op_type = "pool2d"
|
|
|
|
self.op_type = "pool2d"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestFP16CUDNNCase4(TestCase3):
|
|
|
|
|
|
|
|
def init_op_type(self):
|
|
|
|
|
|
|
|
self.use_cudnn = True
|
|
|
|
|
|
|
|
self.op_type = "pool2d"
|
|
|
|
|
|
|
|
self.dtype = np.float16
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_check_output(self):
|
|
|
|
|
|
|
|
if core.is_compiled_with_cuda():
|
|
|
|
|
|
|
|
place = core.CUDAPlace(0)
|
|
|
|
|
|
|
|
if core.is_float16_supported(place):
|
|
|
|
|
|
|
|
self.check_output_with_place(place, atol=1e-3)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestCUDNNCase5(TestCase4):
|
|
|
|
class TestCUDNNCase5(TestCase4):
|
|
|
|
def init_op_type(self):
|
|
|
|
def init_op_type(self):
|
|
|
|
self.use_cudnn = True
|
|
|
|
self.use_cudnn = True
|
|
|
|
self.op_type = "pool2d"
|
|
|
|
self.op_type = "pool2d"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestFP16CUDNNCase5(TestCase4):
|
|
|
|
|
|
|
|
def init_op_type(self):
|
|
|
|
|
|
|
|
self.use_cudnn = True
|
|
|
|
|
|
|
|
self.op_type = "pool2d"
|
|
|
|
|
|
|
|
self.dtype = np.float16
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_check_output(self):
|
|
|
|
|
|
|
|
if core.is_compiled_with_cuda():
|
|
|
|
|
|
|
|
place = core.CUDAPlace(0)
|
|
|
|
|
|
|
|
if core.is_float16_supported(place):
|
|
|
|
|
|
|
|
self.check_output_with_place(place, atol=1e-3)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestCUDNNCase6(TestCase5):
|
|
|
|
class TestCUDNNCase6(TestCase5):
|
|
|
|
def init_op_type(self):
|
|
|
|
def init_op_type(self):
|
|
|
|
self.use_cudnn = True
|
|
|
|
self.use_cudnn = True
|
|
|
|
self.op_type = "pool2d"
|
|
|
|
self.op_type = "pool2d"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestFP16CUDNNCase6(TestCase5):
|
|
|
|
|
|
|
|
def init_op_type(self):
|
|
|
|
|
|
|
|
self.use_cudnn = True
|
|
|
|
|
|
|
|
self.op_type = "pool2d"
|
|
|
|
|
|
|
|
self.dtype = np.float16
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_check_output(self):
|
|
|
|
|
|
|
|
if core.is_compiled_with_cuda():
|
|
|
|
|
|
|
|
place = core.CUDAPlace(0)
|
|
|
|
|
|
|
|
if core.is_float16_supported(place):
|
|
|
|
|
|
|
|
self.check_output_with_place(place, atol=1e-3)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestCeilModeCase1(TestCUDNNCase1):
|
|
|
|
class TestCeilModeCase1(TestCUDNNCase1):
|
|
|
|
def init_ceil_mode(self):
|
|
|
|
def init_ceil_mode(self):
|
|
|
|
self.ceil_mode = True
|
|
|
|
self.ceil_mode = True
|
|
|
|