@@ -70,30 +70,36 @@ def conv3d_forward_naive(input, filter, group, conv_param):
70
70
71
71
class TestConv3dOp (OpTest ):
72
72
def setUp (self ):
73
+ self .op_type = "conv3d"
73
74
self .use_cudnn = False
75
+ self .dtype = np .float32
76
+ self .init_kernel_type ()
74
77
self .init_group ()
75
- self .init_op_type ()
76
78
self .init_dilation ()
77
79
self .init_test_case ()
78
80
79
81
conv3d_param = {
80
82
'stride' : self .stride ,
81
83
'pad' : self .pad ,
82
84
'dilations' : self .dilations ,
83
- 'use_cudnn' : self .use_cudnn ,
84
85
'data_format' : 'AnyLayout' # TODO(dzhwinter) : should be fix latter
85
86
}
86
- input = np .random .random (self .input_size ).astype ("float32" )
87
- filter = np .random .random (self .filter_size ).astype ("float32" )
87
+
88
+ input = np .random .random (self .input_size ).astype (self .dtype )
89
+ filter = np .random .random (self .filter_size ).astype (self .dtype )
88
90
output = conv3d_forward_naive (input , filter , self .groups ,
89
- conv3d_param ).astype ("float32" )
91
+ conv3d_param ).astype (self . dtype )
90
92
91
- self .inputs = {'Input' : input , 'Filter' : filter }
93
+ self .inputs = {
94
+ 'Input' : OpTest .np_dtype_to_fluid_dtype (input ),
95
+ 'Filter' : OpTest .np_dtype_to_fluid_dtype (filter )
96
+ }
92
97
self .attrs = {
93
98
'strides' : self .stride ,
94
99
'paddings' : self .pad ,
95
100
'groups' : self .groups ,
96
- 'dilations' : self .dilations
101
+ 'dilations' : self .dilations ,
102
+ 'use_cudnn' : self .use_cudnn
97
103
}
98
104
self .outputs = {'Output' : output }
99
105
@@ -108,6 +114,8 @@ def test_check_output(self):
108
114
self .check_output ()
109
115
110
116
def test_check_grad (self ):
117
+ if self .dtype == np .float16 :
118
+ return
111
119
if self .testcudnn ():
112
120
place = core .CUDAPlace (0 )
113
121
self .check_grad_with_place (
@@ -120,6 +128,8 @@ def test_check_grad(self):
120
128
set (['Input' , 'Filter' ]), 'Output' , max_relative_error = 0.03 )
121
129
122
130
def test_check_grad_no_filter (self ):
131
+ if self .dtype == np .float16 :
132
+ return
123
133
if self .testcudnn ():
124
134
place = core .CUDAPlace (0 )
125
135
self .check_grad_with_place (
@@ -135,6 +145,8 @@ def test_check_grad_no_filter(self):
135
145
no_grad_set = set (['Filter' ]))
136
146
137
147
def test_check_grad_no_input (self ):
148
+ if self .dtype == np .float16 :
149
+ return
138
150
if self .testcudnn ():
139
151
place = core .CUDAPlace (0 )
140
152
self .check_grad_with_place (
@@ -163,8 +175,8 @@ def init_dilation(self):
163
175
def init_group (self ):
164
176
self .groups = 1
165
177
166
- def init_op_type (self ):
167
- self . op_type = "conv3d"
178
+ def init_kernel_type (self ):
179
+ pass
168
180
169
181
170
182
class TestCase1 (TestConv3dOp ):
@@ -235,34 +247,90 @@ def init_group(self):
235
247
self .groups = 3
236
248
237
249
250
+ #----------------Conv3dCUDNN----------------
238
251
class TestCUDNN (TestConv3dOp ):
239
- def init_op_type (self ):
252
+ def init_kernel_type (self ):
240
253
self .use_cudnn = True
241
- self .op_type = "conv3d"
254
+
255
+
256
+ class TestFP16CUDNN (TestConv3dOp ):
257
+ def init_kernel_type (self ):
258
+ self .use_cudnn = True
259
+ self .dtype = np .float16
260
+
261
+ def test_check_output (self ):
262
+ if core .is_compiled_with_cuda ():
263
+ place = core .CUDAPlace (0 )
264
+ if core .is_float16_supported (place ):
265
+ self .check_output_with_place (place , atol = 2e-2 )
242
266
243
267
244
268
class TestWithGroup1CUDNN (TestWithGroup1 ):
245
- def init_op_type (self ):
269
+ def init_kernel_type (self ):
246
270
self .use_cudnn = True
247
- self .op_type = "conv3d"
271
+
272
+
273
+ class TestFP16WithGroup1CUDNN (TestWithGroup1 ):
274
+ def init_kernel_type (self ):
275
+ self .use_cudnn = True
276
+ self .dtype = np .float16
277
+
278
+ def test_check_output (self ):
279
+ if core .is_compiled_with_cuda ():
280
+ place = core .CUDAPlace (0 )
281
+ if core .is_float16_supported (place ):
282
+ self .check_output_with_place (place , atol = 2e-2 )
248
283
249
284
250
285
class TestWithGroup2CUDNN (TestWithGroup2 ):
251
- def init_op_type (self ):
286
+ def init_kernel_type (self ):
252
287
self .use_cudnn = True
253
- self .op_type = "conv3d"
288
+
289
+
290
+ class TestFP16WithGroup2CUDNN (TestWithGroup2 ):
291
+ def init_kernel_type (self ):
292
+ self .use_cudnn = True
293
+ self .dtype = np .float16
294
+
295
+ def test_check_output (self ):
296
+ if core .is_compiled_with_cuda ():
297
+ place = core .CUDAPlace (0 )
298
+ if core .is_float16_supported (place ):
299
+ self .check_output_with_place (place , atol = 2e-2 )
254
300
255
301
256
302
class TestWith1x1CUDNN (TestWith1x1 ):
257
- def init_op_type (self ):
303
+ def init_kernel_type (self ):
258
304
self .use_cudnn = True
259
- self .op_type = "conv3d"
305
+
306
+
307
+ class TestFP16With1x1CUDNN (TestWith1x1 ):
308
+ def init_kernel_type (self ):
309
+ self .use_cudnn = True
310
+ self .dtype = np .float16
311
+
312
+ def test_check_output (self ):
313
+ if core .is_compiled_with_cuda ():
314
+ place = core .CUDAPlace (0 )
315
+ if core .is_float16_supported (place ):
316
+ self .check_output_with_place (place , atol = 2e-2 )
260
317
261
318
262
319
class TestWithInput1x1Filter1x1CUDNN (TestWithInput1x1Filter1x1 ):
263
- def init_op_type (self ):
320
+ def init_kernel_type (self ):
264
321
self .use_cudnn = True
265
- self .op_type = "conv3d"
322
+
323
+
324
+ class TestFP16WithInput1x1Filter1x1CUDNN (TestWithInput1x1Filter1x1 ):
325
+ def init_kernel_type (self ):
326
+ self .use_cudnn = True
327
+ self .dtype = np .float16
328
+
329
+ def test_check_output (self ):
330
+ if core .is_compiled_with_cuda ():
331
+ place = core .CUDAPlace (0 )
332
+ if core .is_float16_supported (place ):
333
+ self .check_output_with_place (place , atol = 2e-2 )
266
334
267
335
268
336
# FIXME(typhoonzero): find a way to determine if
0 commit comments