Skip to content

Commit fee5b24

Browse files
authored
Merge pull request #9985 from mozga-intel/mozga-intel/mkldnn_separate_tests
The mkldnn tests are skipped when the MKLDNN flag is OFF
2 parents 038dbb3 + 5e13314 commit fee5b24

10 files changed

+240
-157
lines changed

python/paddle/fluid/tests/unittests/CMakeLists.txt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
file(GLOB TEST_OPS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "test_*.py")
22
string(REPLACE ".py" "" TEST_OPS "${TEST_OPS}")
33

4-
# The fully connected test is removed whe the WITH_MKLDNN flag is OFF
5-
# Because the fully connected layer has only one kernel (MKLDNN)
4+
# The MKLDNN tests are skiped when the MKLDNN flag is OFF
65
if(NOT WITH_MKLDNN)
7-
list(REMOVE_ITEM TEST_OPS test_fc_op)
6+
foreach(src ${TEST_OPS})
7+
if(${src} MATCHES ".*_mkldnn_op$")
8+
list(REMOVE_ITEM TEST_OPS ${src})
9+
endif()
10+
endforeach()
811
endif(NOT WITH_MKLDNN)
912

1013
if(NOT WITH_DISTRIBUTE)
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import unittest
16+
import numpy as np
17+
import paddle.fluid.core as core
18+
from op_test import OpTest
19+
from scipy.special import expit
20+
from test_activation_op import TestRelu, TestTanh, TestSqrt, TestAbs
21+
22+
23+
class TestMKLDNNReluDim2(TestRelu):
24+
def setUp(self):
25+
super(TestMKLDNNReluDim2, self).setUp()
26+
27+
self.attrs = {"use_mkldnn": True}
28+
29+
30+
class TestMKLDNNTanhDim2(TestTanh):
31+
def setUp(self):
32+
super(TestMKLDNNTanhDim2, self).setUp()
33+
34+
self.attrs = {"use_mkldnn": True}
35+
36+
37+
class TestMKLDNNSqrtDim2(TestSqrt):
38+
def setUp(self):
39+
super(TestMKLDNNSqrtDim2, self).setUp()
40+
41+
self.attrs = {"use_mkldnn": True}
42+
43+
44+
class TestMKLDNNAbsDim2(TestAbs):
45+
def setUp(self):
46+
super(TestMKLDNNAbsDim2, self).setUp()
47+
self.attrs = {"use_mkldnn": True}
48+
49+
50+
class TestMKLDNNReluDim4(TestRelu):
51+
def setUp(self):
52+
super(TestMKLDNNReluDim4, self).setUp()
53+
54+
x = np.random.uniform(-1, 1, [2, 4, 3, 5]).astype("float32")
55+
# The same reason with TestAbs
56+
x[np.abs(x) < 0.005] = 0.02
57+
out = np.maximum(x, 0)
58+
59+
self.inputs = {'X': OpTest.np_dtype_to_fluid_dtype(x)}
60+
self.outputs = {'Out': out}
61+
self.attrs = {"use_mkldnn": True}
62+
63+
64+
class TestMKLDNNTanhDim4(TestTanh):
65+
def setUp(self):
66+
super(TestMKLDNNTanhDim4, self).setUp()
67+
68+
self.inputs = {
69+
'X': np.random.uniform(0.1, 1, [2, 4, 3, 5]).astype("float32")
70+
}
71+
self.outputs = {'Out': np.tanh(self.inputs['X'])}
72+
self.attrs = {"use_mkldnn": True}
73+
74+
75+
class TestMKLDNNSqrtDim4(TestSqrt):
76+
def setUp(self):
77+
super(TestMKLDNNSqrtDim4, self).setUp()
78+
79+
self.inputs = {
80+
'X': np.random.uniform(0.1, 1, [2, 4, 3, 5]).astype("float32")
81+
}
82+
self.outputs = {'Out': np.sqrt(self.inputs['X'])}
83+
self.attrs = {"use_mkldnn": True}
84+
85+
86+
class TestMKLDNNAbsDim4(TestAbs):
87+
def setUp(self):
88+
super(TestMKLDNNAbsDim4, self).setUp()
89+
90+
x = np.random.uniform(-1, 1, [2, 4, 3, 5]).astype("float32")
91+
# The same reason with TestAbs
92+
x[np.abs(x) < 0.005] = 0.02
93+
self.inputs = {'X': x}
94+
self.outputs = {'Out': np.abs(self.inputs['X'])}
95+
self.attrs = {"use_mkldnn": True}
96+
97+
98+
if __name__ == '__main__':
99+
unittest.main()

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

Lines changed: 0 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,82 +1098,5 @@ def test_check_output(self):
10981098
self.check_output_with_place(place, atol=1e-3)
10991099

11001100

1101-
#--------------------test MKLDNN--------------------
1102-
class TestMKLDNNReluDim2(TestRelu):
1103-
def setUp(self):
1104-
super(TestMKLDNNReluDim2, self).setUp()
1105-
1106-
self.attrs = {"use_mkldnn": True}
1107-
1108-
1109-
class TestMKLDNNTanhDim2(TestTanh):
1110-
def setUp(self):
1111-
super(TestMKLDNNTanhDim2, self).setUp()
1112-
1113-
self.attrs = {"use_mkldnn": True}
1114-
1115-
1116-
class TestMKLDNNSqrtDim2(TestSqrt):
1117-
def setUp(self):
1118-
super(TestMKLDNNSqrtDim2, self).setUp()
1119-
1120-
self.attrs = {"use_mkldnn": True}
1121-
1122-
1123-
class TestMKLDNNAbsDim2(TestAbs):
1124-
def setUp(self):
1125-
super(TestMKLDNNAbsDim2, self).setUp()
1126-
1127-
self.attrs = {"use_mkldnn": True}
1128-
1129-
1130-
class TestMKLDNNReluDim4(TestRelu):
1131-
def setUp(self):
1132-
super(TestMKLDNNReluDim4, self).setUp()
1133-
1134-
x = np.random.uniform(-1, 1, [2, 4, 3, 5]).astype("float32")
1135-
# The same reason with TestAbs
1136-
x[np.abs(x) < 0.005] = 0.02
1137-
out = np.maximum(x, 0)
1138-
1139-
self.inputs = {'X': OpTest.np_dtype_to_fluid_dtype(x)}
1140-
self.outputs = {'Out': out}
1141-
self.attrs = {"use_mkldnn": True}
1142-
1143-
1144-
class TestMKLDNNTanhDim4(TestTanh):
1145-
def setUp(self):
1146-
super(TestMKLDNNTanhDim4, self).setUp()
1147-
1148-
self.inputs = {
1149-
'X': np.random.uniform(0.1, 1, [2, 4, 3, 5]).astype("float32")
1150-
}
1151-
self.outputs = {'Out': np.tanh(self.inputs['X'])}
1152-
self.attrs = {"use_mkldnn": True}
1153-
1154-
1155-
class TestMKLDNNSqrtDim4(TestSqrt):
1156-
def setUp(self):
1157-
super(TestMKLDNNSqrtDim4, self).setUp()
1158-
1159-
self.inputs = {
1160-
'X': np.random.uniform(0.1, 1, [2, 4, 3, 5]).astype("float32")
1161-
}
1162-
self.outputs = {'Out': np.sqrt(self.inputs['X'])}
1163-
self.attrs = {"use_mkldnn": True}
1164-
1165-
1166-
class TestMKLDNNAbsDim4(TestAbs):
1167-
def setUp(self):
1168-
super(TestMKLDNNAbsDim4, self).setUp()
1169-
1170-
x = np.random.uniform(-1, 1, [2, 4, 3, 5]).astype("float32")
1171-
# The same reason with TestAbs
1172-
x[np.abs(x) < 0.005] = 0.02
1173-
self.inputs = {'X': x}
1174-
self.outputs = {'Out': np.abs(self.inputs['X'])}
1175-
self.attrs = {"use_mkldnn": True}
1176-
1177-
11781101
if __name__ == "__main__":
11791102
unittest.main()
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import unittest
16+
17+
from test_conv2d_op import TestConv2dOp, TestWithPad, TestWithStride
18+
19+
20+
class TestMKLDNN(TestConv2dOp):
21+
def init_kernel_type(self):
22+
self.use_mkldnn = True
23+
24+
25+
class TestMKLDNNWithPad(TestWithPad):
26+
def init_kernel_type(self):
27+
self.use_mkldnn = True
28+
29+
30+
class TestMKLDNNWithStride(TestWithStride):
31+
def init_kernel_type(self):
32+
self.use_mkldnn = True
33+
34+
35+
if __name__ == '__main__':
36+
unittest.main()

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

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -373,22 +373,5 @@ def init_test_case(self):
373373
# def init_op_type(self):
374374
# self.op_type = "conv_cudnn"
375375

376-
377-
#----------------Conv2dMKLDNN----------------
378-
class TestMKLDNN(TestConv2dOp):
379-
def init_kernel_type(self):
380-
self.use_mkldnn = True
381-
382-
383-
class TestMKLDNNWithPad(TestWithPad):
384-
def init_kernel_type(self):
385-
self.use_mkldnn = True
386-
387-
388-
class TestMKLDNNWithStride(TestWithStride):
389-
def init_kernel_type(self):
390-
self.use_mkldnn = True
391-
392-
393376
if __name__ == '__main__':
394377
unittest.main()
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import unittest
16+
from test_lrn_op import TestLRNOp
17+
18+
19+
class TestLRNMKLDNNOp(TestLRNOp):
20+
def get_attrs(self):
21+
attrs = TestLRNOp.get_attrs(self)
22+
attrs['use_mkldnn'] = True
23+
return attrs
24+
25+
def test_check_output(self):
26+
self.check_output(atol=0.002)
27+
28+
29+
class TestLRNMKLDNNOpWithIsTest(TestLRNMKLDNNOp):
30+
def get_attrs(self):
31+
attrs = TestLRNMKLDNNOp.get_attrs(self)
32+
attrs['is_test'] = True
33+
return attrs
34+
35+
def test_check_grad_normal(self):
36+
def check_raise_is_test():
37+
try:
38+
self.check_grad(['X'], 'Out', max_relative_error=0.01)
39+
except Exception as e:
40+
t = \
41+
"is_test attribute should be set to False in training phase."
42+
if t in str(e):
43+
raise AttributeError
44+
45+
self.assertRaises(AttributeError, check_raise_is_test)
46+
47+
48+
if __name__ == "__main__":
49+
unittest.main()

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

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -87,34 +87,5 @@ def test_check_grad_normal(self):
8787
self.check_grad(['X'], 'Out', max_relative_error=0.01)
8888

8989

90-
class TestLRNMKLDNNOp(TestLRNOp):
91-
def get_attrs(self):
92-
attrs = TestLRNOp.get_attrs(self)
93-
attrs['use_mkldnn'] = True
94-
return attrs
95-
96-
def test_check_output(self):
97-
self.check_output(atol=0.002)
98-
99-
100-
class TestLRNMKLDNNOpWithIsTest(TestLRNMKLDNNOp):
101-
def get_attrs(self):
102-
attrs = TestLRNMKLDNNOp.get_attrs(self)
103-
attrs['is_test'] = True
104-
return attrs
105-
106-
def test_check_grad_normal(self):
107-
def check_raise_is_test():
108-
try:
109-
self.check_grad(['X'], 'Out', max_relative_error=0.01)
110-
except Exception as e:
111-
t = \
112-
"is_test attribute should be set to False in training phase."
113-
if t in str(e):
114-
raise AttributeError
115-
116-
self.assertRaises(AttributeError, check_raise_is_test)
117-
118-
11990
if __name__ == "__main__":
12091
unittest.main()
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import unittest
16+
from test_pool2d_op import TestPool2d_Op, TestCase1, TestCase2, TestCase3, TestCase4, TestCase5
17+
18+
19+
class TestMKLDNNCase1(TestPool2d_Op):
20+
def init_kernel_type(self):
21+
self.use_mkldnn = True
22+
23+
24+
class TestMKLDNNCase2(TestCase1):
25+
def init_kernel_type(self):
26+
self.use_mkldnn = True
27+
28+
29+
class TestMKLDNNCase3(TestCase2):
30+
def init_kernel_type(self):
31+
self.use_mkldnn = True
32+
33+
34+
class TestMKLDNNCase4(TestCase3):
35+
def init_kernel_type(self):
36+
self.use_mkldnn = True
37+
38+
39+
class TestMKLDNNCase5(TestCase4):
40+
def init_kernel_type(self):
41+
self.use_mkldnn = True
42+
43+
44+
class TestMKLDNNCase6(TestCase5):
45+
def init_kernel_type(self):
46+
self.use_mkldnn = True
47+
48+
49+
if __name__ == '__main__':
50+
unittest.main()

0 commit comments

Comments
 (0)