| 107 | } |
| 108 | |
| 109 | void Compute(OpKernelContext* ctx) override { |
| 110 | // Each input tensor in OneDNN layout has additional meta-tensor carrying |
| 111 | // layout information. So the number of actual tensors is half the total |
| 112 | // number of inputs. |
| 113 | const int num_inputs = ctx->num_inputs() / 2; |
| 114 | |
| 115 | MklDnnShape mkl_shape; |
| 116 | const size_t kSrc0Idx = 0; |
| 117 | const size_t kOutputIdx = 0; |
| 118 | |
| 119 | if (num_inputs == 1) { |
| 120 | GetMklShape(ctx, kSrc0Idx, &mkl_shape); |
| 121 | bool input_in_mkl_format = mkl_shape.IsMklTensor(); |
| 122 | |
| 123 | if (input_in_mkl_format) { |
| 124 | ForwardMklTensorInToOut(ctx, kSrc0Idx, kOutputIdx); |
| 125 | } else { |
| 126 | ForwardTfTensorInToOut(ctx, kSrc0Idx, kOutputIdx); |
| 127 | } |
| 128 | return; |
| 129 | } |
| 130 | |
| 131 | // Check if the input shape is same |
| 132 | if (!CheckInputShape(ctx)) return; |
| 133 | |
| 134 | try { |
| 135 | TensorShape output_tf_shape; |
| 136 | MklDnnShape output_mkl_shape; |
| 137 | const Tensor& src_tensor = MklGetInput(ctx, kSrc0Idx); |
| 138 | |
| 139 | Tensor* dst_tensor = nullptr; |
| 140 | |
| 141 | // Nothing to compute, return. |
| 142 | if (src_tensor.shape().num_elements() == 0) { |
| 143 | output_mkl_shape.SetMklTensor(false); |
| 144 | output_tf_shape = src_tensor.shape(); |
| 145 | AllocateOutputSetMklShape(ctx, kOutputIdx, &dst_tensor, output_tf_shape, |
| 146 | output_mkl_shape); |
| 147 | return; |
| 148 | } |
| 149 | |
| 150 | if (src_tensor.dims() == 0) { |
| 151 | ComputeScalar(ctx); |
| 152 | return; |
| 153 | } |
| 154 | |
| 155 | auto cpu_engine = engine(ENGINE_CPU, 0); |
| 156 | std::vector<float> coeff(num_inputs, 1.0); |
| 157 | std::vector<MEMORY_PRIMITIVE_DESC> srcs_pd; |
| 158 | std::vector<memory> inputs; |
| 159 | |
| 160 | MklDnnData<T> dst(&cpu_engine); |
| 161 | MklDnnData<T> src(&cpu_engine); |
| 162 | bool has_mkl_input = false; |
| 163 | int mkl_input_index = FindMKLInputIndex(ctx); |
| 164 | MKL_TENSOR_FORMAT mkl_data_format; |
| 165 | TensorFormat tf_data_format; |
| 166 | MEMORY_FORMAT dnn_fmt = MEMORY_FORMAT::any; |
nothing calls this directly
no test coverage detected