You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by an...@apache.org on 2018/06/13 21:32:32 UTC
[incubator-mxnet] 02/12: [MXNET-33] SSD example not working with
mkl-dnn (#10021)
This is an automated email from the ASF dual-hosted git repository.
anirudh2290 pushed a commit to branch v1.2.0
in repository https://gitbox.apache.org/repos/asf/incubator-mxnet.git
commit db24cc0bed085187bcdbecb144807d756898f51a
Author: Ashok Emani <as...@intel.com>
AuthorDate: Tue Apr 24 10:48:01 2018 -0700
[MXNET-33] SSD example not working with mkl-dnn (#10021)
* use mkl-dnn for 'valid' pooling_convention only
* pooling convention full not supported by current mkl-dnn impl
* disable unreachable code
* add sample model test for mkldnn
* fix review feedback
* add jira link to comment
* fix lint issue
* rename python test for mkl
* enable python tests for mkldnn in CI
* use vgg16 with convention full
* fix unittest
---
Jenkinsfile | 8 +-
ci/docker/runtime_functions.sh | 12 +
src/operator/nn/mkldnn/mkldnn_pooling-inl.h | 6 +
.../data/test_mkldnn_test_mkldnn_model_model1.json | 770 +++++++++++++++++++++
tests/python/mkl/test_mkldnn.py | 94 +++
5 files changed, 889 insertions(+), 1 deletion(-)
diff --git a/Jenkinsfile b/Jenkinsfile
index 8686012..7167f14 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -107,6 +107,12 @@ def python3_ut(docker_container_name) {
}
}
+def python3_ut_mkldnn(docker_container_name) {
+ timeout(time: max_time, unit: 'MINUTES') {
+ sh "ci/build.py --build --platform ${docker_container_name} /work/runtime_functions.sh unittest_ubuntu_python3_cpu_mkldnn"
+ }
+}
+
// GPU test has two parts. 1) run unittest on GPU, 2) compare the results on
// both CPU and GPU
// Python 2
@@ -438,7 +444,7 @@ try {
ws('workspace/ut-python3-mkldnn-cpu') {
init_git()
unpack_lib('mkldnn_cpu', mx_mkldnn_lib)
- python3_ut('ubuntu_cpu')
+ python3_ut_mkldnn('ubuntu_cpu')
}
}
},
diff --git a/ci/docker/runtime_functions.sh b/ci/docker/runtime_functions.sh
index 77ffad1..4d0f846 100755
--- a/ci/docker/runtime_functions.sh
+++ b/ci/docker/runtime_functions.sh
@@ -375,6 +375,18 @@ unittest_ubuntu_python3_cpu() {
nosetests-3.4 --verbose tests/python/quantization
}
+unittest_ubuntu_python3_cpu_mkldnn() {
+ set -ex
+ export PYTHONPATH=./python/
+ # MXNET_MKLDNN_DEBUG is buggy and produces false positives
+ # https://github.com/apache/incubator-mxnet/issues/10026
+ #export MXNET_MKLDNN_DEBUG=1 # Ignored if not present
+ export MXNET_STORAGE_FALLBACK_LOG_VERBOSE=0
+ nosetests-3.4 --verbose tests/python/unittest
+ nosetests-3.4 --verbose tests/python/quantization
+ nosetests-3.4 --verbose tests/python/mkl
+}
+
unittest_ubuntu_python2_gpu() {
set -ex
export PYTHONPATH=./python/
diff --git a/src/operator/nn/mkldnn/mkldnn_pooling-inl.h b/src/operator/nn/mkldnn/mkldnn_pooling-inl.h
index 2097d57..4b6235e 100644
--- a/src/operator/nn/mkldnn/mkldnn_pooling-inl.h
+++ b/src/operator/nn/mkldnn/mkldnn_pooling-inl.h
@@ -92,12 +92,18 @@ inline bool SupportMKLDNNPooling(const PoolingParam ¶m,
if (param.pooling_convention == pool_enum::kValid)
return true;
+ else
+ return false;
+// need to support pooling convention full
+// https://issues.apache.org/jira/browse/MXNET-33
+#if 0
if (((dshape[2] + 2 * param.pad[0] - param.kernel[0]) % param.stride[0] == 0) &&
((dshape[3] + 2 * param.pad[1] - param.kernel[1]) % param.stride[1] == 0))
return true;
else
return false;
+#endif
}
inline bool MKLDNNRequireWorkspace(const PoolingParam ¶m) {
diff --git a/tests/python/mkl/data/test_mkldnn_test_mkldnn_model_model1.json b/tests/python/mkl/data/test_mkldnn_test_mkldnn_model_model1.json
new file mode 100644
index 0000000..ba822f5
--- /dev/null
+++ b/tests/python/mkl/data/test_mkldnn_test_mkldnn_model_model1.json
@@ -0,0 +1,770 @@
+{
+ "nodes": [
+ {
+ "op": "null",
+ "name": "data",
+ "inputs": []
+ },
+ {
+ "op": "null",
+ "name": "conv1_1_weight",
+ "attrs": {
+ "kernel": "(3, 3)",
+ "num_filter": "64",
+ "pad": "(1, 1)"
+ },
+ "inputs": []
+ },
+ {
+ "op": "null",
+ "name": "conv1_1_bias",
+ "attrs": {
+ "kernel": "(3, 3)",
+ "num_filter": "64",
+ "pad": "(1, 1)"
+ },
+ "inputs": []
+ },
+ {
+ "op": "Convolution",
+ "name": "conv1_1",
+ "attrs": {
+ "kernel": "(3, 3)",
+ "num_filter": "64",
+ "pad": "(1, 1)"
+ },
+ "inputs": [[0, 0, 0], [1, 0, 0], [2, 0, 0]]
+ },
+ {
+ "op": "Activation",
+ "name": "relu1_1",
+ "attrs": {"act_type": "relu"},
+ "inputs": [[3, 0, 0]]
+ },
+ {
+ "op": "null",
+ "name": "conv1_2_weight",
+ "attrs": {
+ "kernel": "(3, 3)",
+ "num_filter": "64",
+ "pad": "(1, 1)"
+ },
+ "inputs": []
+ },
+ {
+ "op": "null",
+ "name": "conv1_2_bias",
+ "attrs": {
+ "kernel": "(3, 3)",
+ "num_filter": "64",
+ "pad": "(1, 1)"
+ },
+ "inputs": []
+ },
+ {
+ "op": "Convolution",
+ "name": "conv1_2",
+ "attrs": {
+ "kernel": "(3, 3)",
+ "num_filter": "64",
+ "pad": "(1, 1)"
+ },
+ "inputs": [[4, 0, 0], [5, 0, 0], [6, 0, 0]]
+ },
+ {
+ "op": "Activation",
+ "name": "relu1_2",
+ "attrs": {"act_type": "relu"},
+ "inputs": [[7, 0, 0]]
+ },
+ {
+ "op": "Pooling",
+ "name": "pool1",
+ "attrs": {
+ "kernel": "(2, 2)",
+ "pool_type": "max",
+ "stride": "(2, 2)"
+ },
+ "inputs": [[8, 0, 0]]
+ },
+ {
+ "op": "null",
+ "name": "conv2_1_weight",
+ "attrs": {
+ "kernel": "(3, 3)",
+ "num_filter": "128",
+ "pad": "(1, 1)"
+ },
+ "inputs": []
+ },
+ {
+ "op": "null",
+ "name": "conv2_1_bias",
+ "attrs": {
+ "kernel": "(3, 3)",
+ "num_filter": "128",
+ "pad": "(1, 1)"
+ },
+ "inputs": []
+ },
+ {
+ "op": "Convolution",
+ "name": "conv2_1",
+ "attrs": {
+ "kernel": "(3, 3)",
+ "num_filter": "128",
+ "pad": "(1, 1)"
+ },
+ "inputs": [[9, 0, 0], [10, 0, 0], [11, 0, 0]]
+ },
+ {
+ "op": "Activation",
+ "name": "relu2_1",
+ "attrs": {"act_type": "relu"},
+ "inputs": [[12, 0, 0]]
+ },
+ {
+ "op": "null",
+ "name": "conv2_2_weight",
+ "attrs": {
+ "kernel": "(3, 3)",
+ "num_filter": "128",
+ "pad": "(1, 1)"
+ },
+ "inputs": []
+ },
+ {
+ "op": "null",
+ "name": "conv2_2_bias",
+ "attrs": {
+ "kernel": "(3, 3)",
+ "num_filter": "128",
+ "pad": "(1, 1)"
+ },
+ "inputs": []
+ },
+ {
+ "op": "Convolution",
+ "name": "conv2_2",
+ "attrs": {
+ "kernel": "(3, 3)",
+ "num_filter": "128",
+ "pad": "(1, 1)"
+ },
+ "inputs": [[13, 0, 0], [14, 0, 0], [15, 0, 0]]
+ },
+ {
+ "op": "Activation",
+ "name": "relu2_2",
+ "attrs": {"act_type": "relu"},
+ "inputs": [[16, 0, 0]]
+ },
+ {
+ "op": "Pooling",
+ "name": "pool2",
+ "attrs": {
+ "kernel": "(2, 2)",
+ "pool_type": "max",
+ "stride": "(2, 2)"
+ },
+ "inputs": [[17, 0, 0]]
+ },
+ {
+ "op": "null",
+ "name": "conv3_1_weight",
+ "attrs": {
+ "kernel": "(3, 3)",
+ "num_filter": "256",
+ "pad": "(1, 1)"
+ },
+ "inputs": []
+ },
+ {
+ "op": "null",
+ "name": "conv3_1_bias",
+ "attrs": {
+ "kernel": "(3, 3)",
+ "num_filter": "256",
+ "pad": "(1, 1)"
+ },
+ "inputs": []
+ },
+ {
+ "op": "Convolution",
+ "name": "conv3_1",
+ "attrs": {
+ "kernel": "(3, 3)",
+ "num_filter": "256",
+ "pad": "(1, 1)"
+ },
+ "inputs": [[18, 0, 0], [19, 0, 0], [20, 0, 0]]
+ },
+ {
+ "op": "Activation",
+ "name": "relu3_1",
+ "attrs": {"act_type": "relu"},
+ "inputs": [[21, 0, 0]]
+ },
+ {
+ "op": "null",
+ "name": "conv3_2_weight",
+ "attrs": {
+ "kernel": "(3, 3)",
+ "num_filter": "256",
+ "pad": "(1, 1)"
+ },
+ "inputs": []
+ },
+ {
+ "op": "null",
+ "name": "conv3_2_bias",
+ "attrs": {
+ "kernel": "(3, 3)",
+ "num_filter": "256",
+ "pad": "(1, 1)"
+ },
+ "inputs": []
+ },
+ {
+ "op": "Convolution",
+ "name": "conv3_2",
+ "attrs": {
+ "kernel": "(3, 3)",
+ "num_filter": "256",
+ "pad": "(1, 1)"
+ },
+ "inputs": [[22, 0, 0], [23, 0, 0], [24, 0, 0]]
+ },
+ {
+ "op": "Activation",
+ "name": "relu3_2",
+ "attrs": {"act_type": "relu"},
+ "inputs": [[25, 0, 0]]
+ },
+ {
+ "op": "null",
+ "name": "conv3_3_weight",
+ "attrs": {
+ "kernel": "(3, 3)",
+ "num_filter": "256",
+ "pad": "(1, 1)"
+ },
+ "inputs": []
+ },
+ {
+ "op": "null",
+ "name": "conv3_3_bias",
+ "attrs": {
+ "kernel": "(3, 3)",
+ "num_filter": "256",
+ "pad": "(1, 1)"
+ },
+ "inputs": []
+ },
+ {
+ "op": "Convolution",
+ "name": "conv3_3",
+ "attrs": {
+ "kernel": "(3, 3)",
+ "num_filter": "256",
+ "pad": "(1, 1)"
+ },
+ "inputs": [[26, 0, 0], [27, 0, 0], [28, 0, 0]]
+ },
+ {
+ "op": "Activation",
+ "name": "relu3_3",
+ "attrs": {"act_type": "relu"},
+ "inputs": [[29, 0, 0]]
+ },
+ {
+ "op": "Pooling",
+ "name": "pool3",
+ "attrs": {
+ "kernel": "(2, 2)",
+ "pool_type": "max",
+ "pooling_convention": "full",
+ "stride": "(2, 2)"
+ },
+ "inputs": [[30, 0, 0]]
+ },
+ {
+ "op": "null",
+ "name": "conv4_1_weight",
+ "attrs": {
+ "kernel": "(3, 3)",
+ "num_filter": "512",
+ "pad": "(1, 1)"
+ },
+ "inputs": []
+ },
+ {
+ "op": "null",
+ "name": "conv4_1_bias",
+ "attrs": {
+ "kernel": "(3, 3)",
+ "num_filter": "512",
+ "pad": "(1, 1)"
+ },
+ "inputs": []
+ },
+ {
+ "op": "Convolution",
+ "name": "conv4_1",
+ "attrs": {
+ "kernel": "(3, 3)",
+ "num_filter": "512",
+ "pad": "(1, 1)"
+ },
+ "inputs": [[31, 0, 0], [32, 0, 0], [33, 0, 0]]
+ },
+ {
+ "op": "Activation",
+ "name": "relu4_1",
+ "attrs": {"act_type": "relu"},
+ "inputs": [[34, 0, 0]]
+ },
+ {
+ "op": "null",
+ "name": "conv4_2_weight",
+ "attrs": {
+ "kernel": "(3, 3)",
+ "num_filter": "512",
+ "pad": "(1, 1)"
+ },
+ "inputs": []
+ },
+ {
+ "op": "null",
+ "name": "conv4_2_bias",
+ "attrs": {
+ "kernel": "(3, 3)",
+ "num_filter": "512",
+ "pad": "(1, 1)"
+ },
+ "inputs": []
+ },
+ {
+ "op": "Convolution",
+ "name": "conv4_2",
+ "attrs": {
+ "kernel": "(3, 3)",
+ "num_filter": "512",
+ "pad": "(1, 1)"
+ },
+ "inputs": [[35, 0, 0], [36, 0, 0], [37, 0, 0]]
+ },
+ {
+ "op": "Activation",
+ "name": "relu4_2",
+ "attrs": {"act_type": "relu"},
+ "inputs": [[38, 0, 0]]
+ },
+ {
+ "op": "null",
+ "name": "conv4_3_weight",
+ "attrs": {
+ "kernel": "(3, 3)",
+ "num_filter": "512",
+ "pad": "(1, 1)"
+ },
+ "inputs": []
+ },
+ {
+ "op": "null",
+ "name": "conv4_3_bias",
+ "attrs": {
+ "kernel": "(3, 3)",
+ "num_filter": "512",
+ "pad": "(1, 1)"
+ },
+ "inputs": []
+ },
+ {
+ "op": "Convolution",
+ "name": "conv4_3",
+ "attrs": {
+ "kernel": "(3, 3)",
+ "num_filter": "512",
+ "pad": "(1, 1)"
+ },
+ "inputs": [[39, 0, 0], [40, 0, 0], [41, 0, 0]]
+ },
+ {
+ "op": "Activation",
+ "name": "relu4_3",
+ "attrs": {"act_type": "relu"},
+ "inputs": [[42, 0, 0]]
+ },
+ {
+ "op": "Pooling",
+ "name": "pool4",
+ "attrs": {
+ "kernel": "(2, 2)",
+ "pool_type": "max",
+ "stride": "(2, 2)"
+ },
+ "inputs": [[43, 0, 0]]
+ },
+ {
+ "op": "null",
+ "name": "conv5_1_weight",
+ "attrs": {
+ "kernel": "(3, 3)",
+ "num_filter": "512",
+ "pad": "(1, 1)"
+ },
+ "inputs": []
+ },
+ {
+ "op": "null",
+ "name": "conv5_1_bias",
+ "attrs": {
+ "kernel": "(3, 3)",
+ "num_filter": "512",
+ "pad": "(1, 1)"
+ },
+ "inputs": []
+ },
+ {
+ "op": "Convolution",
+ "name": "conv5_1",
+ "attrs": {
+ "kernel": "(3, 3)",
+ "num_filter": "512",
+ "pad": "(1, 1)"
+ },
+ "inputs": [[44, 0, 0], [45, 0, 0], [46, 0, 0]]
+ },
+ {
+ "op": "Activation",
+ "name": "relu5_1",
+ "attrs": {"act_type": "relu"},
+ "inputs": [[47, 0, 0]]
+ },
+ {
+ "op": "null",
+ "name": "conv5_2_weight",
+ "attrs": {
+ "kernel": "(3, 3)",
+ "num_filter": "512",
+ "pad": "(1, 1)"
+ },
+ "inputs": []
+ },
+ {
+ "op": "null",
+ "name": "conv5_2_bias",
+ "attrs": {
+ "kernel": "(3, 3)",
+ "num_filter": "512",
+ "pad": "(1, 1)"
+ },
+ "inputs": []
+ },
+ {
+ "op": "Convolution",
+ "name": "conv5_2",
+ "attrs": {
+ "kernel": "(3, 3)",
+ "num_filter": "512",
+ "pad": "(1, 1)"
+ },
+ "inputs": [[48, 0, 0], [49, 0, 0], [50, 0, 0]]
+ },
+ {
+ "op": "Activation",
+ "name": "relu5_2",
+ "attrs": {"act_type": "relu"},
+ "inputs": [[51, 0, 0]]
+ },
+ {
+ "op": "null",
+ "name": "conv5_3_weight",
+ "attrs": {
+ "kernel": "(3, 3)",
+ "num_filter": "512",
+ "pad": "(1, 1)"
+ },
+ "inputs": []
+ },
+ {
+ "op": "null",
+ "name": "conv5_3_bias",
+ "attrs": {
+ "kernel": "(3, 3)",
+ "num_filter": "512",
+ "pad": "(1, 1)"
+ },
+ "inputs": []
+ },
+ {
+ "op": "Convolution",
+ "name": "conv5_3",
+ "attrs": {
+ "kernel": "(3, 3)",
+ "num_filter": "512",
+ "pad": "(1, 1)"
+ },
+ "inputs": [[52, 0, 0], [53, 0, 0], [54, 0, 0]]
+ },
+ {
+ "op": "Activation",
+ "name": "relu5_3",
+ "attrs": {"act_type": "relu"},
+ "inputs": [[55, 0, 0]]
+ },
+ {
+ "op": "Pooling",
+ "name": "pool5",
+ "attrs": {
+ "kernel": "(3, 3)",
+ "pad": "(1, 1)",
+ "pool_type": "max",
+ "stride": "(1, 1)"
+ },
+ "inputs": [[56, 0, 0]]
+ },
+ {
+ "op": "null",
+ "name": "fc6_weight",
+ "attrs": {
+ "dilate": "(6, 6)",
+ "kernel": "(3, 3)",
+ "num_filter": "1024",
+ "pad": "(6, 6)"
+ },
+ "inputs": []
+ },
+ {
+ "op": "null",
+ "name": "fc6_bias",
+ "attrs": {
+ "dilate": "(6, 6)",
+ "kernel": "(3, 3)",
+ "num_filter": "1024",
+ "pad": "(6, 6)"
+ },
+ "inputs": []
+ },
+ {
+ "op": "Convolution",
+ "name": "fc6",
+ "attrs": {
+ "dilate": "(6, 6)",
+ "kernel": "(3, 3)",
+ "num_filter": "1024",
+ "pad": "(6, 6)"
+ },
+ "inputs": [[57, 0, 0], [58, 0, 0], [59, 0, 0]]
+ },
+ {
+ "op": "Activation",
+ "name": "relu6",
+ "attrs": {"act_type": "relu"},
+ "inputs": [[60, 0, 0]]
+ },
+ {
+ "op": "null",
+ "name": "fc7_weight",
+ "attrs": {
+ "kernel": "(1, 1)",
+ "num_filter": "1024",
+ "pad": "(0, 0)"
+ },
+ "inputs": []
+ },
+ {
+ "op": "null",
+ "name": "fc7_bias",
+ "attrs": {
+ "kernel": "(1, 1)",
+ "num_filter": "1024",
+ "pad": "(0, 0)"
+ },
+ "inputs": []
+ },
+ {
+ "op": "Convolution",
+ "name": "fc7",
+ "attrs": {
+ "kernel": "(1, 1)",
+ "num_filter": "1024",
+ "pad": "(0, 0)"
+ },
+ "inputs": [[61, 0, 0], [62, 0, 0], [63, 0, 0]]
+ },
+ {
+ "op": "Activation",
+ "name": "relu7",
+ "attrs": {"act_type": "relu"},
+ "inputs": [[64, 0, 0]]
+ },
+ {
+ "op": "Pooling",
+ "name": "global_pool",
+ "attrs": {
+ "global_pool": "True",
+ "kernel": "(7, 7)",
+ "pool_type": "avg"
+ },
+ "inputs": [[65, 0, 0]]
+ },
+ {
+ "op": "null",
+ "name": "fc8_weight",
+ "attrs": {
+ "kernel": "(1, 1)",
+ "num_filter": "1000"
+ },
+ "inputs": []
+ },
+ {
+ "op": "null",
+ "name": "fc8_bias",
+ "attrs": {
+ "kernel": "(1, 1)",
+ "num_filter": "1000"
+ },
+ "inputs": []
+ },
+ {
+ "op": "Convolution",
+ "name": "fc8",
+ "attrs": {
+ "kernel": "(1, 1)",
+ "num_filter": "1000"
+ },
+ "inputs": [[66, 0, 0], [67, 0, 0], [68, 0, 0]]
+ },
+ {
+ "op": "Flatten",
+ "name": "flatten0",
+ "inputs": [[69, 0, 0]]
+ },
+ {
+ "op": "null",
+ "name": "softmax_label",
+ "inputs": []
+ },
+ {
+ "op": "SoftmaxOutput",
+ "name": "softmax",
+ "inputs": [[70, 0, 0], [71, 0, 0]]
+ }
+ ],
+ "arg_nodes": [
+ 0,
+ 1,
+ 2,
+ 5,
+ 6,
+ 10,
+ 11,
+ 14,
+ 15,
+ 19,
+ 20,
+ 23,
+ 24,
+ 27,
+ 28,
+ 32,
+ 33,
+ 36,
+ 37,
+ 40,
+ 41,
+ 45,
+ 46,
+ 49,
+ 50,
+ 53,
+ 54,
+ 58,
+ 59,
+ 62,
+ 63,
+ 67,
+ 68,
+ 71
+ ],
+ "node_row_ptr": [
+ 0,
+ 1,
+ 2,
+ 3,
+ 4,
+ 5,
+ 6,
+ 7,
+ 8,
+ 9,
+ 11,
+ 12,
+ 13,
+ 14,
+ 15,
+ 16,
+ 17,
+ 18,
+ 19,
+ 21,
+ 22,
+ 23,
+ 24,
+ 25,
+ 26,
+ 27,
+ 28,
+ 29,
+ 30,
+ 31,
+ 32,
+ 33,
+ 35,
+ 36,
+ 37,
+ 38,
+ 39,
+ 40,
+ 41,
+ 42,
+ 43,
+ 44,
+ 45,
+ 46,
+ 47,
+ 49,
+ 50,
+ 51,
+ 52,
+ 53,
+ 54,
+ 55,
+ 56,
+ 57,
+ 58,
+ 59,
+ 60,
+ 61,
+ 63,
+ 64,
+ 65,
+ 66,
+ 67,
+ 68,
+ 69,
+ 70,
+ 71,
+ 72,
+ 73,
+ 74,
+ 75,
+ 76,
+ 77,
+ 78
+ ],
+ "heads": [[72, 0, 0]],
+ "attrs": {"mxnet_version": ["int", 10200]}
+}
diff --git a/tests/python/mkl/test_mkldnn.py b/tests/python/mkl/test_mkldnn.py
new file mode 100644
index 0000000..a4c9c45
--- /dev/null
+++ b/tests/python/mkl/test_mkldnn.py
@@ -0,0 +1,94 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""
+MKL-DNN related test cases
+"""
+
+import logging
+import os
+from sys import platform
+
+
+def test_mkldnn_install():
+ """
+ This test will verify that MXNet is built/installed correctly when
+ compiled with Intel MKL-DNN library. The method will try to import
+ the mxnet module and see if the mkldnn library is mapped to this
+ process's address space.
+ """
+ logging.basicConfig(level=logging.INFO)
+
+ if not platform.startswith('linux'):
+ logging.info("Bypass mkldnn install test for non-Linux OS")
+ return
+
+ try:
+ #pylint: disable=unused-variable
+ import mxnet as mx
+ except (ImportError, OSError) as e:
+ assert 0, "Import mxnet error: %s. Please double check your build/" \
+ "install steps or environment variable settings" % str(e)
+
+ pid = os.getpid()
+ rc = os.system("cat /proc/" + str(pid) +
+ "/maps | grep libmkldnn > /dev/null")
+
+ if rc == 0:
+ logging.info("MXNet is built/installed correctly with MKL-DNN")
+ else:
+ assert 0, "MXNet is built/installed incorrectly with MKL-DNN, please " \
+ "double check your build/install steps or environment " \
+ "variable settings"
+
+
+def test_mkldnn_model():
+ """
+ This test will run a sample model for couple of iterations.
+ """
+
+ import mxnet as mx
+ model = os.path.join(os.path.dirname(os.path.realpath(__file__)), "data",
+ "test_mkldnn_test_mkldnn_model_model1.json")
+ shape = (32, 3, 300, 300)
+ ctx = mx.cpu()
+
+ sym = mx.sym.load(model)
+ args = sym.list_arguments()
+ shapes = sym.infer_shape(data=shape)
+
+ def get_tensors(args, shapes, ctx):
+ return {x: mx.nd.ones(y, ctx) for x, y in zip(args, shapes)}
+
+ inputs = get_tensors(args, shapes[0], ctx)
+ grads = get_tensors(args, shapes[0], ctx)
+
+ try:
+ exe = sym.bind(ctx, inputs, args_grad=grads)
+ for _ in range(2):
+ exe.forward(is_train=True)
+ for y in exe.outputs:
+ y.wait_to_read()
+ exe.backward()
+ for y in exe.grad_arrays:
+ y.wait_to_read()
+ except: # pylint: disable=bare-except
+ assert 0, "test_mkldnn_model exception in bind and execution"
+
+
+if __name__ == '__main__':
+ test_mkldnn_install()
--
To stop receiving notification emails like this one, please contact
anirudh2290@apache.org.