You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2021/10/28 14:51:25 UTC

[GitHub] [incubator-mxnet] agrabows opened a new pull request #20713: [FEATURE] Integrate oneDNN binary primitive support for forward add, subtract, multiply, divide.

agrabows opened a new pull request #20713:
URL: https://github.com/apache/incubator-mxnet/pull/20713


   ## Description ##
   Binary broadcast operators such as add, subtract, multiply, divide are implemented in both NDArray and NumPy modules and no oneDNN support exists for those operators. Goal of this task was to dispatch execution of those operators to oneDNN binary primitive. 
   
   ## Checklist ##
   ### Essentials ###
   - [x] PR's title starts with a category (e.g. [BUGFIX], [MODEL], [TUTORIAL], [FEATURE], [DOC], etc)
   - [x] Changes are complete (i.e. I finished coding on this PR)
   - [x] All changes have test coverage
   - [x] Code is well-documented
   
   ### Changes ###
   - [x] Merge execution of add, subtract, multiply, divide operators to one NNVM_REGISTER_OP() function
   - [x] Implement oneDNN dispatch for binary broadcast operators
   
   ## Comments ##
   Speedup for all cases noticed, up to ~350%.
   ![image](https://user-images.githubusercontent.com/59651240/139280757-35ef83c5-3118-43c4-8c8f-eae4b2881d20.png)
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@mxnet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-mxnet] agrabows commented on a change in pull request #20713: [FEATURE] Integrate oneDNN binary primitive support for forward add, subtract, multiply, divide.

Posted by GitBox <gi...@apache.org>.
agrabows commented on a change in pull request #20713:
URL: https://github.com/apache/incubator-mxnet/pull/20713#discussion_r783793071



##########
File path: src/operator/nn/dnnl/dnnl_binary-inl.h
##########
@@ -0,0 +1,89 @@
+/*
+ * 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.
+ */
+
+/*!
+ * \file dnnl_binary-inl.h
+ * \author: Adam Grabowski, adam.grabowski@intel.com
+ */
+
+#ifndef MXNET_OPERATOR_NN_DNNL_DNNL_BINARY_INL_H_
+#define MXNET_OPERATOR_NN_DNNL_DNNL_BINARY_INL_H_
+
+#if MXNET_USE_ONEDNN == 1
+#include "./dnnl_base-inl.h"
+#include "./dnnl_ops-inl.h"
+#include <vector>
+
+#include "../../tensor/elemwise_binary_broadcast_op.h"
+
+namespace mxnet {
+namespace op {
+
+using binary_op_fwd_t    = dnnl::binary;
+using binary_op_fwd_pd_t = dnnl::binary::primitive_desc;
+
+class DNNLBinaryOpFwd {
+ public:
+  template <dnnl::algorithm alg>
+  static DNNLBinaryOpFwd& GetBinaryOpForward(const nnvm::NodeAttrs& attrs,
+                                             const std::vector<NDArray>& inputs,
+                                             const std::vector<NDArray>& outputs);
+  DNNLBinaryOpFwd(const dnnl::algorithm alg,
+                  const nnvm::NodeAttrs& attrs,
+                  const std::vector<NDArray>& inputs,
+                  const std::vector<NDArray>& outputs);
+
+  void Execute(const std::vector<NDArray>& inputs,
+               const std::vector<OpReqType>& req,
+               const std::vector<NDArray>& outputs);
+
+ private:
+  std::shared_ptr<binary_op_fwd_t> fwd;
+  std::shared_ptr<binary_op_fwd_pd_t> fwd_pd;
+};
+
+template <dnnl::algorithm alg>
+DNNLBinaryOpFwd& DNNLBinaryOpFwd::GetBinaryOpForward(const nnvm::NodeAttrs& attrs,
+                                                     const std::vector<NDArray>& inputs,
+                                                     const std::vector<NDArray>& outputs) {
+  using binary_op_fwd_map = std::unordered_map<OpSignature, DNNLBinaryOpFwd, OpHash>;
+#if DMLC_CXX11_THREAD_LOCAL
+  static thread_local binary_op_fwd_map fwds;
+#else
+  static MX_THREAD_LOCAL binary_op_fwd_map fwds;
+#endif
+  OpSignature key;
+  key.AddSign(static_cast<int>(alg));

Review comment:
       attrs removed where it was possible




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@mxnet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-mxnet] agrabows commented on pull request #20713: [FEATURE] Integrate oneDNN binary primitive support for forward add, subtract, multiply, divide.

Posted by GitBox <gi...@apache.org>.
agrabows commented on pull request #20713:
URL: https://github.com/apache/incubator-mxnet/pull/20713#issuecomment-982467773


   @mxnet-bot run ci [unix-cpu]


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@mxnet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-mxnet] mimiao2017 commented on pull request #20713: [FEATURE] Integrate oneDNN binary primitive support for forward add, subtract, multiply, divide.

Posted by GitBox <gi...@apache.org>.
mimiao2017 commented on pull request #20713:
URL: https://github.com/apache/incubator-mxnet/pull/20713#issuecomment-987845603


   您好,您发给我的邮件已收到,我会尽快查看。


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@mxnet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-mxnet] agrabows commented on pull request #20713: [FEATURE] Integrate oneDNN binary primitive support for forward add, subtract, multiply, divide.

Posted by GitBox <gi...@apache.org>.
agrabows commented on pull request #20713:
URL: https://github.com/apache/incubator-mxnet/pull/20713#issuecomment-1014257337


   @mxnet-bot run ci [windows-gpu]


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@mxnet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-mxnet] agrabows commented on pull request #20713: [FEATURE] Integrate oneDNN binary primitive support for forward add, subtract, multiply, divide.

Posted by GitBox <gi...@apache.org>.
agrabows commented on pull request #20713:
URL: https://github.com/apache/incubator-mxnet/pull/20713#issuecomment-983797713


   @mxnet-bot run ci [sanity]


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@mxnet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-mxnet] mxnet-bot commented on pull request #20713: [FEATURE] Integrate oneDNN binary primitive support for forward add, subtract, multiply, divide.

Posted by GitBox <gi...@apache.org>.
mxnet-bot commented on pull request #20713:
URL: https://github.com/apache/incubator-mxnet/pull/20713#issuecomment-982467988


   Jenkins CI successfully triggered : [unix-cpu]


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@mxnet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-mxnet] mxnet-bot commented on pull request #20713: [FEATURE] Integrate oneDNN binary primitive support for forward add, subtract, multiply, divide.

Posted by GitBox <gi...@apache.org>.
mxnet-bot commented on pull request #20713:
URL: https://github.com/apache/incubator-mxnet/pull/20713#issuecomment-1009724967


   Jenkins CI successfully triggered : [windows-gpu]


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@mxnet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-mxnet] agrabows commented on pull request #20713: [FEATURE] Integrate oneDNN binary primitive support for forward add, subtract, multiply, divide.

Posted by GitBox <gi...@apache.org>.
agrabows commented on pull request #20713:
URL: https://github.com/apache/incubator-mxnet/pull/20713#issuecomment-1012122962


   @mxnet-bot run ci [windows-gpu]


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@mxnet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-mxnet] anko-intel commented on a change in pull request #20713: [FEATURE] Integrate oneDNN binary primitive support for forward add, subtract, multiply, divide.

Posted by GitBox <gi...@apache.org>.
anko-intel commented on a change in pull request #20713:
URL: https://github.com/apache/incubator-mxnet/pull/20713#discussion_r783038714



##########
File path: src/operator/tensor/elemwise_binary_broadcast_op.h
##########
@@ -91,8 +91,14 @@ inline bool BinaryBroadcastMulStorageType(const nnvm::NodeAttrs& attrs,
   int& out_stype      = out_attrs->at(0);
   bool dispatched     = false;
   if (!dispatched && common::ContainsOnlyStorage(*in_attrs, kDefaultStorage)) {
+#if MXNET_USE_ONEDNN == 1
+    if (dev_mask == mshadow::cpu::kDevMask)

Review comment:
       disabling oneDNN in runtime is still working ?

##########
File path: src/operator/nn/dnnl/dnnl_binary-inl.h
##########
@@ -0,0 +1,89 @@
+/*
+ * 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.
+ */
+
+/*!
+ * \file dnnl_binary-inl.h
+ * \author: Adam Grabowski, adam.grabowski@intel.com
+ */
+
+#ifndef MXNET_OPERATOR_NN_DNNL_DNNL_BINARY_INL_H_
+#define MXNET_OPERATOR_NN_DNNL_DNNL_BINARY_INL_H_
+
+#if MXNET_USE_ONEDNN == 1
+#include "./dnnl_base-inl.h"
+#include "./dnnl_ops-inl.h"
+#include <vector>
+
+#include "../../tensor/elemwise_binary_broadcast_op.h"
+
+namespace mxnet {
+namespace op {
+
+using binary_op_fwd_t    = dnnl::binary;
+using binary_op_fwd_pd_t = dnnl::binary::primitive_desc;
+
+class DNNLBinaryOpFwd {
+ public:
+  template <dnnl::algorithm alg>
+  static DNNLBinaryOpFwd& GetBinaryOpForward(const nnvm::NodeAttrs& attrs,
+                                             const std::vector<NDArray>& inputs,
+                                             const std::vector<NDArray>& outputs);
+  DNNLBinaryOpFwd(const dnnl::algorithm alg,
+                  const nnvm::NodeAttrs& attrs,
+                  const std::vector<NDArray>& inputs,
+                  const std::vector<NDArray>& outputs);
+
+  void Execute(const std::vector<NDArray>& inputs,
+               const std::vector<OpReqType>& req,
+               const std::vector<NDArray>& outputs);
+
+ private:
+  std::shared_ptr<binary_op_fwd_t> fwd;
+  std::shared_ptr<binary_op_fwd_pd_t> fwd_pd;
+};
+
+template <dnnl::algorithm alg>
+DNNLBinaryOpFwd& DNNLBinaryOpFwd::GetBinaryOpForward(const nnvm::NodeAttrs& attrs,
+                                                     const std::vector<NDArray>& inputs,
+                                                     const std::vector<NDArray>& outputs) {
+  using binary_op_fwd_map = std::unordered_map<OpSignature, DNNLBinaryOpFwd, OpHash>;
+#if DMLC_CXX11_THREAD_LOCAL
+  static thread_local binary_op_fwd_map fwds;
+#else
+  static MX_THREAD_LOCAL binary_op_fwd_map fwds;
+#endif
+  OpSignature key;
+  key.AddSign(static_cast<int>(alg));

Review comment:
       what about "attrs"  in the key ?
   I think we probably should add attrs to key or remove it form DNNLBinaryOpFwd constructor parameters

##########
File path: tests/python/unittest/test_operator.py
##########
@@ -1915,7 +1915,11 @@ def gen_broadcast_data(idx):
         [[1, 1, 65, 2, 22], [1, 1, 65, 1, 1]],
         [[1, 24, 103, 17, 18], [1, 24, 1, 1, 1]],
         [[1, 1, 1, 1, 2], [1, 24, 194, 50, 1]],
-        [[1, 1, 107, 84, 9], [1, 1, 1, 1, 1]]])
+        [[1, 1, 107, 84, 9], [1, 1, 1, 1, 1]],
+        [[8, 1, 6, 1], [7, 1, 5]], [[5, 4], [1]],
+        [[256, 256, 3], [3]], [[5, 4], [4]],
+        [[15, 3, 5], [3, 5]], [[15, 3, 5], [1, 5]],
+        [[15, 3, 5], [3, 1]]])

Review comment:
       tests/python/unittest/test_numpy_op.py::test_np_binary_funcs




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@mxnet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-mxnet] agrabows commented on pull request #20713: [FEATURE] Integrate oneDNN binary primitive support for forward add, subtract, multiply, divide.

Posted by GitBox <gi...@apache.org>.
agrabows commented on pull request #20713:
URL: https://github.com/apache/incubator-mxnet/pull/20713#issuecomment-1010008384


   @mxnet-bot run ci [windows-gpu]


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@mxnet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-mxnet] mxnet-bot commented on pull request #20713: [FEATURE] Integrate oneDNN binary primitive support for forward add, subtract, multiply, divide.

Posted by GitBox <gi...@apache.org>.
mxnet-bot commented on pull request #20713:
URL: https://github.com/apache/incubator-mxnet/pull/20713#issuecomment-1008844542


   Jenkins CI successfully triggered : [windows-gpu]


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@mxnet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-mxnet] mxnet-bot commented on pull request #20713: [FEATURE] Integrate oneDNN binary primitive support for forward add, subtract, multiply, divide.

Posted by GitBox <gi...@apache.org>.
mxnet-bot commented on pull request #20713:
URL: https://github.com/apache/incubator-mxnet/pull/20713#issuecomment-983797813


   Jenkins CI successfully triggered : [sanity]


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@mxnet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-mxnet] anko-intel commented on a change in pull request #20713: [FEATURE] Integrate oneDNN binary primitive support for forward add, subtract, multiply, divide.

Posted by GitBox <gi...@apache.org>.
anko-intel commented on a change in pull request #20713:
URL: https://github.com/apache/incubator-mxnet/pull/20713#discussion_r783076324



##########
File path: src/operator/numpy/np_elemwise_broadcast_op_sub.cc
##########
@@ -33,6 +33,10 @@ MXNET_OPERATOR_REGISTER_NP_BINARY_MIXED_PRECISION(_npi_subtract)
                                                     op::mshadow_op::minus,
                                                     op::mshadow_op::mixed_minus,
                                                     op::mshadow_op::mixed_rminus>)
+#if MXNET_USE_ONEDNN == 1
+    .set_attr<FComputeEx>("FComputeEx<cpu>", NumpyBinaryOperatorComputeExCPU<op::mshadow_op::minus>)

Review comment:
       What about mixed version? is it work properly for GPU if oneDNN is enabled (default configuration). Could you check if there is any test for it ?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@mxnet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-mxnet] mxnet-bot commented on pull request #20713: [FEATURE] Integrate oneDNN binary primitive support for forward add, subtract, multiply, divide.

Posted by GitBox <gi...@apache.org>.
mxnet-bot commented on pull request #20713:
URL: https://github.com/apache/incubator-mxnet/pull/20713#issuecomment-1012123027


   Jenkins CI successfully triggered : [windows-gpu]


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@mxnet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-mxnet] mxnet-bot commented on pull request #20713: [FEATURE] Integrate oneDNN binary primitive support for forward add, subtract, multiply, divide.

Posted by GitBox <gi...@apache.org>.
mxnet-bot commented on pull request #20713:
URL: https://github.com/apache/incubator-mxnet/pull/20713#issuecomment-953923206


   Hey @agrabows , Thanks for submitting the PR 
   All tests are already queued to run once. If tests fail, you can trigger one or more tests again with the following commands: 
   - To trigger all jobs: @mxnet-bot run ci [all] 
   - To trigger specific jobs: @mxnet-bot run ci [job1, job2] 
   *** 
   **CI supported jobs**: [centos-gpu, sanity, centos-cpu, windows-gpu, edge, website, miscellaneous, unix-cpu, clang, unix-gpu, windows-cpu]
   *** 
   _Note_: 
    Only following 3 categories can trigger CI :PR Author, MXNet Committer, Jenkins Admin. 
   All CI tests must pass before the PR can be merged. 
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@mxnet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-mxnet] mxnet-bot commented on pull request #20713: [FEATURE] Integrate oneDNN binary primitive support for forward add, subtract, multiply, divide.

Posted by GitBox <gi...@apache.org>.
mxnet-bot commented on pull request #20713:
URL: https://github.com/apache/incubator-mxnet/pull/20713#issuecomment-984632357


   Jenkins CI successfully triggered : [website, unix-cpu, clang, centos-gpu, unix-gpu, edge, windows-cpu, centos-cpu, windows-gpu, sanity, miscellaneous]


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@mxnet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-mxnet] agrabows commented on a change in pull request #20713: [FEATURE] Integrate oneDNN binary primitive support for forward add, subtract, multiply, divide.

Posted by GitBox <gi...@apache.org>.
agrabows commented on a change in pull request #20713:
URL: https://github.com/apache/incubator-mxnet/pull/20713#discussion_r764825320



##########
File path: tests/python/unittest/test_operator.py
##########
@@ -1915,7 +1915,11 @@ def gen_broadcast_data(idx):
         [[1, 1, 65, 2, 22], [1, 1, 65, 1, 1]],
         [[1, 24, 103, 17, 18], [1, 24, 1, 1, 1]],
         [[1, 1, 1, 1, 2], [1, 24, 194, 50, 1]],
-        [[1, 1, 107, 84, 9], [1, 1, 1, 1, 1]]])
+        [[1, 1, 107, 84, 9], [1, 1, 1, 1, 1]],
+        [[8, 1, 6, 1], [7, 1, 5]], [[5, 4], [1]],
+        [[256, 256, 3], [3]], [[5, 4], [4]],
+        [[15, 3, 5], [3, 5]], [[15, 3, 5], [1, 5]],
+        [[15, 3, 5], [3, 1]]])

Review comment:
       These are mx.nd operator tests and this module doesn't support zero shapes.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@mxnet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-mxnet] mxnet-bot commented on pull request #20713: [FEATURE] Integrate oneDNN binary primitive support for forward add, subtract, multiply, divide.

Posted by GitBox <gi...@apache.org>.
mxnet-bot commented on pull request #20713:
URL: https://github.com/apache/incubator-mxnet/pull/20713#issuecomment-985500121


   Jenkins CI successfully triggered : [windows-gpu]


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@mxnet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-mxnet] mxnet-bot commented on pull request #20713: [FEATURE] Integrate oneDNN binary primitive support for forward add, subtract, multiply, divide.

Posted by GitBox <gi...@apache.org>.
mxnet-bot commented on pull request #20713:
URL: https://github.com/apache/incubator-mxnet/pull/20713#issuecomment-1010008461


   Jenkins CI successfully triggered : [windows-gpu]


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@mxnet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-mxnet] agrabows commented on pull request #20713: [FEATURE] Integrate oneDNN binary primitive support for forward add, subtract, multiply, divide.

Posted by GitBox <gi...@apache.org>.
agrabows commented on pull request #20713:
URL: https://github.com/apache/incubator-mxnet/pull/20713#issuecomment-1008791869


   @mxnet-bot run ci [unix-cpu]


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@mxnet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-mxnet] agrabows commented on pull request #20713: [FEATURE] Integrate oneDNN binary primitive support for forward add, subtract, multiply, divide.

Posted by GitBox <gi...@apache.org>.
agrabows commented on pull request #20713:
URL: https://github.com/apache/incubator-mxnet/pull/20713#issuecomment-985500055


   @mxnet-bot run ci [windows-gpu]


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@mxnet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-mxnet] bgawrych commented on a change in pull request #20713: [FEATURE] Integrate oneDNN binary primitive support for forward add, subtract, multiply, divide.

Posted by GitBox <gi...@apache.org>.
bgawrych commented on a change in pull request #20713:
URL: https://github.com/apache/incubator-mxnet/pull/20713#discussion_r763899696



##########
File path: tests/python/unittest/test_operator.py
##########
@@ -1915,7 +1915,11 @@ def gen_broadcast_data(idx):
         [[1, 1, 65, 2, 22], [1, 1, 65, 1, 1]],
         [[1, 24, 103, 17, 18], [1, 24, 1, 1, 1]],
         [[1, 1, 1, 1, 2], [1, 24, 194, 50, 1]],
-        [[1, 1, 107, 84, 9], [1, 1, 1, 1, 1]]])
+        [[1, 1, 107, 84, 9], [1, 1, 1, 1, 1]],
+        [[8, 1, 6, 1], [7, 1, 5]], [[5, 4], [1]],
+        [[256, 256, 3], [3]], [[5, 4], [4]],
+        [[15, 3, 5], [3, 5]], [[15, 3, 5], [1, 5]],
+        [[15, 3, 5], [3, 1]]])

Review comment:
       maybe some shapes with zeros?

##########
File path: src/operator/tensor/elemwise_binary_broadcast_op_basic.cc
##########
@@ -24,9 +24,76 @@
 #include "./elemwise_unary_op.h"
 #include "./elemwise_binary_op-inl.h"
 #include "./elemwise_binary_broadcast_op.h"
+#if MXNET_USE_ONEDNN == 1
+#include "../nn/dnnl/dnnl_binary-inl.h"
+#endif  // MXNET_USE_ONEDNN == 1
 
 namespace mxnet {
 namespace op {
+
+#if MXNET_USE_ONEDNN == 1
+template <dnnl::algorithm alg>
+void DNNLBinaryOpForward(const nnvm::NodeAttrs& attrs,
+                         const OpContext& ctx,
+                         const std::vector<NDArray>& inputs,
+                         const std::vector<OpReqType>& req,
+                         const std::vector<NDArray>& outputs) {
+  mxnet::TShape new_lshape, new_rshape, new_oshape;
+  int ndim = BinaryBroadcastShapeCompact(inputs[0].shape(),
+                                         inputs[1].shape(),
+                                         outputs[0].shape(),
+                                         &new_lshape,
+                                         &new_rshape,
+                                         &new_oshape);
+  std::vector<NDArray> new_inputs;
+  std::vector<NDArray> new_outputs;
+  if (ndim) {
+    new_inputs  = {inputs[0].Reshape(new_lshape), inputs[1].Reshape(new_rshape)};
+    new_outputs = {outputs[0].Reshape(new_oshape)};
+  } else if (inputs[0].shape().Size() == 1 && inputs[0].shape().Size() == 1) {

Review comment:
       check condition

##########
File path: src/operator/nn/dnnl/dnnl_binary.cc
##########
@@ -0,0 +1,77 @@
+/*
+ * 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.
+ */
+
+/*!
+ * \file dnnl_binary.cc
+ * \author: Adam Grabowski, adam.grabowski@intel.com
+ */
+
+#if MXNET_USE_ONEDNN == 1
+#include "./dnnl_binary-inl.h"
+
+namespace mxnet {
+namespace op {
+
+DNNLBinaryOpFwd::DNNLBinaryOpFwd(const dnnl::algorithm alg,
+                                 const nnvm::NodeAttrs& attrs,
+                                 const std::vector<NDArray>& inputs,
+                                 const std::vector<NDArray>& outputs) {
+  auto src0_desc = inputs[0].GetDNNLData()->get_desc();
+  auto src1_desc = inputs[1].GetDNNLData()->get_desc();
+  auto dst_desc  = outputs[0].GetDNNLData()->get_desc();
+
+  dnnl::binary::desc fwd_desc(alg, src0_desc, src1_desc, dst_desc);
+  fwd_pd = std::make_shared<binary_op_fwd_pd_t>(fwd_desc, mxnet::CpuEngine::Get()->get_engine());
+  fwd    = std::make_shared<binary_op_fwd_t>(*fwd_pd);
+}
+
+void DNNLBinaryOpFwd::Execute(const std::vector<NDArray>& inputs,
+                              const std::vector<OpReqType>& req,
+                              const std::vector<NDArray>& outputs) {
+  auto engine = mxnet::CpuEngine::Get()->get_engine();
+  auto src0 =
+      dnnl::memory(fwd_pd->src0_desc(), engine, reinterpret_cast<void*>(inputs[0].data().dptr_));

Review comment:
       Can't you just use GetDNNLData() here instead of creating memory by hand?

##########
File path: tests/python/unittest/test_operator.py
##########
@@ -2012,10 +2016,16 @@ def reduce_op(shape, x):
             if shape == x.shape:
                 return x
             keepdims_shape = list(x.shape)
+            #calculate difference between output and input ndims

Review comment:
       add space after # 

##########
File path: src/operator/tensor/elemwise_binary_broadcast_op_basic.cc
##########
@@ -24,9 +24,76 @@
 #include "./elemwise_unary_op.h"
 #include "./elemwise_binary_op-inl.h"
 #include "./elemwise_binary_broadcast_op.h"
+#if MXNET_USE_ONEDNN == 1
+#include "../nn/dnnl/dnnl_binary-inl.h"
+#endif  // MXNET_USE_ONEDNN == 1
 
 namespace mxnet {
 namespace op {
+
+#if MXNET_USE_ONEDNN == 1
+template <dnnl::algorithm alg>
+void DNNLBinaryOpForward(const nnvm::NodeAttrs& attrs,
+                         const OpContext& ctx,
+                         const std::vector<NDArray>& inputs,
+                         const std::vector<OpReqType>& req,
+                         const std::vector<NDArray>& outputs) {
+  mxnet::TShape new_lshape, new_rshape, new_oshape;
+  int ndim = BinaryBroadcastShapeCompact(inputs[0].shape(),
+                                         inputs[1].shape(),
+                                         outputs[0].shape(),
+                                         &new_lshape,
+                                         &new_rshape,
+                                         &new_oshape);
+  std::vector<NDArray> new_inputs;
+  std::vector<NDArray> new_outputs;
+  if (ndim) {
+    new_inputs  = {inputs[0].Reshape(new_lshape), inputs[1].Reshape(new_rshape)};
+    new_outputs = {outputs[0].Reshape(new_oshape)};
+  } else if (inputs[0].shape().Size() == 1 && inputs[0].shape().Size() == 1) {
+    // BinaryBroadcastShapeCompact function doesn't reshape shape().Size() == 1 tensors
+    // into shape (1). It is mandatory for oneDNN primitive to have this reshape done.
+    mxnet::TShape one_shape = mxnet::TShape(1, 1);
+    new_inputs              = {inputs[0].Reshape(one_shape), inputs[1].Reshape(one_shape)};
+    new_outputs             = {outputs[0].Reshape(one_shape)};
+  } else {
+    new_inputs  = {inputs[0], inputs[1]};
+    new_outputs = {outputs[0]};
+  }
+
+  DNNLBinaryOpFwd& fwd = DNNLBinaryOpFwd::GetBinaryOpForward<alg>(attrs, new_inputs, new_outputs);
+  fwd.Execute(new_inputs, req, new_outputs);
+}
+#endif
+
+template <typename OP>
+static void BinaryOperatorComputeExCPU(const nnvm::NodeAttrs& attrs,
+                                       const OpContext& ctx,
+                                       const std::vector<NDArray>& inputs,
+                                       const std::vector<OpReqType>& req,
+                                       const std::vector<NDArray>& outputs) {
+#if MXNET_USE_ONEDNN == 1
+  if (common::ContainsOnlyStorage(inputs, kDefaultStorage)) {
+    if (SupportDNNLBinary(inputs)) {
+      const dnnl::algorithm alg = GetDNNLAlgorithm<OP>::dnnl_alg;

Review comment:
       GetDNNLAlgorithm => DNNLAlgorithm ?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@mxnet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-mxnet] mxnet-bot commented on pull request #20713: [FEATURE] Integrate oneDNN binary primitive support for forward add, subtract, multiply, divide.

Posted by GitBox <gi...@apache.org>.
mxnet-bot commented on pull request #20713:
URL: https://github.com/apache/incubator-mxnet/pull/20713#issuecomment-1014257406


   Jenkins CI successfully triggered : [windows-gpu]


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@mxnet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-mxnet] mxnet-bot commented on pull request #20713: [FEATURE] Integrate oneDNN binary primitive support for forward add, subtract, multiply, divide.

Posted by GitBox <gi...@apache.org>.
mxnet-bot commented on pull request #20713:
URL: https://github.com/apache/incubator-mxnet/pull/20713#issuecomment-1011877026


   Jenkins CI successfully triggered : [windows-gpu]


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@mxnet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-mxnet] agrabows commented on pull request #20713: [FEATURE] Integrate oneDNN binary primitive support for forward add, subtract, multiply, divide.

Posted by GitBox <gi...@apache.org>.
agrabows commented on pull request #20713:
URL: https://github.com/apache/incubator-mxnet/pull/20713#issuecomment-1009724910


   @mxnet-bot run ci [windows-gpu]


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@mxnet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-mxnet] bgawrych commented on a change in pull request #20713: [FEATURE] Integrate oneDNN binary primitive support for forward add, subtract, multiply, divide.

Posted by GitBox <gi...@apache.org>.
bgawrych commented on a change in pull request #20713:
URL: https://github.com/apache/incubator-mxnet/pull/20713#discussion_r783150164



##########
File path: src/operator/nn/dnnl/dnnl_binary.cc
##########
@@ -0,0 +1,75 @@
+/*
+ * 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.
+ */
+
+/*!
+ * \file dnnl_binary.cc
+ * \author: Adam Grabowski, adam.grabowski@intel.com
+ */
+
+#if MXNET_USE_ONEDNN == 1
+#include "./dnnl_binary-inl.h"
+
+namespace mxnet {
+namespace op {
+
+DNNLBinaryOpFwd::DNNLBinaryOpFwd(const dnnl::algorithm alg,
+                                 const nnvm::NodeAttrs& attrs,
+                                 const std::vector<NDArray>& inputs,
+                                 const std::vector<NDArray>& outputs) {
+  auto src0_desc = inputs[0].GetDNNLData()->get_desc();
+  auto src1_desc = inputs[1].GetDNNLData()->get_desc();
+  auto dst_desc  = outputs[0].GetDNNLData()->get_desc();
+
+  dnnl::binary::desc fwd_desc(alg, src0_desc, src1_desc, dst_desc);
+  fwd_pd = std::make_shared<binary_op_fwd_pd_t>(fwd_desc, mxnet::CpuEngine::Get()->get_engine());
+  fwd    = std::make_shared<binary_op_fwd_t>(*fwd_pd);
+}
+
+void DNNLBinaryOpFwd::Execute(const std::vector<NDArray>& inputs,
+                              const std::vector<OpReqType>& req,
+                              const std::vector<NDArray>& outputs) {
+  auto engine           = mxnet::CpuEngine::Get()->get_engine();
+  auto src0             = inputs[0].GetDNNLData();
+  auto src1             = inputs[1].GetDNNLData();
+  dnnl_output_t out_mem = CreateDNNLMem(outputs[0], fwd_pd->dst_desc(), req[0], &inputs[0]);

Review comment:
       either inputs[0] or inputs[1] can be inplace - maybe it is worth checking which input is used as output when inplace 

##########
File path: src/operator/nn/dnnl/dnnl_binary-inl.h
##########
@@ -0,0 +1,89 @@
+/*
+ * 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.
+ */
+
+/*!
+ * \file dnnl_binary-inl.h
+ * \author: Adam Grabowski, adam.grabowski@intel.com
+ */
+
+#ifndef MXNET_OPERATOR_NN_DNNL_DNNL_BINARY_INL_H_
+#define MXNET_OPERATOR_NN_DNNL_DNNL_BINARY_INL_H_
+
+#if MXNET_USE_ONEDNN == 1
+#include "./dnnl_base-inl.h"
+#include "./dnnl_ops-inl.h"
+#include <vector>
+
+#include "../../tensor/elemwise_binary_broadcast_op.h"
+
+namespace mxnet {
+namespace op {
+
+using binary_op_fwd_t    = dnnl::binary;

Review comment:
       binary_op_fwd_t => binary_fwd_t ?

##########
File path: src/operator/nn/dnnl/dnnl_binary-inl.h
##########
@@ -0,0 +1,89 @@
+/*
+ * 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.
+ */
+
+/*!
+ * \file dnnl_binary-inl.h
+ * \author: Adam Grabowski, adam.grabowski@intel.com
+ */
+
+#ifndef MXNET_OPERATOR_NN_DNNL_DNNL_BINARY_INL_H_
+#define MXNET_OPERATOR_NN_DNNL_DNNL_BINARY_INL_H_
+
+#if MXNET_USE_ONEDNN == 1
+#include "./dnnl_base-inl.h"
+#include "./dnnl_ops-inl.h"
+#include <vector>
+
+#include "../../tensor/elemwise_binary_broadcast_op.h"
+
+namespace mxnet {
+namespace op {
+
+using binary_op_fwd_t    = dnnl::binary;
+using binary_op_fwd_pd_t = dnnl::binary::primitive_desc;
+
+class DNNLBinaryOpFwd {
+ public:
+  template <dnnl::algorithm alg>
+  static DNNLBinaryOpFwd& GetBinaryOpForward(const nnvm::NodeAttrs& attrs,
+                                             const std::vector<NDArray>& inputs,
+                                             const std::vector<NDArray>& outputs);
+  DNNLBinaryOpFwd(const dnnl::algorithm alg,
+                  const nnvm::NodeAttrs& attrs,
+                  const std::vector<NDArray>& inputs,
+                  const std::vector<NDArray>& outputs);
+
+  void Execute(const std::vector<NDArray>& inputs,
+               const std::vector<OpReqType>& req,
+               const std::vector<NDArray>& outputs);
+
+ private:
+  std::shared_ptr<binary_op_fwd_t> fwd;
+  std::shared_ptr<binary_op_fwd_pd_t> fwd_pd;
+};
+
+template <dnnl::algorithm alg>
+DNNLBinaryOpFwd& DNNLBinaryOpFwd::GetBinaryOpForward(const nnvm::NodeAttrs& attrs,
+                                                     const std::vector<NDArray>& inputs,
+                                                     const std::vector<NDArray>& outputs) {
+  using binary_op_fwd_map = std::unordered_map<OpSignature, DNNLBinaryOpFwd, OpHash>;
+#if DMLC_CXX11_THREAD_LOCAL
+  static thread_local binary_op_fwd_map fwds;
+#else
+  static MX_THREAD_LOCAL binary_op_fwd_map fwds;
+#endif
+  OpSignature key;
+  key.AddSign(static_cast<int>(alg));

Review comment:
       +1 to remove attrs

##########
File path: tests/python/unittest/test_operator.py
##########
@@ -1915,7 +1915,11 @@ def gen_broadcast_data(idx):
         [[1, 1, 65, 2, 22], [1, 1, 65, 1, 1]],
         [[1, 24, 103, 17, 18], [1, 24, 1, 1, 1]],
         [[1, 1, 1, 1, 2], [1, 24, 194, 50, 1]],
-        [[1, 1, 107, 84, 9], [1, 1, 1, 1, 1]]])
+        [[1, 1, 107, 84, 9], [1, 1, 1, 1, 1]],
+        [[8, 1, 6, 1], [7, 1, 5]], [[5, 4], [1]],
+        [[256, 256, 3], [3]], [[5, 4], [4]],
+        [[15, 3, 5], [3, 5]], [[15, 3, 5], [1, 5]],
+        [[15, 3, 5], [3, 1]]])

Review comment:
       please check if it works when rhs shape is longer than lhs e.g. [15,3] and [4, 15, 3]




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@mxnet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-mxnet] agrabows commented on pull request #20713: [FEATURE] Integrate oneDNN binary primitive support for forward add, subtract, multiply, divide.

Posted by GitBox <gi...@apache.org>.
agrabows commented on pull request #20713:
URL: https://github.com/apache/incubator-mxnet/pull/20713#issuecomment-1008844492


   @mxnet-bot run ci [windows-gpu]


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@mxnet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-mxnet] mxnet-bot commented on pull request #20713: [FEATURE] Integrate oneDNN binary primitive support for forward add, subtract, multiply, divide.

Posted by GitBox <gi...@apache.org>.
mxnet-bot commented on pull request #20713:
URL: https://github.com/apache/incubator-mxnet/pull/20713#issuecomment-1012933289


   Jenkins CI successfully triggered : [windows-gpu]


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@mxnet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-mxnet] agrabows commented on a change in pull request #20713: [FEATURE] Integrate oneDNN binary primitive support for forward add, subtract, multiply, divide.

Posted by GitBox <gi...@apache.org>.
agrabows commented on a change in pull request #20713:
URL: https://github.com/apache/incubator-mxnet/pull/20713#discussion_r783792736



##########
File path: src/operator/numpy/np_elemwise_broadcast_op_sub.cc
##########
@@ -33,6 +33,10 @@ MXNET_OPERATOR_REGISTER_NP_BINARY_MIXED_PRECISION(_npi_subtract)
                                                     op::mshadow_op::minus,
                                                     op::mshadow_op::mixed_minus,
                                                     op::mshadow_op::mixed_rminus>)
+#if MXNET_USE_ONEDNN == 1
+    .set_attr<FComputeEx>("FComputeEx<cpu>", NumpyBinaryOperatorComputeExCPU<op::mshadow_op::minus>)

Review comment:
       OneDNN dispatch is only taken under consideration after _dev_mask == mshadow::cpu::kDevMask_ condition is met, thus not affecting GPU workflow.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@mxnet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-mxnet] agrabows commented on pull request #20713: [FEATURE] Integrate oneDNN binary primitive support for forward add, subtract, multiply, divide.

Posted by GitBox <gi...@apache.org>.
agrabows commented on pull request #20713:
URL: https://github.com/apache/incubator-mxnet/pull/20713#issuecomment-984632228


   @mxnet-bot run ci [all]


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@mxnet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-mxnet] anko-intel commented on a change in pull request #20713: [FEATURE] Integrate oneDNN binary primitive support for forward add, subtract, multiply, divide.

Posted by GitBox <gi...@apache.org>.
anko-intel commented on a change in pull request #20713:
URL: https://github.com/apache/incubator-mxnet/pull/20713#discussion_r786618910



##########
File path: src/operator/nn/dnnl/dnnl_binary.cc
##########
@@ -0,0 +1,78 @@
+/*
+ * 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.
+ */
+
+/*!
+ * \file dnnl_binary.cc
+ * \author: Adam Grabowski, adam.grabowski@intel.com
+ */
+
+#if MXNET_USE_ONEDNN == 1
+#include "./dnnl_binary-inl.h"
+
+namespace mxnet {
+namespace op {
+
+DNNLBinaryOpFwd::DNNLBinaryOpFwd(const dnnl::algorithm alg,
+                                 const std::vector<NDArray>& inputs,
+                                 const std::vector<NDArray>& outputs) {
+  auto src0_desc = inputs[0].GetDNNLData()->get_desc();
+  auto src1_desc = inputs[1].GetDNNLData()->get_desc();
+  auto dst_desc  = outputs[0].GetDNNLData()->get_desc();
+
+  dnnl::binary::desc fwd_desc(alg, src0_desc, src1_desc, dst_desc);
+  fwd_pd = std::make_shared<binary_fwd_pd_t>(fwd_desc, mxnet::CpuEngine::Get()->get_engine());
+  fwd    = std::make_shared<binary_fwd_t>(*fwd_pd);
+}
+
+void DNNLBinaryOpFwd::Execute(const std::vector<NDArray>& inputs,
+                              const std::vector<OpReqType>& req,
+                              const std::vector<NDArray>& outputs) {
+  auto engine = mxnet::CpuEngine::Get()->get_engine();
+  auto src0   = inputs[0].GetDNNLData();
+  auto src1   = inputs[1].GetDNNLData();
+  dnnl_output_t out_mem;
+  if (outputs[0].GetDNNLData()->get_data_handle() == inputs[1].GetDNNLData()->get_data_handle())
+    out_mem = CreateDNNLMem(outputs[0], fwd_pd->dst_desc(), req[0], &inputs[1]);
+  else
+    out_mem = CreateDNNLMem(outputs[0], fwd_pd->dst_desc(), req[0], &inputs[0]);
+
+  dnnl_args_map_t args = {
+      {DNNL_ARG_SRC_0, *src0},
+      {DNNL_ARG_SRC_1, *src1},
+      {DNNL_ARG_DST, *out_mem.second},
+  };
+
+  DNNLStream::Get()->RegisterPrimArgs(*fwd, args);
+  CommitOutput(outputs[0], out_mem);
+  DNNLStream::Get()->Submit();
+}
+
+bool SupportDNNLBinary(const std::vector<NDArray>& inputs) {
+  auto dtype  = inputs[0].dtype();
+  auto ndim_0 = inputs[0].shape().ndim();
+  auto ndim_1 = inputs[1].shape().ndim();
+  return ndim_0 >= 1 && ndim_0 <= 6 && ndim_1 >= 1 && ndim_1 <= 6 &&
+         inputs[0].shape().Size() != 0 && inputs[1].shape().Size() != 0 &&
+         dtype == mshadow::kFloat32 && dtype == inputs[1].dtype();

Review comment:
       please check if oneDNN supports bfloat, if yes please create separate PR for it.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@mxnet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-mxnet] agrabows commented on pull request #20713: [FEATURE] Integrate oneDNN binary primitive support for forward add, subtract, multiply, divide.

Posted by GitBox <gi...@apache.org>.
agrabows commented on pull request #20713:
URL: https://github.com/apache/incubator-mxnet/pull/20713#issuecomment-1012933203


   @mxnet-bot run ci [windows-gpu]


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@mxnet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-mxnet] mxnet-bot commented on pull request #20713: [FEATURE] Integrate oneDNN binary primitive support for forward add, subtract, multiply, divide.

Posted by GitBox <gi...@apache.org>.
mxnet-bot commented on pull request #20713:
URL: https://github.com/apache/incubator-mxnet/pull/20713#issuecomment-1008791912


   Jenkins CI successfully triggered : [unix-cpu]


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@mxnet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-mxnet] agrabows commented on pull request #20713: [FEATURE] Integrate oneDNN binary primitive support for forward add, subtract, multiply, divide.

Posted by GitBox <gi...@apache.org>.
agrabows commented on pull request #20713:
URL: https://github.com/apache/incubator-mxnet/pull/20713#issuecomment-1011876977


   @mxnet-bot run ci [windows-gpu]


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@mxnet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-mxnet] bgawrych merged pull request #20713: [FEATURE] Integrate oneDNN binary primitive support for forward add, subtract, multiply, divide.

Posted by GitBox <gi...@apache.org>.
bgawrych merged pull request #20713:
URL: https://github.com/apache/incubator-mxnet/pull/20713


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@mxnet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org