@@ -90,20 +90,22 @@ def avg_pool3D_forward_naive(x,
9090
9191class TestPool3d_Op (OpTest ):
9292 def setUp (self ):
93+ self .op_type = "pool3d"
9394 self .use_cudnn = False
95+ self .dtype = np .float32
9496 self .init_test_case ()
9597 self .init_global_pool ()
96- self .init_op_type ()
98+ self .init_kernel_type ()
9799 self .init_pool_type ()
98100 self .init_ceil_mode ()
99101
100102 if self .global_pool :
101103 self .paddings = [0 for _ in range (len (self .paddings ))]
102- input = np .random .random (self .shape ).astype ("float32" )
104+ input = np .random .random (self .shape ).astype (self . dtype )
103105 output = self .pool3D_forward_naive (input , self .ksize , self .strides ,
104106 self .paddings , self .global_pool ,
105- self .ceil_mode ).astype ("float32" )
106- self .inputs = {'X' : input }
107+ self .ceil_mode ).astype (self . dtype )
108+ self .inputs = {'X' : OpTest . np_dtype_to_fluid_dtype ( input ) }
107109
108110 self .attrs = {
109111 'strides' : self .strides ,
@@ -116,7 +118,7 @@ def setUp(self):
116118 'data_format' : 'AnyLayout' # TODO(dzhwinter) : should be fix latter
117119 }
118120
119- self .outputs = {'Out' : output . astype ( 'float32' ) }
121+ self .outputs = {'Out' : output }
120122
121123 def testcudnn (self ):
122124 return core .is_compiled_with_cuda () and self .use_cudnn
@@ -129,6 +131,8 @@ def test_check_output(self):
129131 self .check_output ()
130132
131133 def test_check_grad (self ):
134+ if self .dtype == np .float16 :
135+ return
132136 if self .testcudnn () and self .pool_type != "max" :
133137 place = core .CUDAPlace (0 )
134138 self .check_grad_with_place (
@@ -142,8 +146,8 @@ def init_test_case(self):
142146 self .strides = [1 , 1 , 1 ]
143147 self .paddings = [0 , 0 , 0 ]
144148
145- def init_op_type (self ):
146- self . op_type = "pool3d"
149+ def init_kernel_type (self ):
150+ pass
147151
148152 def init_pool_type (self ):
149153 self .pool_type = "avg"
@@ -158,15 +162,11 @@ def init_ceil_mode(self):
158162
159163class TestCase1 (TestPool3d_Op ):
160164 def init_test_case (self ):
161- self .op_type = "pool3d"
162165 self .shape = [2 , 3 , 7 , 7 , 7 ]
163166 self .ksize = [3 , 3 , 3 ]
164167 self .strides = [1 , 1 , 1 ]
165168 self .paddings = [0 , 0 , 0 ]
166169
167- def init_op_type (self ):
168- self .op_type = "pool3d"
169-
170170 def init_pool_type (self ):
171171 self .pool_type = "avg"
172172 self .pool3D_forward_naive = avg_pool3D_forward_naive
@@ -182,9 +182,6 @@ def init_test_case(self):
182182 self .strides = [1 , 1 , 1 ]
183183 self .paddings = [1 , 1 , 1 ]
184184
185- def init_op_type (self ):
186- self .op_type = "pool3d"
187-
188185 def init_pool_type (self ):
189186 self .pool_type = "avg"
190187 self .pool3D_forward_naive = avg_pool3D_forward_naive
@@ -194,67 +191,124 @@ def init_global_pool(self):
194191
195192
196193class TestCase3 (TestPool3d_Op ):
197- def init_op_type (self ):
198- self .op_type = "pool3d"
199-
200194 def init_pool_type (self ):
201195 self .pool_type = "max"
202196 self .pool3D_forward_naive = max_pool3D_forward_naive
203197
204198
205199class TestCase4 (TestCase1 ):
206- def init_op_type (self ):
207- self .op_type = "pool3d"
208-
209200 def init_pool_type (self ):
210201 self .pool_type = "max"
211202 self .pool3D_forward_naive = max_pool3D_forward_naive
212203
213204
214205class TestCase5 (TestCase2 ):
215- def init_op_type (self ):
216- self .op_type = "pool3d"
217-
218206 def init_pool_type (self ):
219207 self .pool_type = "max"
220208 self .pool3D_forward_naive = max_pool3D_forward_naive
221209
222210
223211#--------------------test pool3d--------------------
224212class TestCUDNNCase1 (TestPool3d_Op ):
225- def init_op_type (self ):
213+ def init_kernel_type (self ):
226214 self .use_cudnn = True
227- self .op_type = "pool3d"
215+
216+
217+ class TestFP16CUDNNCase1 (TestPool3d_Op ):
218+ def init_kernel_type (self ):
219+ self .use_cudnn = True
220+ self .dtype = np .float16
221+
222+ def test_check_output (self ):
223+ if core .is_compiled_with_cuda ():
224+ place = core .CUDAPlace (0 )
225+ if core .is_float16_supported (place ):
226+ self .check_output_with_place (place , atol = 1e-3 )
228227
229228
230229class TestCUDNNCase2 (TestCase1 ):
231- def init_op_type (self ):
230+ def init_kernel_type (self ):
232231 self .use_cudnn = True
233- self .op_type = "pool3d"
232+
233+
234+ class TestFP16CUDNNCase2 (TestCase1 ):
235+ def init_kernel_type (self ):
236+ self .use_cudnn = True
237+ self .dtype = np .float16
238+
239+ def test_check_output (self ):
240+ if core .is_compiled_with_cuda ():
241+ place = core .CUDAPlace (0 )
242+ if core .is_float16_supported (place ):
243+ self .check_output_with_place (place , atol = 1e-3 )
234244
235245
236246class TestCUDNNCase3 (TestCase2 ):
237- def init_op_type (self ):
247+ def init_kernel_type (self ):
238248 self .use_cudnn = True
239- self .op_type = "pool3d"
249+
250+
251+ class TestFP16CUDNNCase3 (TestCase2 ):
252+ def init_kernel_type (self ):
253+ self .use_cudnn = True
254+ self .dtype = np .float16
255+
256+ def test_check_output (self ):
257+ if core .is_compiled_with_cuda ():
258+ place = core .CUDAPlace (0 )
259+ if core .is_float16_supported (place ):
260+ self .check_output_with_place (place , atol = 1e-3 )
240261
241262
242263class TestCUDNNCase4 (TestCase3 ):
243- def init_op_type (self ):
264+ def init_kernel_type (self ):
244265 self .use_cudnn = True
245- self .op_type = "pool3d"
266+
267+
268+ class TestFP16CUDNNCase4 (TestCase3 ):
269+ def init_kernel_type (self ):
270+ self .use_cudnn = True
271+ self .dtype = np .float16
272+
273+ def test_check_output (self ):
274+ if core .is_compiled_with_cuda ():
275+ place = core .CUDAPlace (0 )
276+ if core .is_float16_supported (place ):
277+ self .check_output_with_place (place , atol = 1e-3 )
246278
247279
248280class TestCUDNNCase5 (TestCase4 ):
249- def init_op_type (self ):
281+ def init_kernel_type (self ):
250282 self .use_cudnn = True
251- self .op_type = "pool3d"
283+
284+
285+ class TestFP16CUDNNCase5 (TestCase4 ):
286+ def init_kernel_type (self ):
287+ self .use_cudnn = True
288+ self .dtype = np .float16
289+
290+ def test_check_output (self ):
291+ if core .is_compiled_with_cuda ():
292+ place = core .CUDAPlace (0 )
293+ if core .is_float16_supported (place ):
294+ self .check_output_with_place (place , atol = 1e-3 )
252295
253296
254297class TestCUDNNCase6 (TestCase5 ):
255- def init_op_type (self ):
298+ def init_kernel_type (self ):
256299 self .use_cudnn = True
257- self .op_type = "pool3d"
300+
301+
302+ class TestFP16CUDNNCase6 (TestCase5 ):
303+ def init_kernel_type (self ):
304+ self .use_cudnn = True
305+ self .dtype = np .float16
306+
307+ def test_check_output (self ):
308+ if core .is_compiled_with_cuda ():
309+ place = core .CUDAPlace (0 )
310+ if core .is_float16_supported (place ):
311+ self .check_output_with_place (place , atol = 1e-3 )
258312
259313
260314class TestCeilModeCase1 (TestCUDNNCase1 ):
0 commit comments