| 50 | } |
| 51 | |
| 52 | void Compute(OpKernelContext* ctx) override { |
| 53 | try { |
| 54 | // Using CPU device |
| 55 | auto cpu_engine = engine(ENGINE_CPU, 0); |
| 56 | |
| 57 | // Get the inputs |
| 58 | const Tensor& src_tensor = ctx->input(kSrcIndex); |
| 59 | const float min_range = ctx->input(1).flat<float>()(0); |
| 60 | const float max_range = ctx->input(2).flat<float>()(0); |
| 61 | |
| 62 | // Get MklShape |
| 63 | MklDnnShape src_mkl_shape; |
| 64 | GetMklShape(ctx, kSrcIndex, &src_mkl_shape); |
| 65 | auto src_tf_shape = src_mkl_shape.IsMklTensor() |
| 66 | ? src_mkl_shape.GetTfShape() |
| 67 | : src_tensor.shape(); |
| 68 | |
| 69 | // src_dims is the dimension of src_tensor |
| 70 | // output_dims are same as src_dims |
| 71 | auto src_dims = src_mkl_shape.IsMklTensor() |
| 72 | ? src_mkl_shape.GetSizesAsMklDnnDims() |
| 73 | : TFShapeToMklDnnDims(src_tensor.shape()); |
| 74 | auto output_dims = src_dims; |
| 75 | |
| 76 | // Create reorder memory for src and dst |
| 77 | MklDnnData<T> src(&cpu_engine); |
| 78 | MklDnnData<float> dst(&cpu_engine); |
| 79 | |
| 80 | std::shared_ptr<stream> reorder_stream; |
| 81 | MklDnnThreadPool eigen_tp(ctx); |
| 82 | reorder_stream.reset(CreateStream(&eigen_tp, cpu_engine)); |
| 83 | |
| 84 | memory::format_tag dst_layout_type; |
| 85 | switch (src_tf_shape.dims()) { |
| 86 | case 1: |
| 87 | dst_layout_type = memory::format_tag::x; |
| 88 | break; |
| 89 | case 2: |
| 90 | dst_layout_type = memory::format_tag::nc; |
| 91 | break; |
| 92 | case 3: |
| 93 | dst_layout_type = memory::format_tag::tnc; |
| 94 | break; |
| 95 | case 4: |
| 96 | dst_layout_type = memory::format_tag::nhwc; |
| 97 | break; |
| 98 | case 5: |
| 99 | dst_layout_type = memory::format_tag::ndhwc; |
| 100 | break; |
| 101 | default: |
| 102 | OP_REQUIRES_OK(ctx, |
| 103 | errors::Aborted("Input dims must be <= 5 and >= 1")); |
| 104 | return; |
| 105 | } |
| 106 | |
| 107 | // If input is in OneDNN layout, then simply grab input layout; otherwise, |
| 108 | // construct input TF layout. For TF layout, although input shape |
| 109 | // (src_dims) required is in OneDNN order, the layout is Tensorflow's |
nothing calls this directly
no test coverage detected