PawelGlomski-Intel commented on a change in pull request #20981:
URL: https://github.com/apache/incubator-mxnet/pull/20981#discussion_r837385725



##########
File path: src/operator/tensor/elemwise_unary_op.h
##########
@@ -457,30 +457,67 @@ class UnaryOp : public OpBase {
 };
 
 #if MXNET_USE_ONEDNN == 1
-inline bool TanhStorageType(const nnvm::NodeAttrs& attrs,
-                            const int dev_mask,
-                            DispatchMode* dispatch_mode,
-                            std::vector<int>* in_attrs,
-                            std::vector<int>* out_attrs) {
+inline bool EltwiseStorageType(const nnvm::NodeAttrs& attrs,
+                               const int dev_mask,
+                               DispatchMode* dispatch_mode,
+                               std::vector<int>* in_attrs,
+                               std::vector<int>* out_attrs) {
   CHECK_EQ(in_attrs->size(), 1);
   CHECK_EQ(out_attrs->size(), 1);
 
   return DNNLStorageType(attrs, dev_mask, true, dispatch_mode, in_attrs, 
out_attrs);
 }
 
-inline void TanhComputeExCPU(const nnvm::NodeAttrs& attrs,
-                             const OpContext& ctx,
-                             const std::vector<mxnet::NDArray>& inputs,
-                             const std::vector<OpReqType>& req,
-                             const std::vector<mxnet::NDArray>& outputs) {
-  if (SupportDNNLTanh(inputs[0], outputs[0])) {
+template <typename OP>
+struct DNNLAlgorithm {};
+template <>
+struct DNNLAlgorithm<op::mshadow_op::plus> {
+  static const dnnl::algorithm value = dnnl::algorithm::binary_add;
+};
+template <>
+struct DNNLAlgorithm<op::mshadow_op::minus> {
+  static const dnnl::algorithm value = dnnl::algorithm::binary_sub;
+};
+template <>
+struct DNNLAlgorithm<op::mshadow_op::mul> {
+  static const dnnl::algorithm value = dnnl::algorithm::binary_mul;
+};
+template <>
+struct DNNLAlgorithm<op::mshadow_op::div> {
+  static const dnnl::algorithm value = dnnl::algorithm::binary_div;
+};
+template <>
+struct DNNLAlgorithm<op::mshadow_op::tanh> {
+  static const dnnl::algorithm value = dnnl::algorithm::eltwise_tanh;
+};
+template <>
+struct DNNLAlgorithm<op::mshadow_op::exp> {
+  static const dnnl::algorithm value = dnnl::algorithm::eltwise_exp;
+};
+template <>
+struct DNNLAlgorithm<op::mshadow_op::square> {
+  static const dnnl::algorithm value = dnnl::algorithm::eltwise_square;
+};
+template <>
+struct DNNLAlgorithm<op::mshadow_op::square_root> {
+  static const dnnl::algorithm value = dnnl::algorithm::eltwise_sqrt;
+};

Review comment:
       Here is the function if you are intrerested:
   ```c++
   template <class>
   inline constexpr bool dependent_false_v = false;
   template <typename MXNetOP>
   constexpr dnnl::algorithm DNNLAlgorithm() {
     if constexpr (std::is_same_v<MXNetOP, op::mshadow_op::plus>) {
       return dnnl::algorithm::binary_add;
     } else if (std::is_same_v<MXNetOP, op::mshadow_op::minus>) {
       return dnnl::algorithm::binary_sub;
     } else if (std::is_same_v<MXNetOP, op::mshadow_op::mul>) {
       return dnnl::algorithm::binary_mul;
     } else if (std::is_same_v<MXNetOP, op::mshadow_op::div>) {
       return dnnl::algorithm::binary_div;
     } else if (std::is_same_v<MXNetOP, op::mshadow_op::tanh>) {
       return dnnl::algorithm::eltwise_tanh;
     } else if (std::is_same_v<MXNetOP, op::mshadow_op::exp>) {
       return dnnl::algorithm::eltwise_exp;
     } else if (std::is_same_v<MXNetOP, op::mshadow_op::square>) {
       return dnnl::algorithm::eltwise_square;
     } else if (std::is_same_v<MXNetOP, op::mshadow_op::square_root>) {
       return dnnl::algorithm::eltwise_sqrt;
     } else {
       static_assert(dependent_false_v<MXNetOP>, "Error");
       return dnnl::algorithm();
     }
   }
   ```




-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to