Skip to content

Commit 90abd9d

Browse files
authored
Merge pull request #9704 from lgone2000/fixunittest
fix pool and conv3d unittest when paddle is not build with gpu
2 parents d655417 + 9d95ccc commit 90abd9d

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

python/paddle/fluid/tests/unittests/test_conv3d_op.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,18 @@ def setUp(self):
9797
}
9898
self.outputs = {'Output': output}
9999

100+
def testcudnn(self):
101+
return core.is_compiled_with_cuda() and self.use_cudnn
102+
100103
def test_check_output(self):
101-
if self.use_cudnn:
104+
if self.testcudnn():
102105
place = core.CUDAPlace(0)
103106
self.check_output_with_place(place, atol=1e-5)
104107
else:
105108
self.check_output()
106109

107110
def test_check_grad(self):
108-
if self.use_cudnn:
111+
if self.testcudnn():
109112
place = core.CUDAPlace(0)
110113
self.check_grad_with_place(
111114
place,
@@ -117,7 +120,7 @@ def test_check_grad(self):
117120
set(['Input', 'Filter']), 'Output', max_relative_error=0.03)
118121

119122
def test_check_grad_no_filter(self):
120-
if self.use_cudnn:
123+
if self.testcudnn():
121124
place = core.CUDAPlace(0)
122125
self.check_grad_with_place(
123126
place, ['Input'],
@@ -132,7 +135,7 @@ def test_check_grad_no_filter(self):
132135
no_grad_set=set(['Filter']))
133136

134137
def test_check_grad_no_input(self):
135-
if self.use_cudnn:
138+
if self.testcudnn():
136139
place = core.CUDAPlace(0)
137140
self.check_grad_with_place(
138141
place, ['Filter'],

python/paddle/fluid/tests/unittests/test_pool2d_op.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,11 @@ def setUp(self):
109109

110110
self.outputs = {'Out': output}
111111

112+
def testcudnn(self):
113+
return core.is_compiled_with_cuda() and self.use_cudnn
114+
112115
def test_check_output(self):
113-
if self.use_cudnn:
116+
if self.testcudnn():
114117
place = core.CUDAPlace(0)
115118
self.check_output_with_place(place, atol=1e-5)
116119
else:
@@ -119,7 +122,7 @@ def test_check_output(self):
119122
def test_check_grad(self):
120123
if self.dtype == np.float16:
121124
return
122-
if self.use_cudnn and self.pool_type != "max":
125+
if self.testcudnn() and self.pool_type != "max":
123126
place = core.CUDAPlace(0)
124127
self.check_grad_with_place(
125128
place, set(['X']), 'Out', max_relative_error=0.07)

python/paddle/fluid/tests/unittests/test_pool3d_op.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,18 @@ def setUp(self):
118118

119119
self.outputs = {'Out': output.astype('float32')}
120120

121+
def testcudnn(self):
122+
return core.is_compiled_with_cuda() and self.use_cudnn
123+
121124
def test_check_output(self):
122-
if self.use_cudnn:
125+
if self.testcudnn():
123126
place = core.CUDAPlace(0)
124127
self.check_output_with_place(place, atol=1e-5)
125128
else:
126129
self.check_output()
127130

128131
def test_check_grad(self):
129-
if self.use_cudnn and self.pool_type != "max":
132+
if self.testcudnn() and self.pool_type != "max":
130133
place = core.CUDAPlace(0)
131134
self.check_grad_with_place(
132135
place, set(['X']), 'Out', max_relative_error=0.07)

0 commit comments

Comments
 (0)