Skip to content

Commit 7b9aa60

Browse files
committed
MKLDNN gausian_random tests
1 parent 7011022 commit 7b9aa60

File tree

3 files changed

+39
-20
lines changed

3 files changed

+39
-20
lines changed

paddle/fluid/operators/gaussian_random_mkldnn_op.cc

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,9 @@ limitations under the License. */
1515
#include <string>
1616
#include "paddle/fluid/operators/mean_op.h"
1717

18-
#include "mkldnn.hpp"
19-
#include "paddle/fluid/framework/tensor.h"
20-
#include "paddle/fluid/operators/math/selected_rows_functor.h"
21-
#include "paddle/fluid/platform/device_context.h"
22-
#include "paddle/fluid/platform/mkldnn_helper.h"
23-
24-
#include "paddle/fluid/framework/eigen.h"
2518
namespace paddle {
2619
namespace operators {
2720

28-
using paddle::framework::Tensor;
29-
using paddle::platform::MKLDNNDeviceContext;
30-
using paddle::platform::MKLDNNMemDesc;
31-
using paddle::platform::CPUDeviceContext;
32-
33-
using mkldnn::memory; // Note: paddle has also "memory" namespace
34-
using mkldnn::primitive;
35-
using mkldnn::softmax_forward;
36-
using mkldnn::prop_kind;
37-
using mkldnn::stream;
38-
3921
using framework::DataLayout;
4022
template <typename T>
4123
class GaussianMKLDNNKernel : public paddle::framework::OpKernel<T> {
@@ -61,7 +43,7 @@ class GaussianMKLDNNKernel : public paddle::framework::OpKernel<T> {
6143
// The format of output is set as the mkldnn's format
6244
// TODO(@mozga-intel) The format of matrix sets inside the another layers.
6345
tensor->set_layout(DataLayout::kMKLDNN);
64-
tensor->set_format(mkldnn::memory::format::Ohwi16o);
46+
tensor->set_format(mkldnn::memory::format::oihw);
6547
}
6648
};
6749
} // namespace operators
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_gaussian_random_op import TestGaussianRandomOp
18+
19+
20+
class TestMKLDNN(TestGaussianRandomOp):
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_gaussian_random_op.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,15 @@ class TestGaussianRandomOp(unittest.TestCase):
2525
def setUp(self):
2626
self.op_type = "gaussian_random"
2727
self.inputs = {}
28-
self.attrs = {"shape": [1000, 784], "mean": .0, "std": 1., "seed": 10}
28+
self.use_mkldnn = False
29+
self.init_kernel_type()
30+
self.attrs = {
31+
"shape": [1000, 784],
32+
"mean": .0,
33+
"std": 1.,
34+
"seed": 10,
35+
"use_mkldnn": self.use_mkldnn
36+
}
2937

3038
self.outputs = ["Out"]
3139

@@ -58,6 +66,9 @@ def gaussian_random_test(self, place):
5866
self.assertAlmostEqual(numpy.mean(tensor), .0, delta=0.1)
5967
self.assertAlmostEqual(numpy.std(tensor), 1., delta=0.1)
6068

69+
def init_kernel_type(self):
70+
pass
71+
6172

6273
if __name__ == "__main__":
6374
unittest.main()

0 commit comments

Comments
 (0)