@@ -90,20 +90,22 @@ def avg_pool3D_forward_naive(x,
90
90
91
91
class TestPool3d_Op (OpTest ):
92
92
def setUp (self ):
93
+ self .op_type = "pool3d"
93
94
self .use_cudnn = False
95
+ self .dtype = np .float32
94
96
self .init_test_case ()
95
97
self .init_global_pool ()
96
- self .init_op_type ()
98
+ self .init_kernel_type ()
97
99
self .init_pool_type ()
98
100
self .init_ceil_mode ()
99
101
100
102
if self .global_pool :
101
103
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 )
103
105
output = self .pool3D_forward_naive (input , self .ksize , self .strides ,
104
106
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 ) }
107
109
108
110
self .attrs = {
109
111
'strides' : self .strides ,
@@ -116,7 +118,7 @@ def setUp(self):
116
118
'data_format' : 'AnyLayout' # TODO(dzhwinter) : should be fix latter
117
119
}
118
120
119
- self .outputs = {'Out' : output . astype ( 'float32' ) }
121
+ self .outputs = {'Out' : output }
120
122
121
123
def testcudnn (self ):
122
124
return core .is_compiled_with_cuda () and self .use_cudnn
@@ -129,6 +131,8 @@ def test_check_output(self):
129
131
self .check_output ()
130
132
131
133
def test_check_grad (self ):
134
+ if self .dtype == np .float16 :
135
+ return
132
136
if self .testcudnn () and self .pool_type != "max" :
133
137
place = core .CUDAPlace (0 )
134
138
self .check_grad_with_place (
@@ -142,8 +146,8 @@ def init_test_case(self):
142
146
self .strides = [1 , 1 , 1 ]
143
147
self .paddings = [0 , 0 , 0 ]
144
148
145
- def init_op_type (self ):
146
- self . op_type = "pool3d"
149
+ def init_kernel_type (self ):
150
+ pass
147
151
148
152
def init_pool_type (self ):
149
153
self .pool_type = "avg"
@@ -158,15 +162,11 @@ def init_ceil_mode(self):
158
162
159
163
class TestCase1 (TestPool3d_Op ):
160
164
def init_test_case (self ):
161
- self .op_type = "pool3d"
162
165
self .shape = [2 , 3 , 7 , 7 , 7 ]
163
166
self .ksize = [3 , 3 , 3 ]
164
167
self .strides = [1 , 1 , 1 ]
165
168
self .paddings = [0 , 0 , 0 ]
166
169
167
- def init_op_type (self ):
168
- self .op_type = "pool3d"
169
-
170
170
def init_pool_type (self ):
171
171
self .pool_type = "avg"
172
172
self .pool3D_forward_naive = avg_pool3D_forward_naive
@@ -182,9 +182,6 @@ def init_test_case(self):
182
182
self .strides = [1 , 1 , 1 ]
183
183
self .paddings = [1 , 1 , 1 ]
184
184
185
- def init_op_type (self ):
186
- self .op_type = "pool3d"
187
-
188
185
def init_pool_type (self ):
189
186
self .pool_type = "avg"
190
187
self .pool3D_forward_naive = avg_pool3D_forward_naive
@@ -194,67 +191,124 @@ def init_global_pool(self):
194
191
195
192
196
193
class TestCase3 (TestPool3d_Op ):
197
- def init_op_type (self ):
198
- self .op_type = "pool3d"
199
-
200
194
def init_pool_type (self ):
201
195
self .pool_type = "max"
202
196
self .pool3D_forward_naive = max_pool3D_forward_naive
203
197
204
198
205
199
class TestCase4 (TestCase1 ):
206
- def init_op_type (self ):
207
- self .op_type = "pool3d"
208
-
209
200
def init_pool_type (self ):
210
201
self .pool_type = "max"
211
202
self .pool3D_forward_naive = max_pool3D_forward_naive
212
203
213
204
214
205
class TestCase5 (TestCase2 ):
215
- def init_op_type (self ):
216
- self .op_type = "pool3d"
217
-
218
206
def init_pool_type (self ):
219
207
self .pool_type = "max"
220
208
self .pool3D_forward_naive = max_pool3D_forward_naive
221
209
222
210
223
211
#--------------------test pool3d--------------------
224
212
class TestCUDNNCase1 (TestPool3d_Op ):
225
- def init_op_type (self ):
213
+ def init_kernel_type (self ):
226
214
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 )
228
227
229
228
230
229
class TestCUDNNCase2 (TestCase1 ):
231
- def init_op_type (self ):
230
+ def init_kernel_type (self ):
232
231
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 )
234
244
235
245
236
246
class TestCUDNNCase3 (TestCase2 ):
237
- def init_op_type (self ):
247
+ def init_kernel_type (self ):
238
248
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 )
240
261
241
262
242
263
class TestCUDNNCase4 (TestCase3 ):
243
- def init_op_type (self ):
264
+ def init_kernel_type (self ):
244
265
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 )
246
278
247
279
248
280
class TestCUDNNCase5 (TestCase4 ):
249
- def init_op_type (self ):
281
+ def init_kernel_type (self ):
250
282
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 )
252
295
253
296
254
297
class TestCUDNNCase6 (TestCase5 ):
255
- def init_op_type (self ):
298
+ def init_kernel_type (self ):
256
299
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 )
258
312
259
313
260
314
class TestCeilModeCase1 (TestCUDNNCase1 ):
0 commit comments