| 3800 | } |
| 3801 | |
| 3802 | const MklLayoutRewritePass::RewriteInfo* |
| 3803 | MklLayoutRewritePass::CheckForNodeRewrite(const Node* n) const { |
| 3804 | CHECK_NOTNULL(n); |
| 3805 | |
| 3806 | // QuantizedOps may have attributes other than "T", so decoupled the check |
| 3807 | // with a function, CheckForQuantizedNodeRewrite(const Node*). |
| 3808 | const RewriteInfo* ri = CheckForQuantizedNodeRewrite(n); |
| 3809 | if (ri != nullptr) return ri; |
| 3810 | |
| 3811 | // First check if node along with its type is supported by OneDNN layer. |
| 3812 | // We do not want to rewrite an op into OneDNN op if types are not supported. |
| 3813 | // E.g., OneDNNRelu does not support INT32. So we cannot rewrite Relu to |
| 3814 | // OneDNNRelu if type is INT32. |
| 3815 | DataType T; |
| 3816 | if (!TryGetNodeAttr(n->def(), "T", &T)) { |
| 3817 | return nullptr; |
| 3818 | } |
| 3819 | |
| 3820 | // We make an exception for Conv2D, as the corresponding OneDNN ops |
| 3821 | // currently do not support the case of padding == EXPLICIT yet. |
| 3822 | if (n->type_string() == csinfo_.conv2d || |
| 3823 | n->type_string() == csinfo_.conv2d_grad_input || |
| 3824 | n->type_string() == csinfo_.conv2d_grad_filter) { |
| 3825 | string padding; |
| 3826 | TF_CHECK_OK(GetNodeAttr(n->def(), "padding", &padding)); |
| 3827 | if (padding == "EXPLICIT") return nullptr; |
| 3828 | } |
| 3829 | |
| 3830 | // We make an exception for __MklDummyConv2DWithBias, |
| 3831 | // __MklConv2DBackpropFilterWithBias, and __MklDummyPadWithConv2D since their |
| 3832 | // names do not match Mkl node names. |
| 3833 | if (n->type_string() != csinfo_.conv2d_with_bias && |
| 3834 | n->type_string() != csinfo_.pad_with_conv2d && |
| 3835 | n->type_string() != csinfo_.pad_with_fused_conv2d && |
| 3836 | n->type_string() != csinfo_.conv2d_grad_filter_with_bias && |
| 3837 | n->type_string() != csinfo_.fused_batch_norm_ex && |
| 3838 | n->type_string() != csinfo_.fused_conv2d && |
| 3839 | n->type_string() != csinfo_.fused_depthwise_conv2d && |
| 3840 | n->type_string() != csinfo_.fused_matmul && |
| 3841 | n->type_string() != csinfo_.fused_batch_matmul && |
| 3842 | n->type_string() != csinfo_.fused_batch_matmul_v2 && |
| 3843 | !mkl_op_registry::IsMklOp(mkl_op_registry::GetMklOpName(n->type_string()), |
| 3844 | T)) { |
| 3845 | return nullptr; |
| 3846 | } |
| 3847 | |
| 3848 | // We now check if rewrite rule applies for this op. If rewrite rule passes |
| 3849 | // for this op, then we rewrite it to OneDNN op. |
| 3850 | // Find matching RewriteInfo and then check that rewrite rule applies. |
| 3851 | if (!CheckForRecoOpsListNodeRewrite(n)) return nullptr; |
| 3852 | for (auto ri = rinfo_.cbegin(); ri != rinfo_.cend(); ++ri) { |
| 3853 | if (n->type_string().compare(ri->name) == 0 && ri->rewrite_rule(n)) { |
| 3854 | return &*ri; |
| 3855 | } |
| 3856 | } |
| 3857 | |
| 3858 | // Else return not found. |
| 3859 | return nullptr; |
nothing calls this directly
no test coverage detected