Skip to content

Commit b88cda8

Browse files
committed
MKLDNN sum unit-test
1 parent 6512be5 commit b88cda8

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

paddle/fluid/operators/sum_mkldnn_op.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ class SumMKLDNNOpKernel : public paddle::framework::OpKernel<T> {
5353
"It must use CPUPlace.");
5454
auto& dev_ctx = ctx.template device_context<MKLDNNDeviceContext>();
5555
const auto& mkldnn_engine = dev_ctx.GetEngine();
56-
5756
auto in_vars = ctx.MultiInputVar("X");
5857

5958
const int N = in_vars.size();
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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_sum_op import TestSumOp
18+
19+
20+
class TestMKLDNN(TestSumOp):
21+
def init_kernel_type(self):
22+
self.use_mkldnn = True
23+
24+
25+
if __name__ == '__main__':
26+
unittest.main()

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,25 @@
2020
class TestSumOp(OpTest):
2121
def setUp(self):
2222
self.op_type = "sum"
23+
self.use_mkldnn = False
24+
self.init_kernel_type()
2325
x0 = np.random.random((3, 4)).astype('float32')
2426
x1 = np.random.random((3, 4)).astype('float32')
2527
x2 = np.random.random((3, 4)).astype('float32')
2628
self.inputs = {"X": [("x0", x0), ("x1", x1), ("x2", x2)]}
2729
y = x0 + x1 + x2
2830
self.outputs = {'Out': y}
31+
self.attrs = {'use_mkldnn': self.use_mkldnn}
2932

3033
def test_check_output(self):
3134
self.check_output()
3235

3336
def test_check_grad(self):
3437
self.check_grad(['x0'], 'Out')
3538

39+
def init_kernel_type(self):
40+
pass
41+
3642

3743
if __name__ == "__main__":
3844
unittest.main()

0 commit comments

Comments
 (0)