pengzhao-intel commented on a change in pull request #13530: Integrate MKLDNN 
Conv1d and support 3d layout
URL: https://github.com/apache/incubator-mxnet/pull/13530#discussion_r243874967
 
 

 ##########
 File path: src/operator/nn/mkldnn/mkldnn_base-inl.h
 ##########
 @@ -253,14 +254,23 @@ inline static mkldnn::memory::desc GetWeightDesc(const 
NDArray &arr,
   if (num_groups == 1) {
     return GetMemDesc(arr);
   } else {
-    CHECK_EQ(arr.shape().ndim(), 4U);
-    mkldnn::memory::dims tz = mkldnn::memory::dims{ num_groups,
-      static_cast<int>(arr.shape()[0] / num_groups),
-      static_cast<int>(arr.shape()[1]),
-      static_cast<int>(arr.shape()[2]),
-      static_cast<int>(arr.shape()[3])};
-    return mkldnn::memory::desc{tz, get_mkldnn_type(arr.dtype()),
-                                mkldnn::memory::format::any};
+    CHECK((arr.shape().ndim() == 3) || (arr.shape().ndim() == 4))
+        << "MKL-DNN weight currectly supports 3d and 4d layout";
+    const int N = 0, H = 2, W = 3, C = 1;
+    if (arr.shape().ndim() == 3) {
+      mkldnn::memory::dims tz = mkldnn::memory::dims{
+          num_groups, static_cast<int>(arr.shape()[N] / num_groups),
+          static_cast<int>(arr.shape()[C]), static_cast<int>(arr.shape()[H])};
+      return mkldnn::memory::desc{tz, get_mkldnn_type(arr.dtype()),
+                                  mkldnn::memory::format::any};
+    } else {
+      mkldnn::memory::dims tz = mkldnn::memory::dims{
+          num_groups, static_cast<int>(arr.shape()[N] / num_groups),
+          static_cast<int>(arr.shape()[C]), static_cast<int>(arr.shape()[H]),
+          static_cast<int>(arr.shape()[W])};
+      return mkldnn::memory::desc{tz, get_mkldnn_type(arr.dtype()),
 
 Review comment:
   This line is the common part of dim3 and dim4, right?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to